Ticket #14681: 14681_unified.diff

File 14681_unified.diff, 1.6 KB (added by dmclain, 14 years ago)

unified the two patches and fixed a bug in one of the tests

  • django/core/files/base.py

    diff --git a/django/core/files/base.py b/django/core/files/base.py
    index 6204d71..fadbd36 100644
    a b class File(FileProxyMixin):  
    1515        if name is None:
    1616            name = getattr(file, 'name', None)
    1717        self.name = name
    18         self.mode = getattr(file, 'mode', None)
     18        if hasattr(file, 'mode'):
     19            self.mode = getattr(file, 'mode')
    1920
    2021    def __str__(self):
    2122        return smart_str(self.name or '')
  • tests/modeltests/files/tests.py

    diff --git a/tests/modeltests/files/tests.py b/tests/modeltests/files/tests.py
    index 885f787..72a3577 100644
    a b from __future__ import with_statement  
    33import shutil
    44import sys
    55import tempfile
     6import gzip
    67
    78from django.core.cache import cache
    89from django.core.files import File
    class FileTests(TestCase):  
    101102        obj4.random.save("random_file", ContentFile("random content"))
    102103        self.assertTrue(obj4.random.name.endswith("/random_file"))
    103104
     105        # should not set mode to None if it is not present
     106        file = SimpleUploadedFile("mode_test.txt", "content")
     107        self.assertFalse(hasattr(file, 'mode'))
     108
     109        # Verify fix for #14681, File like objects should not explicitly set
     110        # mode=None for compatibility with stdlib gzip
     111        file = SimpleUploadedFile("gzip_test.txt", "content")
     112        self.assertFalse(hasattr(file, 'mode'))
     113        g = gzip.GzipFile(fileobj=file)
     114       
    104115        # Clean up the temporary files and dir.
    105116        obj1.normal.delete()
    106117        obj2.normal.delete()
Back to Top