add threaded WSGI server mixin to check URL existence on same host :>

This commit is contained in:
posativ 2012-12-16 00:46:20 +01:00
parent 63b990838d
commit 8e2e90ed4e
3 changed files with 12 additions and 4 deletions

View File

@ -50,7 +50,7 @@ class Isso(object):
MODERATION = False MODERATION = False
SQLITE = None SQLITE = None
HOST = 'http://localhost:8000/' HOST = 'http://localhost:8080/'
MAX_AGE = 15 * 60 MAX_AGE = 15 * 60
HTTP_STATUS_CODES = { HTTP_STATUS_CODES = {
@ -189,5 +189,5 @@ def main():
else: else:
from wsgiref.simple_server import make_server 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() httpd.serve_forever()

View File

@ -13,7 +13,8 @@ from isso import json, models, utils, wsgi
def create(app, environ, request, path): 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', {} return 400, 'URL does not exist', {}
try: try:

View File

@ -5,12 +5,15 @@ import io
import os import os
import re import re
import cgi import cgi
import wsgiref
import tempfile import tempfile
import urlparse import urlparse
import mimetypes import mimetypes
from Cookie import SimpleCookie
from urllib import quote from urllib import quote
from Cookie import SimpleCookie
from SocketServer import ThreadingMixIn
from wsgiref.simple_server import WSGIServer
class Request(object): class Request(object):
@ -119,3 +122,7 @@ def sendfile(filename, root):
def setcookie(name, value, **kwargs): def setcookie(name, value, **kwargs):
return '; '.join([quote(name, '') + '=' + quote(value, '')] + return '; '.join([quote(name, '') + '=' + quote(value, '')] +
[k.replace('_', '-') + '=' + str(v) for k, v in kwargs.iteritems()]) [k.replace('_', '-') + '=' + str(v) for k, v in kwargs.iteritems()])
class ThreadedWSGIServer(ThreadingMixIn, WSGIServer):
pass