diff options
| author | Aymeric Augustin <aymeric.augustin@m4x.org> | 2017-01-18 22:05:41 +0100 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2017-01-18 21:45:12 -0500 |
| commit | a5563963397aeee30c32e3c1dab31bfe453ca89f (patch) | |
| tree | 6fe111ef4ea95da191037341729c7d39b87c07d7 /django | |
| parent | eb422e476f3c0070dbf200bd62d97d12150c6fd9 (diff) | |
Refs #23919 -- Replaced io.open() with open().
io.open() is an alias for open() on Python 3.
Diffstat (limited to 'django')
| -rw-r--r-- | django/core/cache/backends/filebased.py | 7 | ||||
| -rw-r--r-- | django/core/management/commands/makemessages.py | 15 | ||||
| -rw-r--r-- | django/core/management/commands/makemigrations.py | 5 | ||||
| -rw-r--r-- | django/core/management/commands/squashmigrations.py | 4 | ||||
| -rw-r--r-- | django/core/management/templates.py | 5 | ||||
| -rw-r--r-- | django/template/backends/dummy.py | 3 | ||||
| -rw-r--r-- | django/template/loaders/filesystem.py | 3 |
7 files changed, 17 insertions, 25 deletions
diff --git a/django/core/cache/backends/filebased.py b/django/core/cache/backends/filebased.py index 88509ed8de..ae5b48c054 100644 --- a/django/core/cache/backends/filebased.py +++ b/django/core/cache/backends/filebased.py @@ -2,7 +2,6 @@ import errno import glob import hashlib -import io import os import pickle import random @@ -32,7 +31,7 @@ class FileBasedCache(BaseCache): def get(self, key, default=None, version=None): fname = self._key_to_file(key, version) try: - with io.open(fname, 'rb') as f: + with open(fname, 'rb') as f: if not self._is_expired(f): return pickle.loads(zlib.decompress(f.read())) except IOError as e: @@ -47,7 +46,7 @@ class FileBasedCache(BaseCache): fd, tmp_path = tempfile.mkstemp(dir=self._dir) renamed = False try: - with io.open(fd, 'wb') as f: + with open(fd, 'wb') as f: expiry = self.get_backend_timeout(timeout) f.write(pickle.dumps(expiry, pickle.HIGHEST_PROTOCOL)) f.write(zlib.compress(pickle.dumps(value, pickle.HIGHEST_PROTOCOL))) @@ -74,7 +73,7 @@ class FileBasedCache(BaseCache): def has_key(self, key, version=None): fname = self._key_to_file(key, version) if os.path.exists(fname): - with io.open(fname, 'rb') as f: + with open(fname, 'rb') as f: return not self._is_expired(f) return False diff --git a/django/core/management/commands/makemessages.py b/django/core/management/commands/makemessages.py index 1597f9347e..dc505173b1 100644 --- a/django/core/management/commands/makemessages.py +++ b/django/core/management/commands/makemessages.py @@ -1,6 +1,5 @@ import fnmatch import glob -import io import os import re import sys @@ -106,7 +105,7 @@ class BuildFile(object): return encoding = settings.FILE_CHARSET if self.command.settings_available else 'utf-8' - with io.open(self.path, 'r', encoding=encoding) as fp: + with open(self.path, 'r', encoding=encoding) as fp: src_data = fp.read() if self.domain == 'djangojs': @@ -114,7 +113,7 @@ class BuildFile(object): elif self.domain == 'django': content = templatize(src_data, origin=self.path[2:], charset=encoding) - with io.open(self.work_path, 'w', encoding='utf-8') as fp: + with open(self.work_path, 'w', encoding='utf-8') as fp: fp.write(content) def postprocess_messages(self, msgs): @@ -190,7 +189,7 @@ def write_pot_file(potfile, msgs): header_read = True lines.append(line) msgs = '\n'.join(lines) - with io.open(potfile, 'a', encoding='utf-8') as fp: + with open(potfile, 'a', encoding='utf-8') as fp: fp.write(msgs) @@ -412,7 +411,7 @@ class Command(BaseCommand): elif self.verbosity > 0: self.stdout.write(errors) msgs = normalize_eols(msgs) - with io.open(potfile, 'w', encoding='utf-8') as fp: + with open(potfile, 'w', encoding='utf-8') as fp: fp.write(msgs) potfiles.append(potfile) return potfiles @@ -613,14 +612,14 @@ class Command(BaseCommand): elif self.verbosity > 0: self.stdout.write(errors) else: - with io.open(potfile, 'r', encoding='utf-8') as fp: + with open(potfile, 'r', encoding='utf-8') as fp: msgs = fp.read() if not self.invoked_for_django: msgs = self.copy_plural_forms(msgs, locale) msgs = normalize_eols(msgs) msgs = msgs.replace( "#. #-#-#-#-# %s.pot (PACKAGE VERSION) #-#-#-#-#\n" % self.domain, "") - with io.open(pofile, 'w', encoding='utf-8') as fp: + with open(pofile, 'w', encoding='utf-8') as fp: fp.write(msgs) if self.no_obsolete: @@ -647,7 +646,7 @@ class Command(BaseCommand): for domain in domains: django_po = os.path.join(django_dir, 'conf', 'locale', locale, 'LC_MESSAGES', '%s.po' % domain) if os.path.exists(django_po): - with io.open(django_po, 'r', encoding='utf-8') as fp: + with open(django_po, 'r', encoding='utf-8') as fp: m = plural_forms_re.search(fp.read()) if m: plural_form_line = force_str(m.group('value')) diff --git a/django/core/management/commands/makemigrations.py b/django/core/management/commands/makemigrations.py index 3364d958a9..8572bbeb95 100644 --- a/django/core/management/commands/makemigrations.py +++ b/django/core/management/commands/makemigrations.py @@ -1,4 +1,3 @@ -import io import os import sys from itertools import takewhile @@ -210,7 +209,7 @@ class Command(BaseCommand): # We just do this once per app directory_created[app_label] = True migration_string = writer.as_string() - with io.open(writer.path, "w", encoding='utf-8') as fh: + with open(writer.path, "w", encoding='utf-8') as fh: fh.write(migration_string) elif self.verbosity == 3: # Alternatively, makemigrations --dry-run --verbosity 3 @@ -289,7 +288,7 @@ class Command(BaseCommand): if not self.dry_run: # Write the merge migrations file to the disk - with io.open(writer.path, "w", encoding='utf-8') as fh: + with open(writer.path, "w", encoding='utf-8') as fh: fh.write(writer.as_string()) if self.verbosity > 0: self.stdout.write("\nCreated new merge migration %s" % writer.path) diff --git a/django/core/management/commands/squashmigrations.py b/django/core/management/commands/squashmigrations.py index 5556b24745..090e7c7dfb 100644 --- a/django/core/management/commands/squashmigrations.py +++ b/django/core/management/commands/squashmigrations.py @@ -1,5 +1,3 @@ -import io - from django.conf import settings from django.core.management.base import BaseCommand, CommandError from django.db import DEFAULT_DB_ALIAS, connections, migrations @@ -163,7 +161,7 @@ class Command(BaseCommand): # Write out the new migration file writer = MigrationWriter(new_migration) - with io.open(writer.path, "w", encoding='utf-8') as fh: + with open(writer.path, "w", encoding='utf-8') as fh: fh.write(writer.as_string()) if self.verbosity > 0: diff --git a/django/core/management/templates.py b/django/core/management/templates.py index ccc4920fe3..a53303ae38 100644 --- a/django/core/management/templates.py +++ b/django/core/management/templates.py @@ -1,6 +1,5 @@ import cgi import errno -import io import mimetypes import os import posixpath @@ -158,11 +157,11 @@ class TemplateCommand(BaseCommand): # Only render the Python files, as we don't want to # accidentally render Django templates files if new_path.endswith(extensions) or filename in extra_files: - with io.open(old_path, 'r', encoding='utf-8') as template_file: + with open(old_path, 'r', encoding='utf-8') as template_file: content = template_file.read() template = Engine().from_string(content) content = template.render(context) - with io.open(new_path, 'w', encoding='utf-8') as new_file: + with open(new_path, 'w', encoding='utf-8') as new_file: new_file.write(content) else: shutil.copyfile(old_path, new_path) diff --git a/django/template/backends/dummy.py b/django/template/backends/dummy.py index 015cb8bda0..ce658ec764 100644 --- a/django/template/backends/dummy.py +++ b/django/template/backends/dummy.py @@ -1,5 +1,4 @@ import errno -import io import string from django.conf import settings @@ -30,7 +29,7 @@ class TemplateStrings(BaseEngine): tried = [] for template_file in self.iter_template_filenames(template_name): try: - with io.open(template_file, encoding=settings.FILE_CHARSET) as fp: + with open(template_file, encoding=settings.FILE_CHARSET) as fp: template_code = fp.read() except IOError as e: if e.errno == errno.ENOENT: diff --git a/django/template/loaders/filesystem.py b/django/template/loaders/filesystem.py index bd126a0c6b..658e702143 100644 --- a/django/template/loaders/filesystem.py +++ b/django/template/loaders/filesystem.py @@ -3,7 +3,6 @@ Wrapper for loading templates from the filesystem. """ import errno -import io from django.core.exceptions import SuspiciousFileOperation from django.template import Origin, TemplateDoesNotExist @@ -23,7 +22,7 @@ class Loader(BaseLoader): def get_contents(self, origin): try: - with io.open(origin.name, encoding=self.engine.file_charset) as fp: + with open(origin.name, encoding=self.engine.file_charset) as fp: return fp.read() except IOError as e: if e.errno == errno.ENOENT: |
