#9115: Check for presence of os.unlink in temp.py
-------------------------------------+--------------------------------------
          Reporter:  michaelhart     |         Owner:  nobody                   
            Status:  new             |     Milestone:                           
         Component:  Core framework  |       Version:  SVN                      
        Resolution:                  |      Keywords:  temp.py windows os.unlink
             Stage:  Accepted        |     Has_patch:  0                        
        Needs_docs:  0               |   Needs_tests:  0                        
Needs_better_patch:  0               |  
-------------------------------------+--------------------------------------
Comment (by michaelhart):

 One option might be to defer the importing of any write-specific module
 initialisations, or at least import these conditionally.

 For example, the user should only specify to use the
 !MemoryFileUploadHandler and not the !TemporaryFileUploadHandler in their
 settings (something that's not currently done in the rietveld project):

 {{{
 #!python
 FILE_UPLOAD_HANDLERS = (
     'django.core.files.uploadhandler.MemoryFileUploadHandler',
     )
 }}}

 And then in core/files/uploadedfile.py, delay the importing until the
 !TemporaryUploadedFile constructor:

 {{{
 #!python
 class TemporaryUploadedFile(UploadedFile):
     """
     A file uploaded to a temporary location (i.e. stream-to-disk).
     """
     def __init__(self, name, content_type, size, charset):
         super(TemporaryUploadedFile, self).__init__(name, content_type,
 size, charset)
         # Moved this from top of file
         from django.core.files import temp as tempfile
         if settings.FILE_UPLOAD_TEMP_DIR:
             self._file = tempfile.NamedTemporaryFile(suffix='.upload',
 dir=settings.FILE_UPLOAD_TEMP_DIR)
         else:
             self._file = tempfile.NamedTemporaryFile(suffix='.upload')
 }}}

 Or, only import temp if !TemporaryFileUploadHandler is in
 settings.FILE_UPLOAD_HANDLERS:

 {{{
 #!python
 from django.conf import settings
 from django.core.files.base import File
 from django.utils.encoding import smart_str

 if 'django.core.files.uploadhandler.TemporaryFileUploadHandler' in
 settings.FILE_UPLOAD_HANDLERS:
     from django.core.files import temp as tempfile
 }}}

 Both of these methods work for me (I can attach patches for either/both if
 you like, however I suspect they're still a little hacky).

-- 
Ticket URL: <http://code.djangoproject.com/ticket/9115#comment:3>
Django <http://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 post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to