mirror of
https://github.com/frappe/gunicorn.git
synced 2026-01-14 11:09:11 +08:00
fix lot of typos/bug
This commit is contained in:
parent
73763d66bf
commit
fe5f44d0b7
@ -27,13 +27,13 @@ from ctypes import *
|
||||
class HttpParser(object):
|
||||
|
||||
def __init__(self):
|
||||
self.headers = {}
|
||||
self._headers = {}
|
||||
self.version = None
|
||||
self.method None
|
||||
self.method = None
|
||||
self.path = None
|
||||
self._content_len = None
|
||||
|
||||
def header(self, headers, buf):
|
||||
def headers(self, headers, buf):
|
||||
""" take a string buff. It return
|
||||
environ or None if parsing isn't done.
|
||||
"""
|
||||
@ -62,15 +62,15 @@ class HttpParser(object):
|
||||
hname = ""
|
||||
for line in lines:
|
||||
if line == "\t":
|
||||
self.headers[hname] += line.strip()
|
||||
self._headers[hname] += line.strip()
|
||||
else:
|
||||
try:
|
||||
hname =self._parse_headerl(line)
|
||||
except ValueError:
|
||||
# bad headers
|
||||
pass
|
||||
headers = self.headers
|
||||
self._content_len = int(self._headers.get('Content-Length'))
|
||||
headers = self._headers
|
||||
self._content_len = int(self._headers.get('Content-Length') or 0)
|
||||
return headers
|
||||
|
||||
def _first_line(self, line):
|
||||
@ -82,16 +82,16 @@ class HttpParser(object):
|
||||
def _parse_headerl(self, line):
|
||||
name, value = line.split(": ", 1)
|
||||
name = name.strip()
|
||||
self.headers[name] = value.strip()
|
||||
self._headers[name] = value.strip()
|
||||
return name
|
||||
|
||||
@property
|
||||
def should_close(self):
|
||||
if self._should_close:
|
||||
return True
|
||||
if self.headers.get("Connection") == "close":
|
||||
if self._headers.get("Connection") == "close":
|
||||
return True
|
||||
if self.headers.get("Connection") == "Keep-Alive":
|
||||
if self._headers.get("Connection") == "Keep-Alive":
|
||||
return False
|
||||
if self.version < "HTTP/1.1":
|
||||
return True
|
||||
@ -117,12 +117,14 @@ class HttpParser(object):
|
||||
if self._len_content == 0:
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
def fetch_body(self, buf, data):
|
||||
dlen = len(data)
|
||||
resize(buf, sizeof(data))
|
||||
s = data.value
|
||||
if self.is_chunked:
|
||||
# do chunk
|
||||
pass
|
||||
else:
|
||||
if self.content_len > 0:
|
||||
nr = min(len(data), self._content_len)
|
||||
|
||||
@ -81,17 +81,16 @@ class HTTPRequest(object):
|
||||
if headers.get('Accept', '').lower() == "100-continue":
|
||||
self.socket.send("100 Continue\n")
|
||||
|
||||
if "?" in parser.path:
|
||||
path_info, query = parser.path.split('?', 1)
|
||||
if "?" in self.parser.path:
|
||||
path_info, query = self.parser.path.split('?', 1)
|
||||
else:
|
||||
path_info = self.parser.path
|
||||
query = ""
|
||||
|
||||
if not length:
|
||||
if not self.parser.content_length and not self.parser.is_chunked:
|
||||
wsgi_input = StringIO.StringIO()
|
||||
else:
|
||||
wsgi_input = TeeInput(self.socket, parser, buf, remain)
|
||||
if not self.parser.content_length and not self.parser.is_chunked:
|
||||
wsgi_input = StringIO.StringIO()
|
||||
else:
|
||||
wsgi_input = TeeInput(self.socket, parser, buf, remain)
|
||||
|
||||
environ = {
|
||||
"wsgi.url_scheme": 'http',
|
||||
@ -103,7 +102,7 @@ class HTTPRequest(object):
|
||||
"wsgi.run_once": False,
|
||||
"SCRIPT_NAME": "",
|
||||
"SERVER_SOFTWARE": self.SERVER_VERSION,
|
||||
"REQUEST_METHOD": self.method,
|
||||
"REQUEST_METHOD": self.parser.method,
|
||||
"PATH_INFO": unquote(path_info),
|
||||
"QUERY_STRING": query,
|
||||
"RAW_URI": self.path,
|
||||
@ -113,7 +112,7 @@ class HTTPRequest(object):
|
||||
"REMOTE_PORT": self.client_address[1],
|
||||
"SERVER_NAME": self.server_address[0],
|
||||
"SERVER_PORT": self.server_address[1],
|
||||
"SERVER_PROTOCOL": self.version
|
||||
"SERVER_PROTOCOL": self.parser.version
|
||||
}
|
||||
|
||||
for key, value in self.headers.items():
|
||||
|
||||
@ -49,7 +49,7 @@ class TeeInput(object):
|
||||
if self._len and self._len < MAX_BODY:
|
||||
self.tmp = StringIO.StringIO()
|
||||
else:
|
||||
self.tmp = new tempfile.TemporaryFile()
|
||||
self.tmp = tempfile.TemporaryFile()
|
||||
self.buf2 = create_string_buffer(tmp)
|
||||
if len(buf) > 0:
|
||||
parser.filter_body(self.buf2, buf)
|
||||
@ -59,7 +59,7 @@ class TeeInput(object):
|
||||
|
||||
@property
|
||||
def len(self):
|
||||
if self._len return self._len
|
||||
if self._len: return self._len
|
||||
if self.remain:
|
||||
pos = self.tmp.tell()
|
||||
while True:
|
||||
@ -76,7 +76,7 @@ class TeeInput(object):
|
||||
return self.tmp.read(length)
|
||||
|
||||
if not length:
|
||||
r = self.tmp.read() or ||
|
||||
r = self.tmp.read() or ""
|
||||
while self._tee(self.remain, self.buf2):
|
||||
r += self.buf2.value
|
||||
return r
|
||||
@ -84,7 +84,7 @@ class TeeInput(object):
|
||||
r = self.buf2
|
||||
diff = self._tmp_size() - self.tmp.tell()
|
||||
if not diff:
|
||||
return self._ensure_length((self._tee(self.remain, r), self.remain)
|
||||
return self._ensure_length(self._tee(self.remain, r), self.remain)
|
||||
else:
|
||||
length = min(diff, self.remain)
|
||||
return self._ensure_length(self._tee(length, r), length)
|
||||
@ -132,7 +132,7 @@ class TeeInput(object):
|
||||
def _ensure_length(buf, length):
|
||||
if not buf or not self._len:
|
||||
return buf
|
||||
while len(buf) < length && self.len != self.tmp.pos():
|
||||
while len(buf) < length and self.len != self.tmp.pos():
|
||||
buf += self._tee(length - len(buf), self.buf2)
|
||||
|
||||
return buf
|
||||
Loading…
x
Reference in New Issue
Block a user