summaryrefslogtreecommitdiff
path: root/django/core/files/utils.py
diff options
context:
space:
mode:
authorSimon Charette <charette.s@gmail.com>2016-05-22 12:43:56 -0400
committerSimon Charette <charette.s@gmail.com>2016-05-27 21:05:58 -0400
commit4f474607de9b470f977a734bdd47590ab202e778 (patch)
treece05cd13e229c7086362703d84c9dedd8a0d6fb2 /django/core/files/utils.py
parent6ab0d1358fc78077064aab88a4fb0a47ca116391 (diff)
downloaddjango-4f474607de9b470f977a734bdd47590ab202e778.tar.gz
Fixed #26646 -- Added IOBase methods required by TextIOWrapper to File.
Thanks Tim for the review.
Diffstat (limited to 'django/core/files/utils.py')
-rw-r--r--django/core/files/utils.py30
1 files changed, 25 insertions, 5 deletions
diff --git a/django/core/files/utils.py b/django/core/files/utils.py
index 2656fa7188..8e891bf23f 100644
--- a/django/core/files/utils.py
+++ b/django/core/files/utils.py
@@ -1,6 +1,3 @@
-from django.utils import six
-
-
class FileProxyMixin(object):
"""
A mixin class used to forward file methods to an underlaying file
@@ -27,8 +24,31 @@ class FileProxyMixin(object):
write = property(lambda self: self.file.write)
writelines = property(lambda self: self.file.writelines)
xreadlines = property(lambda self: self.file.xreadlines)
- if six.PY3:
- seekable = property(lambda self: self.file.seekable)
+
+ @property
+ def closed(self):
+ return not self.file or self.file.closed
+
+ def readable(self):
+ if self.closed:
+ return False
+ if hasattr(self.file, 'readable'):
+ return self.file.readable()
+ return True
+
+ def writable(self):
+ if self.closed:
+ return False
+ if hasattr(self.file, 'writable'):
+ return self.file.writable()
+ return 'w' in getattr(self.file, 'mode', '')
+
+ def seekable(self):
+ if self.closed:
+ return False
+ if hasattr(self.file, 'seekable'):
+ return self.file.seekable()
+ return True
def __iter__(self):
return iter(self.file)