From 516adafcbe616801ef6457f97be71b1197b3af6a Mon Sep 17 00:00:00 2001 From: benoitc Date: Fri, 7 May 2010 09:31:14 +0200 Subject: [PATCH] fix some errors & add headers. unitests still broken --- gunicorn/http/__init__.py | 8 ++++++-- gunicorn/http/body.py | 15 +++++++++------ gunicorn/http/errors.py | 11 +++++++++++ gunicorn/http/message.py | 12 ++++++++---- gunicorn/http/parser.py | 10 +++++++--- gunicorn/http/unreader.py | 4 ++++ gunicorn/http/wsgi.py | 8 +++----- gunicorn/workers/async.py | 2 +- setup.py | 2 +- 9 files changed, 50 insertions(+), 22 deletions(-) diff --git a/gunicorn/http/__init__.py b/gunicorn/http/__init__.py index 29a553f4..f66a0f68 100644 --- a/gunicorn/http/__init__.py +++ b/gunicorn/http/__init__.py @@ -1,3 +1,7 @@ +# -*- coding: utf-8 - +# +# This file is part of gunicorn released under the MIT license. +# See the NOTICE for more information. -from message import Message, Request -from parser import RequestParser +from gunicorn.http.message import Message, Request +from gunicorn.http.parser import RequestParser diff --git a/gunicorn/http/body.py b/gunicorn/http/body.py index 06650aae..293c5359 100644 --- a/gunicorn/http/body.py +++ b/gunicorn/http/body.py @@ -1,12 +1,15 @@ - -import re +# -*- coding: utf-8 - +# +# This file is part of gunicorn released under the MIT license. +# See the NOTICE for more information. try: from cStringIO import StringIO except ImportError: from StringIO import StringIO -from errors import * +from gunicorn.http.errors import NoMoreData, ChunkMissingTerminator, \ +InvalidChunkSize class ChunkedReader(object): def __init__(self, req, unreader): @@ -147,9 +150,9 @@ class EOFReader(object): data = self.unreader.read() while data: - buf.write(data) - if size is not None and buf.tell() > size: - data = buf.getvalue() + self.buf.write(data) + if size is not None and self.buf.tell() > size: + data = self.buf.getvalue() ret, rest = data[:size], data[size:] self.buf.truncate(0) self.buf.write(rest) diff --git a/gunicorn/http/errors.py b/gunicorn/http/errors.py index 57cd9932..d062d27a 100644 --- a/gunicorn/http/errors.py +++ b/gunicorn/http/errors.py @@ -1,3 +1,7 @@ +# -*- coding: utf-8 - +# +# This file is part of gunicorn released under the MIT license. +# See the NOTICE for more information. class ParseException(Exception): pass @@ -22,6 +26,13 @@ class InvalidRequestMethod(ParseException): def __str__(self): return "Invalid HTTP method: %r" % self.method + +class InvalidHTTPVersion(ParseException): + def __init__(self, version): + self.version = version + + def __str__(self): + return "Invalid HTTP Version: %s" % self.version class InvalidHeader(ParseException): def __init__(self, hdr): diff --git a/gunicorn/http/message.py b/gunicorn/http/message.py index cb703f83..86a5b9aa 100644 --- a/gunicorn/http/message.py +++ b/gunicorn/http/message.py @@ -1,5 +1,8 @@ +# -*- coding: utf-8 - +# +# This file is part of gunicorn released under the MIT license. +# See the NOTICE for more information. -import os import re import urlparse @@ -8,8 +11,9 @@ try: except ImportError: from StringIO import StringIO -from body import ChunkedReader, LengthReader, EOFReader, Body -from errors import * +from gunicorn.http.body import ChunkedReader, LengthReader, EOFReader, Body +from gunicorn.http.errors import InvalidHeader, InvalidHeaderName, NoMoreData, \ +InvalidRequestLine, InvalidRequestMethod, InvalidHTTPVersion class Message(object): def __init__(self, unreader): @@ -72,7 +76,7 @@ class Message(object): try: clength = int(value) except ValueError: - clenth = None + clength = None elif name.upper() == "TRANSFER-ENCODING": chunked = value.lower() == "chunked" diff --git a/gunicorn/http/parser.py b/gunicorn/http/parser.py index 9eb93480..e4c64035 100644 --- a/gunicorn/http/parser.py +++ b/gunicorn/http/parser.py @@ -1,8 +1,12 @@ +# -*- coding: utf-8 - +# +# This file is part of gunicorn released under the MIT license. +# See the NOTICE for more information. import socket -from message import Request -from unreader import SocketUnreader, IterUnreader +from gunicorn.http.message import Request +from gunicorn.http.unreader import SocketUnreader, IterUnreader class Parser(object): def __init__(self, mesg_class, source): @@ -25,7 +29,7 @@ class Parser(object): if self.mesg: data = self.mesg.body.read(8192) while data: - data = mesg.body.read(8192) + data = self.mesg.body.read(8192) # Parse the next request self.mesg = self.mesg_class(self.unreader) diff --git a/gunicorn/http/unreader.py b/gunicorn/http/unreader.py index 838452e9..4dcee55a 100644 --- a/gunicorn/http/unreader.py +++ b/gunicorn/http/unreader.py @@ -1,3 +1,7 @@ +# -*- coding: utf-8 - +# +# This file is part of gunicorn released under the MIT license. +# See the NOTICE for more information. import os diff --git a/gunicorn/http/wsgi.py b/gunicorn/http/wsgi.py index 8f77fbfd..582c72bb 100644 --- a/gunicorn/http/wsgi.py +++ b/gunicorn/http/wsgi.py @@ -3,11 +3,9 @@ # This file is part of gunicorn released under the MIT license. # See the NOTICE for more information. -import errno import logging import os import re -import socket import sys from urllib import unquote @@ -37,11 +35,11 @@ def create(req, sock, client, server, debug=False): if name == "expect": # handle expect if hdr_value.lower() == "100-continue": - self.socket.send("HTTP/1.1 100 Continue\r\n\r\n") + sock.send("HTTP/1.1 100 Continue\r\n\r\n") elif name == "x-forwarded-for": - forward_address = hdr_value + forward = hdr_value elif name == "host": - host = hdr_value + server = hdr_value elif name == "script_name": script_name = hdr_value elif name == "content-type": diff --git a/gunicorn/workers/async.py b/gunicorn/workers/async.py index 4c9658fc..5476e970 100644 --- a/gunicorn/workers/async.py +++ b/gunicorn/workers/async.py @@ -74,6 +74,6 @@ class AsyncWorker(base.Worker): #Only send back traceback in HTTP in debug mode. if not self.debug: raise - util.write_error(client, traceback.format_exc()) + util.write_error(sock, traceback.format_exc()) return False return True diff --git a/setup.py b/setup.py index 9cf4d771..18f16ab4 100644 --- a/setup.py +++ b/setup.py @@ -41,7 +41,7 @@ setup( packages = find_packages(exclude=['examples', 'tests']), include_package_data = True, - install_requires=['setuptools', 'simplehttp'], + install_requires=['setuptools'], entry_points="""