Ticket #2613: wsgi.py-memoryerror.diff
File wsgi.py-memoryerror.diff, 1.4 KB (added by , 18 years ago) |
---|
-
core/handlers/wsgi.py
4 4 from django.utils import datastructures 5 5 from django import http 6 6 from pprint import pformat 7 try: 8 from cStringIO import StringIO 9 except ImportError: 10 from StringIO import StringIO 7 11 12 from shutil import copyfileobj 13 def copyfileobj2(fsrc, fdst, length=16*1024, howmany=0): 14 """copy data from file-like object fsrc to file-like object fdst""" 15 if howmany == 0: 16 return copyfileobj(fsrc, fdst, length) 17 remain = howmany 18 while remain > 0: 19 buf = fsrc.read(min(length, remain)) 20 if not buf: 21 break 22 fdst.write(buf) 23 remain -= len(buf) 24 8 25 # See http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html 9 26 STATUS_CODE_TEXT = { 10 27 100: 'CONTINUE', … … 119 136 try: 120 137 return self._raw_post_data 121 138 except AttributeError: 122 self._raw_post_data = self.environ['wsgi.input'].read(int(self.environ["CONTENT_LENGTH"])) 139 s = StringIO() 140 copyfileobj2(self.environ['wsgi.input'], s, 141 howmany=int(self.environ['CONTENT_LENGTH'])) 142 self._raw_post_data = s.getvalue() 143 s.close() 123 144 return self._raw_post_data 124 145 125 146 GET = property(_get_get, _set_get)