Replaced use of six with the equivalent pure python3 constructs.

- Legacy-Id: 16428
This commit is contained in:
Henrik Levkowetz 2019-07-08 10:43:47 +00:00
parent 671b4035ea
commit f481f5c3e6
16 changed files with 24 additions and 55 deletions

View file

@ -1,6 +1,5 @@
# Copyright The IETF Trust 2014-2019, All Rights Reserved
import re
import six
import datetime
from urllib.parse import urlencode
@ -76,7 +75,7 @@ class TimedeltaField(ApiField):
if value is None:
return None
if isinstance(value, six.string_types):
if isinstance(value, str):
match = TIMEDELTA_REGEX.search(value)
if match:
@ -91,7 +90,7 @@ class TimedeltaField(ApiField):
value = super(TimedeltaField, self).hydrate(bundle)
if value and not hasattr(value, 'seconds'):
if isinstance(value, six.string_types):
if isinstance(value, str):
try:
match = TIMEDELTA_REGEX.search(value)
@ -117,7 +116,7 @@ class ToOneField(tastypie.fields.ToOneField):
if callable(self.attribute):
previous_obj = bundle.obj
foreign_obj = self.attribute(bundle)
elif isinstance(self.attribute, six.string_types):
elif isinstance(self.attribute, str):
foreign_obj = bundle.obj
for attr in self._attrs:

View file

@ -5,7 +5,6 @@ import datetime
import logging
import os
import rfc2html
import six
from django.db import models
from django.core import checks
@ -430,7 +429,7 @@ class DocumentInfo(models.Model):
def relations_that_doc(self, relationship):
"""Return the related-document objects that describe a given relationship from self to other documents."""
if isinstance(relationship, six.string_types):
if isinstance(relationship, str):
relationship = ( relationship, )
if not isinstance(relationship, tuple):
raise TypeError("Expected a string or tuple, received %s" % type(relationship))

View file

@ -7,7 +7,6 @@ import calendar
import datetime
import io
import bleach
import six
from pyquery import PyQuery
from tempfile import NamedTemporaryFile

View file

@ -3,7 +3,6 @@
import datetime, os
import operator
import six
from email.utils import parseaddr
from form_utils.forms import BetterModelForm
@ -199,7 +198,7 @@ class CustomModelMultipleChoiceField(forms.ModelMultipleChoiceField):
if isinstance(value, QuerySet):
return value
if (hasattr(value, '__iter__') and
not isinstance(value, six.text_type) and
not isinstance(value, str) and
not hasattr(value, '_meta')):
return [super(CustomModelMultipleChoiceField, self).prepare_value(v) for v in value]
return super(CustomModelMultipleChoiceField, self).prepare_value(value)

View file

@ -1,6 +1,5 @@
# Copyright The IETF Trust 2012-2019, All Rights Reserved
import json
import six
from collections import Counter
from urllib.parse import urlencode
@ -110,7 +109,7 @@ class SearchablePersonsField(forms.CharField):
#if self.only_users:
# objs = objs.exclude(person__user=None)
found_pks = [ six.text_type(o.pk) for o in objs]
found_pks = [ str(o.pk) for o in objs]
failed_pks = [x for x in pks if x not in found_pks]
if failed_pks:
raise forms.ValidationError("Could not recognize the following {model_name}s: {pks}. You can only input {model_name}s already registered in the Datatracker.".format(pks=", ".join(failed_pks), model_name=self.model.__name__.lower()))

View file

@ -3,7 +3,6 @@
import datetime
import email.utils
import email.header
import six
import uuid
from hashids import Hashids
@ -360,7 +359,7 @@ class PersonalApiKey(models.Model):
for v in (str(self.id), str(self.person.id), self.created.isoformat(), self.endpoint, str(self.valid), self.salt, settings.SECRET_KEY):
v = smart_bytes(v)
hash.update(v)
key = struct.pack(KEY_STRUCT, self.id, six.binary_type(self.salt), hash.digest())
key = struct.pack(KEY_STRUCT, self.id, bytes(self.salt), hash.digest())
self._cached_hash = base64.urlsafe_b64encode(key).decode('ascii')
return self._cached_hash

View file

