Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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
Jacob Kaplan-Moss authored August 27, 2008

Showing 1 changed file with 14 additions and 13 deletions. Show diff stats Hide diff stats

  1. 27  django/core/files/uploadedfile.py
27  django/core/files/uploadedfile.py
@@ -84,8 +84,9 @@ def temporary_file_path(self):
84 84
     # We can't directly subclass because NamedTemporaryFile is actually a
85 85
     # factory function
86 86
     def read(self, *args):          return self._file.read(*args)
87  
-    def seek(self, offset):         return self._file.seek(offset)
  87
+    def seek(self, *args):          return self._file.seek(*args)
88 88
     def write(self, s):             return self._file.write(s)
  89
+    def tell(self, *args):          return self._file.tell(*args)
89 90
     def __iter__(self):             return iter(self._file)
90 91
     def readlines(self, size=None): return self._file.readlines(size)
91 92
     def xreadlines(self):           return self._file.xreadlines()
@@ -107,39 +108,39 @@ class InMemoryUploadedFile(UploadedFile):
107 108
     """
108 109
     def __init__(self, file, field_name, name, content_type, size, charset):
109 110
         super(InMemoryUploadedFile, self).__init__(name, content_type, size, charset)
110  
-        self.file = file
  111
+        self._file = file
111 112
         self.field_name = field_name
112  
-        self.file.seek(0)
113  
-
114  
-    def seek(self, *args, **kwargs):
115  
-        self.file.seek(*args, **kwargs)
  113
+        self._file.seek(0)
116 114
 
117 115
     def open(self):
118  
-        self.seek(0)
119  
-
120  
-    def read(self, *args, **kwargs):
121  
-        return self.file.read(*args, **kwargs)
  116
+        self._file.seek(0)
122 117
 
123 118
     def chunks(self, chunk_size=None):
124  
-        self.file.seek(0)
  119
+        self._file.seek(0)
125 120
         yield self.read()
126 121
 
127 122
     def multiple_chunks(self, chunk_size=None):
128 123
         # Since it's in memory, we'll never have multiple chunks.
129 124
         return False
130 125
 
  126
+    # proxy methods to StringIO
  127
+    def read(self, *args): return self._file.read(*args)
  128
+    def seek(self, *args): return self._file.seek(*args)
  129
+    def tell(self, *args): return self._file.tell(*args)
  130
+    def close(self):       return self._file.close()
  131
+
131 132
 class SimpleUploadedFile(InMemoryUploadedFile):
132 133
     """
133 134
     A simple representation of a file, which just has content, size, and a name.
134 135
     """
135 136
     def __init__(self, name, content, content_type='text/plain'):
136  
-        self.file = StringIO(content or '')
  137
+        self._file = StringIO(content or '')
137 138
         self.name = name
138 139
         self.field_name = None
139 140
         self.size = len(content or '')
140 141
         self.content_type = content_type
141 142
         self.charset = None
142  
-        self.file.seek(0)
  143
+        self._file.seek(0)
143 144
 
144 145
     def from_dict(cls, file_dict):
145 146
         """

0 notes on commit 615ed20

Please sign in to comment.
Something went wrong with that request. Please try again.