mirror of
				https://github.com/django/django.git
				synced 2025-10-31 09:41:08 +00:00 
			
		
		
		
	Refs #23919 -- Removed misc Python 2/3 references.
This commit is contained in:
		| @@ -57,8 +57,8 @@ class AppConfig: | ||||
|         """Attempt to determine app's filesystem path from its module.""" | ||||
|         # See #21874 for extended discussion of the behavior of this method in | ||||
|         # various cases. | ||||
|         # Convert paths to list because Python 3's _NamespacePath does not | ||||
|         # support indexing. | ||||
|         # Convert paths to list because Python's _NamespacePath doesn't support | ||||
|         # indexing. | ||||
|         paths = list(getattr(module, '__path__', [])) | ||||
|         if len(paths) != 1: | ||||
|             filename = getattr(module, '__file__', None) | ||||
|   | ||||
| @@ -419,8 +419,7 @@ class BCryptSHA256PasswordHasher(BasePasswordHasher): | ||||
|         # Hash the password prior to using bcrypt to prevent password | ||||
|         # truncation as described in #20138. | ||||
|         if self.digest is not None: | ||||
|             # Use binascii.hexlify() because a hex encoded bytestring is | ||||
|             # Unicode on Python 3. | ||||
|             # Use binascii.hexlify() because a hex encoded bytestring is str. | ||||
|             password = binascii.hexlify(self.digest(force_bytes(password)).digest()) | ||||
|         else: | ||||
|             password = force_bytes(password) | ||||
|   | ||||
| @@ -298,7 +298,7 @@ def password_reset_confirm(request, uidb64=None, token=None, | ||||
|     else: | ||||
|         post_reset_redirect = resolve_url(post_reset_redirect) | ||||
|     try: | ||||
|         # urlsafe_base64_decode() decodes to bytestring on Python 3 | ||||
|         # urlsafe_base64_decode() decodes to bytestring | ||||
|         uid = force_text(urlsafe_base64_decode(uidb64)) | ||||
|         user = UserModel._default_manager.get(pk=uid) | ||||
|     except (TypeError, ValueError, OverflowError, UserModel.DoesNotExist): | ||||
| @@ -442,7 +442,7 @@ class PasswordResetConfirmView(PasswordContextMixin, FormView): | ||||
|  | ||||
|     def get_user(self, uidb64): | ||||
|         try: | ||||
|             # urlsafe_base64_decode() decodes to bytestring on Python 3 | ||||
|             # urlsafe_base64_decode() decodes to bytestring | ||||
|             uid = force_text(urlsafe_base64_decode(uidb64)) | ||||
|             user = UserModel._default_manager.get(pk=uid) | ||||
|         except (TypeError, ValueError, OverflowError, UserModel.DoesNotExist): | ||||
|   | ||||
| @@ -324,8 +324,8 @@ class EmailMessage: | ||||
|                     try: | ||||
|                         content = content.decode('utf-8') | ||||
|                     except UnicodeDecodeError: | ||||
|                         # If mimetype suggests the file is text but it's actually | ||||
|                         # binary, read() will raise a UnicodeDecodeError on Python 3. | ||||
|                         # If mimetype suggests the file is text but it's | ||||
|                         # actually binary, read() raises a UnicodeDecodeError. | ||||
|                         mimetype = DEFAULT_ATTACHMENT_MIME_TYPE | ||||
|  | ||||
|             self.attachments.append((filename, content, mimetype)) | ||||
|   | ||||
| @@ -53,7 +53,7 @@ class Command(BaseCommand): | ||||
|             import rlcompleter | ||||
|             readline.set_completer(rlcompleter.Completer(imported_objects).complete) | ||||
|             # Enable tab completion on systems using libedit (e.g. Mac OSX). | ||||
|             # These lines are copied from Lib/site.py on Python 3.4. | ||||
|             # These lines are copied from Python's Lib/site.py. | ||||
|             readline_doc = getattr(readline, '__doc__', '') | ||||
|             if readline_doc is not None and 'libedit' in readline_doc: | ||||
|                 readline.parse_and_bind("bind ^I rl_complete") | ||||
|   | ||||
| @@ -322,8 +322,7 @@ class OracleParam: | ||||
|             param = Oracle_datetime.from_datetime(param) | ||||
|  | ||||
|         string_size = 0 | ||||
|         # Oracle doesn't recognize True and False correctly in Python 3. | ||||
|         # The conversion done below works both in 2 and 3. | ||||
|         # Oracle doesn't recognize True and False correctly. | ||||
|         if param is True: | ||||
|             param = 1 | ||||
|         elif param is False: | ||||
|   | ||||
| @@ -8,7 +8,6 @@ import math | ||||
| import re | ||||
| import types | ||||
| import uuid | ||||
| from importlib import import_module | ||||
|  | ||||
| from django.db import models | ||||
| from django.db.migrations.operations.base import Operation | ||||
| @@ -155,20 +154,15 @@ class FunctionTypeSerializer(BaseSerializer): | ||||
|             raise ValueError("Cannot serialize function: lambda") | ||||
|         if self.value.__module__ is None: | ||||
|             raise ValueError("Cannot serialize function %r: No module" % self.value) | ||||
|         # Python 3 is a lot easier, and only uses this branch if it's not local. | ||||
|         if getattr(self.value, "__qualname__", None) and getattr(self.value, "__module__", None): | ||||
|             if "<" not in self.value.__qualname__:  # Qualname can include <locals> | ||||
|                 return "%s.%s" % \ | ||||
|                     (self.value.__module__, self.value.__qualname__), {"import %s" % self.value.__module__} | ||||
|         # Fallback version | ||||
|  | ||||
|         module_name = self.value.__module__ | ||||
|         # Make sure it's actually there | ||||
|         module = import_module(module_name) | ||||
|         if not hasattr(module, self.value.__name__): | ||||
|             raise ValueError( | ||||
|                 "Could not find function %s in %s.\n" % (self.value.__name__, module_name) | ||||
|             ) | ||||
|         return "%s.%s" % (module_name, self.value.__name__), {"import %s" % module_name} | ||||
|  | ||||
|         if '<' not in self.value.__qualname__:  # Qualname can include <locals> | ||||
|             return '%s.%s' % (module_name, self.value.__qualname__), {'import %s' % self.value.__module__} | ||||
|  | ||||
|         raise ValueError( | ||||
|             'Could not find function %s in %s.\n' % (self.value.__name__, module_name) | ||||
|         ) | ||||
|  | ||||
|  | ||||
| class FunctoolsPartialSerializer(BaseSerializer): | ||||
|   | ||||
| @@ -258,8 +258,7 @@ def default_test_processes(): | ||||
|     """ | ||||
|     # The current implementation of the parallel test runner requires | ||||
|     # multiprocessing to start subprocesses with fork(). | ||||
|     # On Python 3.4+: if multiprocessing.get_start_method() != 'fork': | ||||
|     if not hasattr(os, 'fork'): | ||||
|     if multiprocessing.get_start_method() != 'fork': | ||||
|         return 1 | ||||
|     try: | ||||
|         return int(os.environ['DJANGO_TEST_PROCESSES']) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user