diff options
| author | Tim Graham <timograham@gmail.com> | 2017-01-20 08:01:02 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-01-20 08:01:02 -0500 |
| commit | 4e729feaa647547f25debb1cb63dec989dc41a20 (patch) | |
| tree | 7c7a38c5961bf4daf98a8cb47dc74c769563ffcf /django | |
| parent | ec4c1d6717da7a9d09d5b3ce84cccac819bb592c (diff) | |
Refs #23919 -- Removed django.utils._os.upath()/npath()/abspathu() usage.
These functions do nothing on Python 3.
Diffstat (limited to 'django')
| -rw-r--r-- | django/apps/config.py | 3 | ||||
| -rw-r--r-- | django/contrib/auth/password_validation.py | 3 | ||||
| -rw-r--r-- | django/core/files/storage.py | 4 | ||||
| -rw-r--r-- | django/core/management/__init__.py | 5 | ||||
| -rw-r--r-- | django/core/management/commands/compilemessages.py | 7 | ||||
| -rw-r--r-- | django/core/management/commands/loaddata.py | 3 | ||||
| -rw-r--r-- | django/core/management/commands/makemessages.py | 3 | ||||
| -rw-r--r-- | django/db/migrations/writer.py | 5 | ||||
| -rw-r--r-- | django/db/utils.py | 5 | ||||
| -rw-r--r-- | django/forms/renderers.py | 3 | ||||
| -rw-r--r-- | django/template/utils.py | 3 | ||||
| -rw-r--r-- | django/utils/_os.py | 11 | ||||
| -rw-r--r-- | django/utils/autoreload.py | 3 | ||||
| -rw-r--r-- | django/utils/translation/trans_real.py | 5 |
14 files changed, 25 insertions, 38 deletions
diff --git a/django/apps/config.py b/django/apps/config.py index 024643a645..78762dd612 100644 --- a/django/apps/config.py +++ b/django/apps/config.py @@ -2,7 +2,6 @@ import os from importlib import import_module from django.core.exceptions import ImproperlyConfigured -from django.utils._os import upath from django.utils.module_loading import module_has_submodule MODELS_MODULE_NAME = 'models' @@ -80,7 +79,7 @@ class AppConfig: "The app module %r has no filesystem location, " "you must configure this app with an AppConfig subclass " "with a 'path' class attribute." % (module,)) - return upath(paths[0]) + return paths[0] @classmethod def create(cls, entry): diff --git a/django/contrib/auth/password_validation.py b/django/contrib/auth/password_validation.py index a7319dbd52..23b2b6f185 100644 --- a/django/contrib/auth/password_validation.py +++ b/django/contrib/auth/password_validation.py @@ -8,7 +8,6 @@ from django.conf import settings from django.core.exceptions import ( FieldDoesNotExist, ImproperlyConfigured, ValidationError, ) -from django.utils._os import upath from django.utils.encoding import force_text from django.utils.functional import lazy from django.utils.html import format_html @@ -168,7 +167,7 @@ class CommonPasswordValidator: https://xato.net/passwords/more-top-worst-passwords/ """ DEFAULT_PASSWORD_LIST_PATH = os.path.join( - os.path.dirname(os.path.realpath(upath(__file__))), 'common-passwords.txt.gz' + os.path.dirname(os.path.realpath(__file__)), 'common-passwords.txt.gz' ) def __init__(self, password_list_path=DEFAULT_PASSWORD_LIST_PATH): diff --git a/django/core/files/storage.py b/django/core/files/storage.py index 6f2d6bfd91..a8814ddc48 100644 --- a/django/core/files/storage.py +++ b/django/core/files/storage.py @@ -9,7 +9,7 @@ from django.core.files import File, locks from django.core.files.move import file_move_safe from django.core.signals import setting_changed from django.utils import timezone -from django.utils._os import abspathu, safe_join +from django.utils._os import safe_join from django.utils.crypto import get_random_string from django.utils.deconstruct import deconstructible from django.utils.encoding import filepath_to_uri, force_text @@ -201,7 +201,7 @@ class FileSystemStorage(Storage): @cached_property def location(self): - return abspathu(self.base_location) + return os.path.abspath(self.base_location) @cached_property def base_url(self): diff --git a/django/core/management/__init__.py b/django/core/management/__init__.py index 1b59dac686..ce0903dbdf 100644 --- a/django/core/management/__init__.py +++ b/django/core/management/__init__.py @@ -14,7 +14,6 @@ from django.core.management.base import ( ) from django.core.management.color import color_style from django.utils import autoreload -from django.utils._os import npath, upath from django.utils.encoding import force_text @@ -26,7 +25,7 @@ def find_commands(management_dir): Returns an empty list if no commands are defined. """ command_dir = os.path.join(management_dir, 'commands') - return [name for _, name, is_pkg in pkgutil.iter_modules([npath(command_dir)]) + return [name for _, name, is_pkg in pkgutil.iter_modules([command_dir]) if not is_pkg and not name.startswith('_')] @@ -63,7 +62,7 @@ def get_commands(): The dictionary is cached on the first call and reused on subsequent calls. """ - commands = {name: 'django.core' for name in find_commands(upath(__path__[0]))} + commands = {name: 'django.core' for name in find_commands(__path__[0])} if not settings.configured: return commands diff --git a/django/core/management/commands/compilemessages.py b/django/core/management/commands/compilemessages.py index 05fb9e5cfc..c5c7f22583 100644 --- a/django/core/management/commands/compilemessages.py +++ b/django/core/management/commands/compilemessages.py @@ -4,7 +4,6 @@ import os from django.core.management.base import BaseCommand, CommandError from django.core.management.utils import find_command, popen_wrapper -from django.utils._os import npath, upath def has_bom(fn): @@ -62,7 +61,7 @@ class Command(BaseCommand): basedirs = [os.path.join('conf', 'locale'), 'locale'] if os.environ.get('DJANGO_SETTINGS_MODULE'): from django.conf import settings - basedirs.extend(upath(path) for path in settings.LOCALE_PATHS) + basedirs.extend(settings.LOCALE_PATHS) # Walk entire tree, looking for locale directories for dirpath, dirnames, filenames in os.walk('.', topdown=True): @@ -115,13 +114,13 @@ class Command(BaseCommand): base_path = os.path.splitext(po_path)[0] # Check writability on first location - if i == 0 and not is_writable(npath(base_path + '.mo')): + if i == 0 and not is_writable(base_path + '.mo'): self.stderr.write("The po files under %s are in a seemingly not writable location. " "mo files will not be updated/created." % dirpath) return args = [self.program] + self.program_options + [ - '-o', npath(base_path + '.mo'), npath(base_path + '.po') + '-o', base_path + '.mo', base_path + '.po' ] output, errors, status = popen_wrapper(args) if status: diff --git a/django/core/management/commands/loaddata.py b/django/core/management/commands/loaddata.py index 9edd642b43..4556d9b9d8 100644 --- a/django/core/management/commands/loaddata.py +++ b/django/core/management/commands/loaddata.py @@ -17,7 +17,6 @@ from django.db import ( DEFAULT_DB_ALIAS, DatabaseError, IntegrityError, connections, router, transaction, ) -from django.utils._os import upath from django.utils.encoding import force_text from django.utils.functional import cached_property @@ -287,7 +286,7 @@ class Command(BaseCommand): dirs.append(app_dir) dirs.extend(list(fixture_dirs)) dirs.append('') - dirs = [upath(os.path.abspath(os.path.realpath(d))) for d in dirs] + dirs = [os.path.abspath(os.path.realpath(d)) for d in dirs] return dirs def parse_name(self, fixture_name): diff --git a/django/core/management/commands/makemessages.py b/django/core/management/commands/makemessages.py index 48ed70845a..5b74ddaa0d 100644 --- a/django/core/management/commands/makemessages.py +++ b/django/core/management/commands/makemessages.py @@ -14,7 +14,6 @@ from django.core.management.base import BaseCommand, CommandError from django.core.management.utils import ( find_command, handle_extensions, popen_wrapper, ) -from django.utils._os import upath from django.utils.encoding import DEFAULT_LOCALE_ENCODING from django.utils.functional import cached_property from django.utils.jslex import prepare_js_for_gettext @@ -638,7 +637,7 @@ class Command(BaseCommand): the msgs string, inserting it at the right place. msgs should be the contents of a newly created .po file. """ - django_dir = os.path.normpath(os.path.join(os.path.dirname(upath(django.__file__)))) + django_dir = os.path.normpath(os.path.join(os.path.dirname(django.__file__))) if self.domain == 'djangojs': domains = ('djangojs', 'django') else: diff --git a/django/db/migrations/writer.py b/django/db/migrations/writer.py index 5a3378fe4b..09d8f1f13b 100644 --- a/django/db/migrations/writer.py +++ b/django/db/migrations/writer.py @@ -7,7 +7,6 @@ from django.apps import apps from django.db import migrations from django.db.migrations.loader import MigrationLoader from django.db.migrations.serializer import serializer_factory -from django.utils._os import upath from django.utils.encoding import force_text from django.utils.inspect import get_func_args from django.utils.module_loading import module_dir @@ -229,7 +228,7 @@ class MigrationWriter: pass else: try: - return upath(module_dir(migrations_module)) + return module_dir(migrations_module) except ValueError: pass @@ -250,7 +249,7 @@ class MigrationWriter: continue else: try: - base_dir = upath(module_dir(base_module)) + base_dir = module_dir(base_module) except ValueError: continue else: diff --git a/django/db/utils.py b/django/db/utils.py index 8ca3f860b3..a35de01ffa 100644 --- a/django/db/utils.py +++ b/django/db/utils.py @@ -6,7 +6,6 @@ from threading import local from django.conf import settings from django.core.exceptions import ImproperlyConfigured from django.utils import six -from django.utils._os import npath, upath from django.utils.functional import cached_property from django.utils.module_loading import import_string @@ -116,10 +115,10 @@ def load_backend(backend_name): except ImportError as e_user: # The database backend wasn't found. Display a helpful error message # listing all possible (built-in) database backends. - backend_dir = os.path.join(os.path.dirname(upath(__file__)), 'backends') + backend_dir = os.path.join(os.path.dirname(__file__), 'backends') try: builtin_backends = [ - name for _, name, ispkg in pkgutil.iter_modules([npath(backend_dir)]) + name for _, name, ispkg in pkgutil.iter_modules([backend_dir]) if ispkg and name not in {'base', 'dummy', 'postgresql_psycopg2'} ] except EnvironmentError: diff --git a/django/forms/renderers.py b/django/forms/renderers.py index 3023d477e4..435a12d852 100644 --- a/django/forms/renderers.py +++ b/django/forms/renderers.py @@ -4,7 +4,6 @@ import os from django.conf import settings from django.template.backends.django import DjangoTemplates from django.template.loader import get_template -from django.utils._os import upath from django.utils.functional import cached_property from django.utils.module_loading import import_string @@ -14,7 +13,7 @@ except ImportError: def Jinja2(params): raise ImportError("jinja2 isn't installed") -ROOT = upath(os.path.dirname(__file__)) +ROOT = os.path.dirname(__file__) @functools.lru_cache() diff --git a/django/template/utils.py b/django/template/utils.py index 852baca566..fde2f64d13 100644 --- a/django/template/utils.py +++ b/django/template/utils.py @@ -5,7 +5,6 @@ from collections import Counter, OrderedDict from django.apps import apps from django.conf import settings from django.core.exceptions import ImproperlyConfigured -from django.utils._os import upath from django.utils.functional import cached_property from django.utils.module_loading import import_string @@ -103,6 +102,6 @@ def get_app_template_dirs(dirname): continue template_dir = os.path.join(app_config.path, dirname) if os.path.isdir(template_dir): - template_dirs.append(upath(template_dir)) + template_dirs.append(template_dir) # Immutable return value because it will be cached and shared by callers. return tuple(template_dirs) diff --git a/django/utils/_os.py b/django/utils/_os.py index 6507e58764..8309e08fbf 100644 --- a/django/utils/_os.py +++ b/django/utils/_os.py @@ -5,20 +5,19 @@ from os.path import abspath, dirname, join, normcase, sep from django.core.exceptions import SuspiciousFileOperation from django.utils.encoding import force_text +# For backwards-compatibility in Django 2.0 abspathu = abspath def upath(path): - """ - Always return a unicode path. - """ + """Always return a unicode path (did something for Python 2).""" return path def npath(path): """ Always return a native path, that is unicode on Python 3 and bytestring on - Python 2. + Python 2. Noop for Python 3. """ return path @@ -33,8 +32,8 @@ def safe_join(base, *paths): """ base = force_text(base) paths = [force_text(p) for p in paths] - final_path = abspathu(join(base, *paths)) - base_path = abspathu(base) + final_path = abspath(join(base, *paths)) + base_path = abspath(base) # Ensure final_path starts with base_path (using normcase to ensure we # don't false-negative on case insensitive operating systems like Windows), # further, one of the following conditions must be true: diff --git a/django/utils/autoreload.py b/django/utils/autoreload.py index d6a5b1a319..6255da1c84 100644 --- a/django/utils/autoreload.py +++ b/django/utils/autoreload.py @@ -41,7 +41,6 @@ from django.apps import apps from django.conf import settings from django.core.signals import request_finished from django.utils import six -from django.utils._os import npath # This import does nothing, but it's necessary to avoid some race conditions # in the threading module. See http://code.djangoproject.com/ticket/2330 . @@ -111,7 +110,7 @@ def gen_filenames(only_new=False): 'conf', 'locale'), 'locale'] for app_config in reversed(list(apps.get_app_configs())): - basedirs.append(os.path.join(npath(app_config.path), 'locale')) + basedirs.append(os.path.join(app_config.path, 'locale')) basedirs.extend(settings.LOCALE_PATHS) basedirs = [os.path.abspath(basedir) for basedir in basedirs if os.path.isdir(basedir)] diff --git a/django/utils/translation/trans_real.py b/django/utils/translation/trans_real.py index 99acda9aab..14bb0ce786 100644 --- a/django/utils/translation/trans_real.py +++ b/django/utils/translation/trans_real.py @@ -14,7 +14,6 @@ from django.conf.locale import LANG_INFO from django.core.exceptions import AppRegistryNotReady from django.core.signals import setting_changed from django.dispatch import receiver -from django.utils._os import upath from django.utils.encoding import force_text from django.utils.safestring import SafeData, mark_safe from django.utils.translation import LANGUAGE_SESSION_KEY @@ -155,7 +154,7 @@ class DjangoTranslation(gettext_module.GNUTranslations): def _init_translation_catalog(self): """Creates a base catalog using global django translations.""" - settingsfile = upath(sys.modules[settings.__module__].__file__) + settingsfile = sys.modules[settings.__module__].__file__ localedir = os.path.join(os.path.dirname(settingsfile), 'locale') translation = self._new_gnu_trans(localedir) self.merge(translation) @@ -399,7 +398,7 @@ def all_locale_paths(): Returns a list of paths to user-provides languages files. """ globalpath = os.path.join( - os.path.dirname(upath(sys.modules[settings.__module__].__file__)), 'locale') + os.path.dirname(sys.modules[settings.__module__].__file__), 'locale') return [globalpath] + list(settings.LOCALE_PATHS) |