@ -7,7 +7,6 @@ import sys
import os
import os.path
import argparse
import six
import time
basedir = os.path.abspath(os.path.join(os.path.dirname(__file__), "../.."))
@ -129,10 +128,10 @@ for doc in docs_qs.prefetch_related("docalias", "formal_languages", "documentaut
# it's an extra author - skip those extra authors
seen = set()
for full, _, _, _, _, email, country, company in d.get_author_list():
assert full is None or isinstance(full, six.text_type)
assert email is None or isinstance(email, six.text_type)
assert country is None or isinstance(country, six.text_type)
assert company is None or isinstance(company, six.text_type)
assert full is None or isinstance(full, str)
assert email is None or isinstance(email, str)
assert country is None or isinstance(country, str)
assert company is None or isinstance(company, str)
#full, email, country, company = [ unicode(s) for s in [full, email, country, company, ] ]
if email in seen:
continue

View file

@ -4,7 +4,6 @@
import datetime
import os
import re
import six # pyflakes:ignore
import xml2rfc
from django.conf import settings
@ -457,7 +456,7 @@ def ensure_person_email_info_exists(name, email, docname):
person = Person()
person.name = name
person.name_from_draft = name
log.assertion('isinstance(person.name, six.text_type)')
log.assertion('isinstance(person.name, str)')
person.ascii = unidecode_name(person.name)
person.save()
else:

View file

@ -40,7 +40,6 @@ import os
import os.path
import re
import stat
import six
import sys
import time
@ -129,7 +128,7 @@ def acronym_match(s, l):
class Draft():
def __init__(self, text, source, name_from_source=False):
assert isinstance(text, six.text_type)
assert isinstance(text, str)
self.source = source
self.rawtext = text
self.name_from_source = name_from_source

View file

@ -1,7 +1,6 @@
# Copyright The IETF Trust 2012-2019, All Rights Reserved
import re
import six
import datetime
import debug # pyflakes:ignore
@ -104,7 +103,7 @@ def parse_duration_ext(value):
return parse_duration(value)
else:
kw = match.groupdict()
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 datetime.timedelta(**kw)
class DurationField(forms.DurationField):

View file

@ -11,7 +11,6 @@ import lxml.html.clean
import debug # pyflakes:ignore
from django.utils.functional import keep_lazy
from django.utils import six
acceptable_tags = ('a', 'abbr', 'acronym', 'address', 'b', 'big',
'blockquote', 'body', 'br', 'caption', 'center', 'cite', 'code', 'col',
@ -32,7 +31,7 @@ def unescape(text):
"""
return text.replace('&#39;', "'").replace('&quot;', '"').replace('&gt;', '>').replace('&lt;', '<' ).replace('&amp;', '&')
@keep_lazy(six.text_type)
@keep_lazy(str)
def remove_tags(html, tags):
"""Returns the given HTML sanitized, and with the given tags removed."""
allowed = set(acceptable_tags) - set([ t.lower() for t in tags ])

View file

@ -9,7 +9,6 @@ from difflib import ndiff
from django.conf import settings
from django.core.management.base import BaseCommand, CommandError
from django.utils.six import string_types
import debug # pyflakes:ignore
@ -57,7 +56,7 @@ class Command(BaseCommand):
valid_sections = ['template', 'url', 'code']
def read_coverage(self, filename, version=None):
if isinstance(filename, string_types):
if isinstance(filename, str):
try:
if filename.endswith(".gz"):
file = gzip.open(filename, "rb")

View file

@ -1,9 +1,10 @@
# Copyright The IETF Trust 2015-2019, All Rights Reserved
import os
import tempfile
from django.core.management import call_command
from django.test import TestCase
from django.utils.six import StringIO
from io import StringIO
import debug # pyflakes:ignore

View file

@ -32,32 +32,14 @@
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import re
import six
import string
from django.utils.html import escape
from ietf.utils import log
from ietf.utils.text import wordwrap
def markup_ascii(content, width=None):
log.unreachable('2017-12-08')
if six.PY2:
assert isinstance(content, str)
# at this point, "content" is normal string
# fix most common non-ASCII characters
t1 = string.maketrans("\x91\x92\x93\x94\x95\x96\x97\xc6\xe8\xe9", "\'\'\"\"o--\'ee")
# map everything except printable ASCII, TAB, LF, FF to "?"
t2 = string.maketrans('','')
t3 = "?"*9 + "\t\n?\f" + "?"*19 + t2[32:127] + "?"*129
t4 = t1.translate(t3)
content = content.translate(t4)
else:
log.assertion('six.PY2')
return markup(content.decode('ascii'), width)
def markup(content, width=None):
log.assertion('isinstance(content, six.text_type)')
log.assertion('isinstance(content, str)')
# normalize line endings to LF only
content = content.replace("\r\n", "\n")
content = content.replace("\r", "\n")

View file

@ -6,14 +6,13 @@ import textwrap
import unicodedata
from django.utils.functional import keep_lazy
from django.utils import six
from django.utils.safestring import mark_safe
import debug # pyflakes:ignore
from .texescape import init as texescape_init, tex_escape_map
@keep_lazy(six.text_type)
@keep_lazy(str)
def xslugify(value):
"""
Converts to ASCII. Converts spaces to hyphens. Removes characters that
@ -134,7 +133,7 @@ def maybe_split(text, split=True, pos=5000):
return text
def decode(raw):
assert isinstance(raw, six.binary_type)
assert isinstance(raw, bytes)
try:
text = raw.decode('utf-8')
except UnicodeDecodeError:
@ -146,7 +145,7 @@ def decode(raw):
def text_to_dict(t):
"Converts text with RFC2822-formatted header fields into a dictionary-like object."
# ensure we're handed a unicode parameter
assert isinstance(t, six.text_type)
assert isinstance(t, str)
d = {}
# Return {} for malformed input
if not len(t.lstrip()) == len(t):

View file

@ -1,6 +1,5 @@
# Copyright The IETF Trust 2016, All Rights Reserved
# Copyright The IETF Trust 2016-2019, All Rights Reserved
import six
import debug # pyflakes:ignore
from inspect import isclass
@ -17,7 +16,7 @@ def url(regex, view, kwargs=None, name=None):
branch = 'name'
elif isinstance(view, (list, tuple)):
branch = 'list'
elif isinstance(view, six.string_types):
elif isinstance(view, str):
branch = 'string'
name = view
elif callable(view) and hasattr(view, '__name__'):