Code

Ticket #7769: uploaded_file.diff

File uploaded_file.diff, 2.0 KB (added by Mads Sülau Jørgensen <django@…>, 6 years ago)
Line 
1Index: django/core/files/uploadedfile.py
2===================================================================
3--- django/core/files/uploadedfile.py   (revision 7930)
4+++ django/core/files/uploadedfile.py   (working copy)
5@@ -199,8 +199,9 @@
6     # We can't directly subclass because NamedTemporaryFile is actually a
7     # factory function
8     def read(self, *args):          return self._file.read(*args)
9-    def seek(self, offset):         return self._file.seek(offset)
10+    def seek(self, *args):          return self._file.seek(*args)
11     def write(self, s):             return self._file.write(s)
12+    def tell(self, *args):          return self._file.tell(*args)
13     def close(self):                return self._file.close()
14     def __iter__(self):             return iter(self._file)
15     def readlines(self, size=None): return self._file.readlines(size)
16@@ -212,26 +213,27 @@
17     """
18     def __init__(self, file, field_name, name, content_type, size, charset):
19         super(InMemoryUploadedFile, self).__init__(name, content_type, size, charset)
20-        self.file = file
21+        self._file = file
22         self.field_name = field_name
23-        self.file.seek(0)
24+        self._file.seek(0)
25 
26-    def seek(self, *args, **kwargs):
27-        self.file.seek(*args, **kwargs)
28-
29     def open(self):
30-        self.seek(0)
31+        self._file.seek(0)
32 
33-    def read(self, *args, **kwargs):
34-        return self.file.read(*args, **kwargs)
35-
36     def chunks(self, chunk_size=None):
37-        self.file.seek(0)
38+        self._file.seek(0)
39         yield self.read()
40 
41     def multiple_chunks(self, chunk_size=None):
42         # Since it's in memory, we'll never have multiple chunks.
43         return False
44+   
45+    # proxy methods to StringIO
46+    def read(self, *args): return self._file.read(*args)
47+    def seek(self, *args): return self._file.seek(*args)
48+    def write(self, s):    return self._file.write(s)
49+    def tell(self, *args): return self._file.tell(*args)
50+    def close(self):       return self._file.close()
51 
52 class SimpleUploadedFile(InMemoryUploadedFile):
53     """