Replaced a hardcoded "2" with the right named constant

This commit is contained in:
Alex Gaynor 2013-11-02 12:55:36 -07:00
parent ee48f4af99
commit 4ad9f4d4ea
1 changed files with 5 additions and 1 deletions

View File

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