Skip to content

Commit

Permalink
add Request.make_tempfile method
Browse files Browse the repository at this point in the history
  • Loading branch information
maluke committed Feb 13, 2011
1 parent 2614fb3 commit 58f00df
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
2 changes: 1 addition & 1 deletion tests/test_request.py
Expand Up @@ -212,7 +212,7 @@ def test_copy():
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():
Expand Down
13 changes: 10 additions & 3 deletions webob/request.py
Expand Up @@ -429,8 +429,9 @@ def _body__get(self):
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):
Expand Down Expand Up @@ -682,7 +683,7 @@ def _copy_body_tempfile(self):
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))
Expand All @@ -692,6 +693,12 @@ def _copy_body_tempfile(self):
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):
Expand Down

0 comments on commit 58f00df

Please sign in to comment.