#33023: InMemoryUploadedFile - opening with context manager multiple time is
throwing error
--------------------------------+--------------------------------------
     Reporter:  Harsh Bhikadia  |                    Owner:  nobody
         Type:  Bug             |                   Status:  closed
    Component:  Core (Other)    |                  Version:  3.2
     Severity:  Normal          |               Resolution:  fixed
     Keywords:                  |             Triage Stage:  Unreviewed
    Has patch:  0               |      Needs documentation:  0
  Needs tests:  0               |  Patch needs improvement:  0
Easy pickings:  0               |                    UI/UX:  0
--------------------------------+--------------------------------------

Comment (by Harsh Bhikadia):

 Also realised the implementation is not respecting the `mode` passed in
 arg when calling `open`.

 The current implementation (`master` branch as of now) looks like the
 following:

 {{{
 class InMemoryUploadedFile(UploadedFile):
     """
     A file uploaded into memory (i.e. stream-to-memory).
     """
     def __init__(self, file, field_name, name, content_type, size,
 charset, content_type_extra=None):
         super().__init__(file, name, content_type, size, charset,
 content_type_extra)
         self.field_name = field_name

     def open(self, mode=None):
         self.file.seek(0)
         return self

     def chunks(self, chunk_size=None):
         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
 }}}

-- 
Ticket URL: <https://code.djangoproject.com/ticket/33023#comment:2>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/063.5c8d42f0a79504c4d96e24c83abac91d%40djangoproject.com.

Reply via email to