diff options
| author | Claude Paroz <claude@2xlibre.net> | 2017-01-07 12:11:46 +0100 |
|---|---|---|
| committer | Claude Paroz <claude@2xlibre.net> | 2017-01-18 21:33:28 +0100 |
| commit | 2b281cc35ed9d997614ca3c416928d7fabfef1ad (patch) | |
| tree | d3e73cf44b15139aa9f1f53e398942ba64f5e190 /django/utils | |
| parent | 7b2f2e74adb36a4334e83130f6abc2f79d395235 (diff) | |
Refs #23919 -- Removed most of remaining six usage
Thanks Tim Graham for the review.
Diffstat (limited to 'django/utils')
| -rw-r--r-- | django/utils/_os.py | 1 | ||||
| -rw-r--r-- | django/utils/autoreload.py | 7 | ||||
| -rw-r--r-- | django/utils/crypto.py | 1 | ||||
| -rw-r--r-- | django/utils/datastructures.py | 6 | ||||
| -rw-r--r-- | django/utils/dateparse.py | 9 | ||||
| -rw-r--r-- | django/utils/encoding.py | 3 | ||||
| -rw-r--r-- | django/utils/feedgenerator.py | 4 | ||||
| -rw-r--r-- | django/utils/functional.py | 4 | ||||
| -rw-r--r-- | django/utils/html.py | 9 | ||||
| -rw-r--r-- | django/utils/html_parser.py | 8 | ||||
| -rw-r--r-- | django/utils/http.py | 8 | ||||
| -rw-r--r-- | django/utils/ipv6.py | 1 | ||||
| -rw-r--r-- | django/utils/regex_helper.py | 1 | ||||
| -rw-r--r-- | django/utils/termcolors.py | 4 | ||||
| -rw-r--r-- | django/utils/text.py | 7 | ||||
| -rw-r--r-- | django/utils/translation/template.py | 2 |
16 files changed, 31 insertions, 44 deletions
diff --git a/django/utils/_os.py b/django/utils/_os.py index ddf2132f5f..6507e58764 100644 --- a/django/utils/_os.py +++ b/django/utils/_os.py @@ -5,7 +5,6 @@ from os.path import abspath, dirname, join, normcase, sep from django.core.exceptions import SuspiciousFileOperation from django.utils.encoding import force_text - abspathu = abspath diff --git a/django/utils/autoreload.py b/django/utils/autoreload.py index e7c9acbaea..d6a5b1a319 100644 --- a/django/utils/autoreload.py +++ b/django/utils/autoreload.py @@ -35,12 +35,13 @@ import sys import time import traceback +import _thread + 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 -from django.utils.six.moves import _thread as thread # This import does nothing, but it's necessary to avoid some race conditions # in the threading module. See http://code.djangoproject.com/ticket/2330 . @@ -293,7 +294,7 @@ def restart_with_reloader(): def python_reloader(main_func, args, kwargs): if os.environ.get("RUN_MAIN") == "true": - thread.start_new_thread(main_func, args, kwargs) + _thread.start_new_thread(main_func, args, kwargs) try: reloader_thread() except KeyboardInterrupt: @@ -311,7 +312,7 @@ def python_reloader(main_func, args, kwargs): def jython_reloader(main_func, args, kwargs): from _systemrestart import SystemRestart - thread.start_new_thread(main_func, args) + _thread.start_new_thread(main_func, args) while True: if code_changed(): raise SystemRestart diff --git a/django/utils/crypto.py b/django/utils/crypto.py index 554958b6ee..74dd9fd7b0 100644 --- a/django/utils/crypto.py +++ b/django/utils/crypto.py @@ -10,7 +10,6 @@ import time from django.conf import settings from django.utils.encoding import force_bytes -from django.utils.six.moves import range # Use the system PRNG if possible try: diff --git a/django/utils/datastructures.py b/django/utils/datastructures.py index 7367924600..bb8166a734 100644 --- a/django/utils/datastructures.py +++ b/django/utils/datastructures.py @@ -1,8 +1,6 @@ import copy from collections import OrderedDict -from django.utils import six - class OrderedSet(object): """ @@ -189,7 +187,7 @@ class MultiValueDict(dict): def lists(self): """Yields (key, list) pairs.""" - return six.iteritems(super(MultiValueDict, self)) + return iter(super(MultiValueDict, self).items()) def values(self): """Yield the last value on every key list.""" @@ -218,7 +216,7 @@ class MultiValueDict(dict): self.setlistdefault(key).append(value) except TypeError: raise ValueError("MultiValueDict.update() takes either a MultiValueDict or dictionary") - for key, value in six.iteritems(kwargs): + for key, value in kwargs.items(): self.setlistdefault(key).append(value) def dict(self): diff --git a/django/utils/dateparse.py b/django/utils/dateparse.py index b2020b5281..d091100a0d 100644 --- a/django/utils/dateparse.py +++ b/django/utils/dateparse.py @@ -8,7 +8,6 @@ import datetime import re -from django.utils import six from django.utils.timezone import get_fixed_timezone, utc date_re = re.compile( @@ -60,7 +59,7 @@ def parse_date(value): """ match = date_re.match(value) if match: - kw = {k: int(v) for k, v in six.iteritems(match.groupdict())} + kw = {k: int(v) for k, v in match.groupdict().items()} return datetime.date(**kw) @@ -78,7 +77,7 @@ def parse_time(value): kw = match.groupdict() if kw['microsecond']: kw['microsecond'] = kw['microsecond'].ljust(6, '0') - kw = {k: int(v) for k, v in six.iteritems(kw) if v is not None} + kw = {k: int(v) for k, v in kw.items() if v is not None} return datetime.time(**kw) @@ -105,7 +104,7 @@ def parse_datetime(value): if tzinfo[0] == '-': offset = -offset tzinfo = get_fixed_timezone(offset) - kw = {k: int(v) for k, v in six.iteritems(kw) if v is not None} + kw = {k: int(v) for k, v in kw.items() if v is not None} kw['tzinfo'] = tzinfo return datetime.datetime(**kw) @@ -127,5 +126,5 @@ def parse_duration(value): kw['microseconds'] = kw['microseconds'].ljust(6, '0') if kw.get('seconds') and kw.get('microseconds') and kw['seconds'].startswith('-'): kw['microseconds'] = '-' + kw['microseconds'] - kw = {k: float(v) for k, v in six.iteritems(kw) if v is not None} + kw = {k: float(v) for k, v in kw.items() if v is not None} return sign * datetime.timedelta(**kw) diff --git a/django/utils/encoding.py b/django/utils/encoding.py index abd17526c6..71c2985e27 100644 --- a/django/utils/encoding.py +++ b/django/utils/encoding.py @@ -2,11 +2,10 @@ import codecs import datetime import locale from decimal import Decimal -from urllib.parse import unquote_to_bytes +from urllib.parse import quote, unquote_to_bytes from django.utils import six from django.utils.functional import Promise -from django.utils.six.moves.urllib.parse import quote class DjangoUnicodeDecodeError(UnicodeDecodeError): diff --git a/django/utils/feedgenerator.py b/django/utils/feedgenerator.py index fbab58b905..33ef20e16b 100644 --- a/django/utils/feedgenerator.py +++ b/django/utils/feedgenerator.py @@ -22,11 +22,11 @@ For definitions of the different versions of RSS, see: http://web.archive.org/web/20110718035220/http://diveintomark.org/archives/2004/02/04/incompatible-rss """ import datetime +from io import StringIO +from urllib.parse import urlparse from django.utils import datetime_safe from django.utils.encoding import force_text, iri_to_uri -from django.utils.six import StringIO -from django.utils.six.moves.urllib.parse import urlparse from django.utils.timezone import utc from django.utils.xmlutils import SimplerXMLGenerator diff --git a/django/utils/functional.py b/django/utils/functional.py index 3e35582cbf..0efce6c635 100644 --- a/django/utils/functional.py +++ b/django/utils/functional.py @@ -2,8 +2,6 @@ import copy import operator from functools import total_ordering, wraps -from django.utils import six - # You can't trivially replace this with `functools.partial` because this binds # to classes and returns bound instances, whereas functools.partial (on @@ -193,7 +191,7 @@ def keep_lazy(*resultclasses): @wraps(func) def wrapper(*args, **kwargs): - for arg in list(args) + list(six.itervalues(kwargs)): + for arg in list(args) + list(kwargs.values()): if isinstance(arg, Promise): break else: diff --git a/django/utils/html.py b/django/utils/html.py index 430350fed6..1fb39bb9b6 100644 --- a/django/utils/html.py +++ b/django/utils/html.py @@ -1,15 +1,14 @@ """HTML utilities suitable for global use.""" import re +from urllib.parse import ( + parse_qsl, quote, unquote, urlencode, urlsplit, urlunsplit, +) -from django.utils import six from django.utils.encoding import force_str, force_text from django.utils.functional import keep_lazy, keep_lazy_text from django.utils.http import RFC3986_GENDELIMS, RFC3986_SUBDELIMS from django.utils.safestring import SafeData, SafeText, mark_safe -from django.utils.six.moves.urllib.parse import ( - parse_qsl, quote, unquote, urlencode, urlsplit, urlunsplit, -) from django.utils.text import normalize_newlines from .html_parser import HTMLParseError, HTMLParser @@ -93,7 +92,7 @@ def format_html(format_string, *args, **kwargs): of str.format or % interpolation to build up small HTML fragments. """ args_safe = map(conditional_escape, args) - kwargs_safe = {k: conditional_escape(v) for (k, v) in six.iteritems(kwargs)} + kwargs_safe = {k: conditional_escape(v) for (k, v) in kwargs.items()} return mark_safe(format_string.format(*args_safe, **kwargs_safe)) diff --git a/django/utils/html_parser.py b/django/utils/html_parser.py index d272004f77..e3e19ee9c3 100644 --- a/django/utils/html_parser.py +++ b/django/utils/html_parser.py @@ -1,14 +1,14 @@ -from django.utils.six.moves import html_parser as _html_parser +import html.parser try: - HTMLParseError = _html_parser.HTMLParseError + HTMLParseError = html.parser.HTMLParseError except AttributeError: # create a dummy class for Python 3.5+ where it's been removed class HTMLParseError(Exception): pass -class HTMLParser(_html_parser.HTMLParser): +class HTMLParser(html.parser.HTMLParser): """Explicitly set convert_charrefs to be False. This silences a deprecation warning on Python 3.4, but we can't do @@ -16,4 +16,4 @@ class HTMLParser(_html_parser.HTMLParser): argument. """ def __init__(self, convert_charrefs=False, **kwargs): - _html_parser.HTMLParser.__init__(self, convert_charrefs=convert_charrefs, **kwargs) + html.parser.HTMLParser.__init__(self, convert_charrefs=convert_charrefs, **kwargs) diff --git a/django/utils/http.py b/django/utils/http.py index 0308e14676..ae23eec06a 100644 --- a/django/utils/http.py +++ b/django/utils/http.py @@ -7,6 +7,10 @@ import unicodedata import warnings from binascii import Error as BinasciiError from email.utils import formatdate +from urllib.parse import ( + quote, quote_plus, unquote, unquote_plus, urlencode as original_urlencode, + urlparse, +) from django.core.exceptions import TooManyFieldsSent from django.utils import six @@ -14,10 +18,6 @@ from django.utils.datastructures import MultiValueDict from django.utils.deprecation import RemovedInDjango21Warning from django.utils.encoding import force_bytes, force_str, force_text from django.utils.functional import keep_lazy_text -from django.utils.six.moves.urllib.parse import ( - quote, quote_plus, unquote, unquote_plus, urlencode as original_urlencode, - urlparse, -) # based on RFC 7232, Appendix C ETAG_MATCH = re.compile(r''' diff --git a/django/utils/ipv6.py b/django/utils/ipv6.py index c41f1e2b46..a1e63be727 100644 --- a/django/utils/ipv6.py +++ b/django/utils/ipv6.py @@ -4,7 +4,6 @@ import re from django.core.exceptions import ValidationError -from django.utils.six.moves import range from django.utils.translation import ugettext_lazy as _ diff --git a/django/utils/regex_helper.py b/django/utils/regex_helper.py index bc4a09b359..f5cfc57156 100644 --- a/django/utils/regex_helper.py +++ b/django/utils/regex_helper.py @@ -8,7 +8,6 @@ should be good enough for a large class of URLS, however. import warnings from django.utils.deprecation import RemovedInDjango21Warning -from django.utils.six.moves import zip # Mapping of an escape character to a representative of that class. So, e.g., # "\w" is replaced by "x" in a reverse URL. A value of None means to ignore diff --git a/django/utils/termcolors.py b/django/utils/termcolors.py index 87ed8c1187..f75e068187 100644 --- a/django/utils/termcolors.py +++ b/django/utils/termcolors.py @@ -2,8 +2,6 @@ termcolors.py """ -from django.utils import six - color_names = ('black', 'red', 'green', 'yellow', 'blue', 'magenta', 'cyan', 'white') foreground = {color_names[x]: '3%s' % x for x in range(8)} background = {color_names[x]: '4%s' % x for x in range(8)} @@ -44,7 +42,7 @@ def colorize(text='', opts=(), **kwargs): code_list = [] if text == '' and len(opts) == 1 and opts[0] == 'reset': return '\x1b[%sm' % RESET - for k, v in six.iteritems(kwargs): + for k, v in kwargs.items(): if k == 'fg': code_list.append(foreground[v]) elif k == 'bg': diff --git a/django/utils/text.py b/django/utils/text.py index 15a9b6160a..d716a0b345 100644 --- a/django/utils/text.py +++ b/django/utils/text.py @@ -1,15 +1,14 @@ +import html.entities import re import unicodedata from gzip import GzipFile from io import BytesIO -from django.utils import six from django.utils.encoding import force_text from django.utils.functional import ( SimpleLazyObject, keep_lazy, keep_lazy_text, lazy, ) from django.utils.safestring import SafeText, mark_safe -from django.utils.six.moves import html_entities from django.utils.translation import pgettext, ugettext as _, ugettext_lazy @@ -369,12 +368,12 @@ def _replace_entity(match): c = int(text[1:], 16) else: c = int(text) - return six.unichr(c) + return chr(c) except ValueError: return match.group(0) else: try: - return six.unichr(html_entities.name2codepoint[text]) + return chr(html.entities.name2codepoint[text]) except (ValueError, KeyError): return match.group(0) diff --git a/django/utils/translation/template.py b/django/utils/translation/template.py index b6d8832f9c..42ff84dc27 100644 --- a/django/utils/translation/template.py +++ b/django/utils/translation/template.py @@ -1,12 +1,12 @@ import re import warnings +from io import StringIO from django.template.base import ( TOKEN_BLOCK, TOKEN_COMMENT, TOKEN_TEXT, TOKEN_VAR, TRANSLATOR_COMMENT_MARK, Lexer, ) from django.utils.encoding import force_text -from django.utils.six import StringIO from . import TranslatorCommentWarning, trim_whitespace |
