Ticket #10541: fix.diff

File fix.diff, 967 bytes (added by Jonas H., 13 years ago)
  • django/core/files/base.py

    diff --git a/django/core/files/base.py b/django/core/files/base.py
    index 6204d71..6a7fbc4 100644
    a b class File(FileProxyMixin):  
    6060            chunk_size = self.DEFAULT_CHUNK_SIZE
    6161
    6262        if hasattr(self, 'seek'):
    63             self.seek(0)
    64         # Assume the pointer is at zero...
    65         counter = self.size
    66 
    67         while counter > 0:
    68             yield self.read(chunk_size)
    69             counter -= chunk_size
     63            try:
     64                self.seek(0)
     65            except IOError, e:
     66                if e.errno != 29:
     67                    # errno 29 is illegal seek, i.e. 'self.file' is a pipe
     68                    # or anything else non-seekable
     69                    raise
     70
     71        chunk = self.read(chunk_size)
     72        while chunk:
     73            yield chunk
     74            chunk = self.read(chunk_size)
    7075
    7176    def multiple_chunks(self, chunk_size=None):
    7277        """
Back to Top