Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed #7769: Added a couple missing file methods to `TemporaryUploade…

…dFile`. Thanks, Mads Sülau Jørgensen.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@8634 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 615ed200060ef6571099886cebb7503078a9bfdf 1 parent 887f778
@jacobian jacobian authored
Showing with 14 additions and 13 deletions.
  1. +14 −13 django/core/files/uploadedfile.py
View
27 django/core/files/uploadedfile.py
@@ -84,8 +84,9 @@ def temporary_file_path(self):
# We can't directly subclass because NamedTemporaryFile is actually a
# factory function
def read(self, *args): return self._file.read(*args)
- def seek(self, offset): return self._file.seek(offset)
+ def seek(self, *args): return self._file.seek(*args)
def write(self, s): return self._file.write(s)
+ def tell(self, *args): return self._file.tell(*args)
def __iter__(self): return iter(self._file)
def readlines(self, size=None): return self._file.readlines(size)
def xreadlines(self): return self._file.xreadlines()
@@ -107,39 +108,39 @@ class InMemoryUploadedFile(UploadedFile):
"""
def __init__(self, file, field_name, name, content_type, size, charset):
super(InMemoryUploadedFile, self).__init__(name, content_type, size, charset)
- self.file = file
+ self._file = file
self.field_name = field_name
- self.file.seek(0)
-
- def seek(self, *args, **kwargs):
- self.file.seek(*args, **kwargs)
+ self._file.seek(0)
def open(self):
- self.seek(0)
-
- def read(self, *args, **kwargs):
- return self.file.read(*args, **kwargs)
+ self._file.seek(0)
def chunks(self, chunk_size=None):
- self.file.seek(0)
+ self._file.seek(0)
yield self.read()
def multiple_chunks(self, chunk_size=None):
# Since it's in memory, we'll never have multiple chunks.
return False
+ # proxy methods to StringIO
+ def read(self, *args): return self._file.read(*args)
+ def seek(self, *args): return self._file.seek(*args)
+ def tell(self, *args): return self._file.tell(*args)
+ def close(self): return self._file.close()
+
class SimpleUploadedFile(InMemoryUploadedFile):
"""
A simple representation of a file, which just has content, size, and a name.
"""
def __init__(self, name, content, content_type='text/plain'):
- self.file = StringIO(content or '')
+ self._file = StringIO(content or '')
self.name = name
self.field_name = None
self.size = len(content or '')
self.content_type = content_type
self.charset = None
- self.file.seek(0)
+ self._file.seek(0)
def from_dict(cls, file_dict):
"""
Please sign in to comment.
Something went wrong with that request. Please try again.