summaryrefslogtreecommitdiff
path: root/django/core/files/storage.py
diff options
context:
space:
mode:
authorClaude Paroz <claude@2xlibre.net>2012-08-29 15:13:20 +0200
committerClaude Paroz <claude@2xlibre.net>2012-08-29 16:37:37 +0200
commit4e70ad11d29bde54b846920ce0dcf8d10741d3ae (patch)
treeab5ae6c4212571d09aad681f16f66326f7962373 /django/core/files/storage.py
parentb5240d25c1bf724f0008478e7f6cccd0a6d6bd1e (diff)
Made FileSystemStorage accept both text and byte streams
Thanks Alexey Boriskin for his help on the patch.
Diffstat (limited to 'django/core/files/storage.py')
-rw-r--r--django/core/files/storage.py11
1 files changed, 9 insertions, 2 deletions
diff --git a/django/core/files/storage.py b/django/core/files/storage.py
index 7542dcda46..0b300cd31e 100644
--- a/django/core/files/storage.py
+++ b/django/core/files/storage.py
@@ -195,11 +195,18 @@ class FileSystemStorage(Storage):
fd = os.open(full_path, os.O_WRONLY | os.O_CREAT | os.O_EXCL | getattr(os, 'O_BINARY', 0))
try:
locks.lock(fd, locks.LOCK_EX)
+ _file = None
for chunk in content.chunks():
- os.write(fd, chunk)
+ if _file is None:
+ mode = 'wb' if isinstance(chunk, bytes) else 'wt'
+ _file = os.fdopen(fd, mode)
+ _file.write(chunk)
finally:
locks.unlock(fd)
- os.close(fd)
+ if _file is not None:
+ _file.close()
+ else:
+ os.close(fd)
except OSError as e:
if e.errno == errno.EEXIST:
# Ooops, the file exists. We need a new file name.