author: Sylvain Viollon
date: Tue Aug 13 14:36:08 2013 +0200
revision: 13:2d7dc1622770 in infrae.fileupload
branch:
details: https://hg.infrae.com/infrae.fileupload?cmd=changeset;node=2d7dc1622770
modified: src/infrae/fileupload/middleware.py
added:
removed:
log: Bug fixes. Support non-blocking upload.
diffstat:
src/infrae/fileupload/middleware.py | 19 +++++++++++++++----
1 files changed, 15 insertions(+), 4 deletions(-)
diffs (58 lines):
diff -r 6a8bfc1145f5 -r 2d7dc1622770 src/infrae/fileupload/middleware.py
--- a/src/infrae/fileupload/middleware.py Tue Aug 13 13:55:02 2013 +0200
+++ b/src/infrae/fileupload/middleware.py Tue Aug 13 14:36:08 2013 +0200
@@ -18,8 +18,17 @@
def compare(original, tested=''):
- """Compare two lines together.
+ """Compare two lines together, paying attention to the different
+ possibilities to end lines.
+ >>> compare(None)
+ False
+ >>> compare('\n')
+ True
+ >>> compare('\r\n')
+ True
+ >>> compare('foo\r\n')
+ False
>>> compare(None, 'foo')
False
>>> compare('foo', 'bar')
@@ -34,7 +43,7 @@
False
"""
if original and original.startswith(tested):
- if original[len(tested):] in ('\n', '\r\n'):
+ if tested[len(original):] in ('', '\r', '\n', '\r\n'):
return True
return False
@@ -255,6 +264,8 @@
data = ''
need_more = True
while need_more:
+ # It is possible we didn't get a full line, and wsgi.input
+ # is not blocking.
max_size = min(BLOCK_SIZE, self._to_read)
if max_size:
data += self._stream.readline(max_size)
@@ -343,7 +354,7 @@
# Read the headers
headers = {}
line = input_stream.read(line=True)
- while compare(line):
+ while not compare(line):
name, payload = line.split(':', 1)
headers[name.lower().strip()] = cgi.parse_header(payload)
line = input_stream.read(line=True)
@@ -370,7 +381,7 @@
request.environ['infrae.fileupload.current'] = upload
line = None
output_stream = upload.write()
- while compare(line, end_boundary):
+ while not compare(line, end_boundary):
output_stream.send(line)
line = input_stream.read()
if compare(line, part_boundary):
lmpx.com only provides a reader for public news (NNTP) servers. It is not
affiliated with the servers or forums shown here and is not responsible for
the content of articles, which is written by their respective authors.