Commits

Sergey Schetinin committed 5c5f7c1

add Request.make_tempfile method

Comments (0)

Files changed (2)

tests/test_request.py

     assert req.body_file is old_body_file
 
 class UnseekableInputWithSeek(UnseekableInput):
-    def seek(self, pos):
+    def seek(self, pos, rel=0):
         raise IOError("Invalid seek!")
 
 def test_broken_seek():
         clen = self.content_length
         if clen is None:
             clen = -1
-        r = self.body_file.read(clen)
-        self.body_file.seek(0)
+        f = self.environ['wsgi.input']
+        r = f.read(clen)
+        f.seek(0)
         return r
 
     def _body__set(self, value):
         assert isinstance(length, int)
         if not tempfile_limit or length <= tempfile_limit:
             return False
-        fileobj = tempfile.TemporaryFile()
+        fileobj = self.make_tempfile()
         input = self.body_file
         while length:
             data = input.read(min(length, 65536))
         self.environ['wsgi.input'] = fileobj
         return True
 
+    def make_tempfile(self):
+        """
+            Create a tempfile to store big request body
+        """
+        return tempfile.TemporaryFile()
+
 
     def remove_conditional_headers(self, remove_encoding=True, remove_range=True,
                                         remove_match=True, remove_modified=True):