Replaced a hardcoded "2" with the right named constant
This commit is contained in:
parent
ee48f4af99
commit
4ad9f4d4ea
|
@ -2,6 +2,7 @@
|
||||||
Classes representing uploaded files.
|
Classes representing uploaded files.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
import errno
|
||||||
import os
|
import os
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
|
|
||||||
|
@ -13,6 +14,7 @@ from django.utils.encoding import force_str
|
||||||
__all__ = ('UploadedFile', 'TemporaryUploadedFile', 'InMemoryUploadedFile',
|
__all__ = ('UploadedFile', 'TemporaryUploadedFile', 'InMemoryUploadedFile',
|
||||||
'SimpleUploadedFile')
|
'SimpleUploadedFile')
|
||||||
|
|
||||||
|
|
||||||
class UploadedFile(File):
|
class UploadedFile(File):
|
||||||
"""
|
"""
|
||||||
A abstract uploaded file (``TemporaryUploadedFile`` and
|
A abstract uploaded file (``TemporaryUploadedFile`` and
|
||||||
|
@ -53,6 +55,7 @@ class UploadedFile(File):
|
||||||
|
|
||||||
name = property(_get_name, _set_name)
|
name = property(_get_name, _set_name)
|
||||||
|
|
||||||
|
|
||||||
class TemporaryUploadedFile(UploadedFile):
|
class TemporaryUploadedFile(UploadedFile):
|
||||||
"""
|
"""
|
||||||
A file uploaded to a temporary location (i.e. stream-to-disk).
|
A file uploaded to a temporary location (i.e. stream-to-disk).
|
||||||
|
@ -75,12 +78,13 @@ class TemporaryUploadedFile(UploadedFile):
|
||||||
try:
|
try:
|
||||||
return self.file.close()
|
return self.file.close()
|
||||||
except OSError as e:
|
except OSError as e:
|
||||||
if e.errno != 2:
|
if e.errno != errno.ENOENT:
|
||||||
# Means the file was moved or deleted before the tempfile
|
# Means the file was moved or deleted before the tempfile
|
||||||
# could unlink it. Still sets self.file.close_called and
|
# could unlink it. Still sets self.file.close_called and
|
||||||
# calls self.file.file.close() before the exception
|
# calls self.file.file.close() before the exception
|
||||||
raise
|
raise
|
||||||
|
|
||||||
|
|
||||||
class InMemoryUploadedFile(UploadedFile):
|
class InMemoryUploadedFile(UploadedFile):
|
||||||
"""
|
"""
|
||||||
A file uploaded into memory (i.e. stream-to-memory).
|
A file uploaded into memory (i.e. stream-to-memory).
|
||||||
|
|
Loading…
Reference in New Issue