From 8e2e90ed4e5a2138041ff741a215dacf6da141b4 Mon Sep 17 00:00:00 2001 From: posativ Date: Sun, 16 Dec 2012 00:46:20 +0100 Subject: [PATCH] add threaded WSGI server mixin to check URL existence on same host :> --- isso/__init__.py | 4 ++-- isso/comment.py | 3 ++- isso/wsgi.py | 9 ++++++++- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/isso/__init__.py b/isso/__init__.py index f246818..1dafd73 100644 --- a/isso/__init__.py +++ b/isso/__init__.py @@ -50,7 +50,7 @@ class Isso(object): MODERATION = False SQLITE = None - HOST = 'http://localhost:8000/' + HOST = 'http://localhost:8080/' MAX_AGE = 15 * 60 HTTP_STATUS_CODES = { @@ -189,5 +189,5 @@ def main(): else: from wsgiref.simple_server import make_server - httpd = make_server('127.0.0.1', 8080, app) + httpd = make_server('127.0.0.1', 8080, app, server_class=wsgi.ThreadedWSGIServer) httpd.serve_forever() diff --git a/isso/comment.py b/isso/comment.py index ea3d65e..ab1759b 100644 --- a/isso/comment.py +++ b/isso/comment.py @@ -13,7 +13,8 @@ from isso import json, models, utils, wsgi def create(app, environ, request, path): - if app.PRODUCTION and not utils.urlexists(app.HOST, '/' + path): + if app.PRODUCTION and not utils.urlexists(app.HOST, path): + print app.HOST, path return 400, 'URL does not exist', {} try: diff --git a/isso/wsgi.py b/isso/wsgi.py index 0b91b14..4963c04 100644 --- a/isso/wsgi.py +++ b/isso/wsgi.py @@ -5,12 +5,15 @@ import io import os import re import cgi +import wsgiref import tempfile import urlparse import mimetypes -from Cookie import SimpleCookie from urllib import quote +from Cookie import SimpleCookie +from SocketServer import ThreadingMixIn +from wsgiref.simple_server import WSGIServer class Request(object): @@ -119,3 +122,7 @@ def sendfile(filename, root): def setcookie(name, value, **kwargs): return '; '.join([quote(name, '') + '=' + quote(value, '')] + [k.replace('_', '-') + '=' + str(v) for k, v in kwargs.iteritems()]) + + +class ThreadedWSGIServer(ThreadingMixIn, WSGIServer): + pass