diff --git a/django/core/files/base.py b/django/core/files/base.py
index 48d0be4..47c06ab 100644
|
a
|
b
|
class File(FileProxyMixin):
|
| 36 | 36 | if not hasattr(self, '_size'): |
| 37 | 37 | if hasattr(self.file, 'size'): |
| 38 | 38 | self._size = self.file.size |
| 39 | | elif os.path.exists(self.file.name): |
| | 39 | elif hasattr(self.file, 'name') and os.path.exists(self.file.name): |
| 40 | 40 | self._size = os.path.getsize(self.file.name) |
| | 41 | elif hasattr(self.file, 'tell') and hasattr(self.file, 'seek'): |
| | 42 | pos = self.file.tell() |
| | 43 | self.file.seek(0, os.SEEK_END) |
| | 44 | self._size = self.file.tell() |
| | 45 | self.file.seek(pos) |
| 41 | 46 | else: |
| 42 | 47 | raise AttributeError("Unable to determine the file's size.") |
| 43 | 48 | return self._size |
diff --git a/tests/regressiontests/file_storage/tests.py b/tests/regressiontests/file_storage/tests.py
index 769e2c7..74d13e5 100644
|
a
|
b
|
except ImportError:
|
| 18 | 18 | |
| 19 | 19 | from django.conf import settings |
| 20 | 20 | from django.core.exceptions import SuspiciousOperation, ImproperlyConfigured |
| 21 | | from django.core.files.base import ContentFile |
| | 21 | from django.core.files.base import File, ContentFile |
| 22 | 22 | from django.core.files.images import get_image_dimensions |
| 23 | 23 | from django.core.files.storage import FileSystemStorage, get_storage_class |
| 24 | 24 | from django.core.files.uploadedfile import UploadedFile |
| … |
… |
class ContentFileTestCase(unittest.TestCase):
|
| 550 | 550 | def test_content_file_default_name(self): |
| 551 | 551 | self.assertEqual(ContentFile("content").name, None) |
| 552 | 552 | |
| 553 | | def test_content_file_custome_name(self): |
| | 553 | def test_content_file_custom_name(self): |
| 554 | 554 | name = "I can have a name too!" |
| 555 | 555 | self.assertEqual(ContentFile("content", name=name).name, name) |
| | 556 | |
| | 557 | class NoNameFileTestCase(unittest.TestCase): |
| | 558 | """ |
| | 559 | Other examples of unnamed files may be tempfile.SpooledTemporaryFile or |
| | 560 | urllib.urlopen() |
| | 561 | """ |
| | 562 | def test_noname_file_default_name(self): |
| | 563 | self.assertEqual(File(StringIO('A file with no name')).name, None) |
| | 564 | |
| | 565 | def test_noname_file_get_size(self): |
| | 566 | self.assertEqual(File(StringIO('A file with no name')).size, 19) |