mirror of
				https://github.com/django/django.git
				synced 2025-10-31 09:41:08 +00:00 
			
		
		
		
	Refs #23919 -- Removed django.utils._os.upath()/npath()/abspathu() usage.
These functions do nothing on Python 3.
This commit is contained in:
		| @@ -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): | ||||
|   | ||||
| @@ -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): | ||||
|   | ||||
| @@ -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): | ||||
|   | ||||
| @@ -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 | ||||
|   | ||||
| @@ -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: | ||||
|   | ||||
| @@ -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): | ||||
|   | ||||
| @@ -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: | ||||
|   | ||||
| @@ -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: | ||||
|   | ||||
| @@ -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: | ||||
|   | ||||
| @@ -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() | ||||
|   | ||||
| @@ -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) | ||||
|   | ||||
| @@ -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: | ||||
|   | ||||
| @@ -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)] | ||||
|   | ||||
| @@ -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) | ||||
|  | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user