summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClaude Paroz <claude@2xlibre.net>2016-10-20 16:59:01 +0200
committerClaude Paroz <claude@2xlibre.net>2016-10-20 16:59:01 +0200
commit1f5b69917dae2a2d5414560f3de9cd95a9adb812 (patch)
treec46519c758c9e26058c84a474e5fc58451237815
parentd75c2ccaa00035bcdeece1099cf9d40c7f53cd80 (diff)
Optimized file copy in TemplateCommand
-rw-r--r--django/core/management/templates.py13
1 files changed, 7 insertions, 6 deletions
diff --git a/django/core/management/templates.py b/django/core/management/templates.py
index ca4b935d79..ee6e284a63 100644
--- a/django/core/management/templates.py
+++ b/django/core/management/templates.py
@@ -1,5 +1,6 @@
import cgi
import errno
+import io
import mimetypes
import os
import posixpath
@@ -158,15 +159,15 @@ class TemplateCommand(BaseCommand):
# Only render the Python files, as we don't want to
# accidentally render Django templates files
- with open(old_path, 'rb') as template_file:
- content = template_file.read()
if new_path.endswith(extensions) or filename in extra_files:
- content = content.decode('utf-8')
+ with io.open(old_path, 'r', encoding='utf-8') as template_file:
+ content = template_file.read()
template = Engine().from_string(content)
content = template.render(context)
- content = content.encode('utf-8')
- with open(new_path, 'wb') as new_file:
- new_file.write(content)
+ with io.open(new_path, 'w', encoding='utf-8') as new_file:
+ new_file.write(content)
+ else:
+ shutil.copyfile(old_path, new_path)
if self.verbosity >= 2:
self.stdout.write("Creating %s\n" % new_path)