author: Sylvain Viollon
date: Tue Aug 13 13:55:02 2013 +0200
revision: 12:6a8bfc1145f5 in infrae.fileupload
branch:
details: https://hg.infrae.com/infrae.fileupload?cmd=changeset;node=6a8bfc1145f5
modified: src/infrae/fileupload/middleware.py
added:
removed:
log: Try to force to read full lines.
diffstat:
src/infrae/fileupload/middleware.py | 25 +++++++++++++++----------
1 files changed, 15 insertions(+), 10 deletions(-)
diffs (50 lines):
diff -r 1ed1c195cd4e -r 6a8bfc1145f5 src/infrae/fileupload/middleware.py
--- a/src/infrae/fileupload/middleware.py Tue Aug 13 12:08:31 2013 +0200
+++ b/src/infrae/fileupload/middleware.py Tue Aug 13 13:55:02 2013 +0200
@@ -251,13 +251,18 @@
for notifier in self._notifies:
notifier(read)
- def read(self):
- max_size = BLOCK_SIZE if BLOCK_SIZE < self._to_read else self._to_read
- if max_size:
- data = self._stream.readline(max_size)
- self.notify(len(data))
- return data
- return None
+ def read(self, line=False):
+ data = ''
+ need_more = True
+ while need_more:
+ max_size = min(BLOCK_SIZE, self._to_read)
+ if max_size:
+ data += self._stream.readline(max_size)
+ self.notify(len(data))
+ need_more = line and data[-1] != '\n'
+ else:
+ need_more = False
+ return data or None
class UploadMiddleware(object):
@@ -331,17 +336,17 @@
input_stream = Reader(request.environ['wsgi.input'], length)
# Read the first marker
- marker = input_stream.read()
+ marker = input_stream.read(line=True)
if marker.strip() != part_boundary:
return fail('Upload request is malformed #2')
# Read the headers
headers = {}
- line = input_stream.read()
+ line = input_stream.read(line=True)
while compare(line):
name, payload = line.split(':', 1)
headers[name.lower().strip()] = cgi.parse_header(payload)
- line = input_stream.read()
+ line = input_stream.read(line=True)
# We should have now the payload
if ('content-disposition' not in headers or
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.