Ticket #7769: uploaded_file.diff

File uploaded_file.diff, 2.0 KB (added by Mads Sülau Jørgensen <django@…>, 16 years ago)
  • django/core/files/uploadedfile.py

     
    199199    # We can't directly subclass because NamedTemporaryFile is actually a
    200200    # factory function
    201201    def read(self, *args):          return self._file.read(*args)
    202     def seek(self, offset):         return self._file.seek(offset)
     202    def seek(self, *args):          return self._file.seek(*args)
    203203    def write(self, s):             return self._file.write(s)
     204    def tell(self, *args):          return self._file.tell(*args)
    204205    def close(self):                return self._file.close()
    205206    def __iter__(self):             return iter(self._file)
    206207    def readlines(self, size=None): return self._file.readlines(size)
     
    212213    """
    213214    def __init__(self, file, field_name, name, content_type, size, charset):
    214215        super(InMemoryUploadedFile, self).__init__(name, content_type, size, charset)
    215         self.file = file
     216        self._file = file
    216217        self.field_name = field_name
    217         self.file.seek(0)
     218        self._file.seek(0)
    218219
    219     def seek(self, *args, **kwargs):
    220         self.file.seek(*args, **kwargs)
    221 
    222220    def open(self):
    223         self.seek(0)
     221        self._file.seek(0)
    224222
    225     def read(self, *args, **kwargs):
    226         return self.file.read(*args, **kwargs)
    227 
    228223    def chunks(self, chunk_size=None):
    229         self.file.seek(0)
     224        self._file.seek(0)
    230225        yield self.read()
    231226
    232227    def multiple_chunks(self, chunk_size=None):
    233228        # Since it's in memory, we'll never have multiple chunks.
    234229        return False
     230   
     231    # proxy methods to StringIO
     232    def read(self, *args): return self._file.read(*args)
     233    def seek(self, *args): return self._file.seek(*args)
     234    def write(self, s):    return self._file.write(s)
     235    def tell(self, *args): return self._file.tell(*args)
     236    def close(self):       return self._file.close()
    235237
    236238class SimpleUploadedFile(InMemoryUploadedFile):
    237239    """
Back to Top