diff options
| author | Claude Paroz <claude@2xlibre.net> | 2016-12-29 16:27:49 +0100 |
|---|---|---|
| committer | Claude Paroz <claude@2xlibre.net> | 2017-01-18 20:18:46 +0100 |
| commit | 7b2f2e74adb36a4334e83130f6abc2f79d395235 (patch) | |
| tree | 313387ba6a6f1311b43cf5fb4f2576d2d6c4f805 /django/test | |
| parent | f6acd1d271122d66de8061e75ae26137ddf02658 (diff) | |
Refs #23919 -- Removed six.<various>_types usage
Thanks Tim Graham and Simon Charette for the reviews.
Diffstat (limited to 'django/test')
| -rw-r--r-- | django/test/client.py | 4 | ||||
| -rw-r--r-- | django/test/html.py | 27 | ||||
| -rw-r--r-- | django/test/testcases.py | 12 | ||||
| -rw-r--r-- | django/test/utils.py | 4 |
4 files changed, 20 insertions, 27 deletions
diff --git a/django/test/client.py b/django/test/client.py index 8134c17253..1c08ada1cf 100644 --- a/django/test/client.py +++ b/django/test/client.py @@ -197,7 +197,7 @@ def encode_multipart(boundary, data): for (key, value) in data.items(): if is_file(value): lines.extend(encode_file(boundary, key, value)) - elif not isinstance(value, six.string_types) and is_iterable(value): + elif not isinstance(value, str) and is_iterable(value): for item in value: if is_file(item): lines.extend(encode_file(boundary, key, item)) @@ -229,7 +229,7 @@ def encode_file(boundary, key, file): # file.name might not be a string. For example, it's an int for # tempfile.TemporaryFile(). - file_has_string_name = hasattr(file, 'name') and isinstance(file.name, six.string_types) + file_has_string_name = hasattr(file, 'name') and isinstance(file.name, str) filename = os.path.basename(file.name) if file_has_string_name else '' if hasattr(file, 'content_type'): diff --git a/django/test/html.py b/django/test/html.py index fd78e6b713..d84b9770e1 100644 --- a/django/test/html.py +++ b/django/test/html.py @@ -4,8 +4,6 @@ Comparing two html documents. import re -from django.utils import six -from django.utils.encoding import force_text from django.utils.html_parser import HTMLParseError, HTMLParser WHITESPACE = re.compile(r'\s+') @@ -22,11 +20,10 @@ class Element(object): self.children = [] def append(self, element): - if isinstance(element, six.string_types): - element = force_text(element) + if isinstance(element, str): element = normalize_whitespace(element) if self.children: - if isinstance(self.children[-1], six.string_types): + if isinstance(self.children[-1], str): self.children[-1] += element self.children[-1] = normalize_whitespace(self.children[-1]) return @@ -34,7 +31,7 @@ class Element(object): # removing last children if it is only whitespace # this can result in incorrect dom representations since # whitespace between inline tags like <span> is significant - if isinstance(self.children[-1], six.string_types): + if isinstance(self.children[-1], str): if self.children[-1].isspace(): self.children.pop() if element: @@ -43,7 +40,7 @@ class Element(object): def finalize(self): def rstrip_last_element(children): if children: - if isinstance(children[-1], six.string_types): + if isinstance(children[-1], str): children[-1] = children[-1].rstrip() if not children[-1]: children.pop() @@ -52,7 +49,7 @@ class Element(object): rstrip_last_element(self.children) for i, child in enumerate(self.children): - if isinstance(child, six.string_types): + if isinstance(child, str): self.children[i] = child.strip() elif hasattr(child, 'finalize'): child.finalize() @@ -88,7 +85,7 @@ class Element(object): return not self.__eq__(element) def _count(self, element, count=True): - if not isinstance(element, six.string_types): + if not isinstance(element, str): if self == element: return 1 if isinstance(element, RootElement): @@ -98,8 +95,8 @@ class Element(object): for child in self.children: # child is text content and element is also text content, then # make a simple "text" in "text" - if isinstance(child, six.string_types): - if isinstance(element, six.string_types): + if isinstance(child, str): + if isinstance(element, str): if count: i += child.count(element) elif element in child: @@ -128,14 +125,14 @@ class Element(object): output += ' %s' % key if self.children: output += '>\n' - output += ''.join(six.text_type(c) for c in self.children) + output += ''.join(str(c) for c in self.children) output += '\n</%s>' % self.name else: output += ' />' return output def __repr__(self): - return six.text_type(self) + return str(self) class RootElement(Element): @@ -143,7 +140,7 @@ class RootElement(Element): super(RootElement, self).__init__(None, ()) def __str__(self): - return ''.join(six.text_type(c) for c in self.children) + return ''.join(str(c) for c in self.children) class Parser(HTMLParser): @@ -232,6 +229,6 @@ def parse_html(html): document.finalize() # Removing ROOT element if it's not necessary if len(document.children) == 1: - if not isinstance(document.children[0], six.string_types): + if not isinstance(document.children[0], str): document = document.children[0] return document diff --git a/django/test/testcases.py b/django/test/testcases.py index 7e8cee5c0d..9d08940f5a 100644 --- a/django/test/testcases.py +++ b/django/test/testcases.py @@ -674,8 +674,7 @@ class SimpleTestCase(unittest.TestCase): standardMsg = '%s != %s' % ( safe_repr(dom1, True), safe_repr(dom2, True)) diff = ('\n' + '\n'.join(difflib.ndiff( - six.text_type(dom1).splitlines(), - six.text_type(dom2).splitlines(), + str(dom1).splitlines(), str(dom2).splitlines(), ))) standardMsg = self._truncateMessage(standardMsg, diff) self.fail(self._formatMessage(msg, standardMsg)) @@ -712,7 +711,7 @@ class SimpleTestCase(unittest.TestCase): data = json.loads(raw) except ValueError: self.fail("First argument is not valid JSON: %r" % raw) - if isinstance(expected_data, six.string_types): + if isinstance(expected_data, str): try: expected_data = json.loads(expected_data) except ValueError: @@ -729,7 +728,7 @@ class SimpleTestCase(unittest.TestCase): data = json.loads(raw) except ValueError: self.fail("First argument is not valid JSON: %r" % raw) - if isinstance(expected_data, six.string_types): + if isinstance(expected_data, str): try: expected_data = json.loads(expected_data) except ValueError: @@ -751,10 +750,7 @@ class SimpleTestCase(unittest.TestCase): if not result: standardMsg = '%s != %s' % (safe_repr(xml1, True), safe_repr(xml2, True)) diff = ('\n' + '\n'.join( - difflib.ndiff( - six.text_type(xml1).splitlines(), - six.text_type(xml2).splitlines(), - ) + difflib.ndiff(xml1.splitlines(), xml2.splitlines()) )) standardMsg = self._truncateMessage(standardMsg, diff) self.fail(self._formatMessage(msg, standardMsg)) diff --git a/django/test/utils.py b/django/test/utils.py index 5ed32dbab5..7395396fbb 100644 --- a/django/test/utils.py +++ b/django/test/utils.py @@ -61,7 +61,7 @@ class ContextList(list): in a list of context objects. """ def __getitem__(self, key): - if isinstance(key, six.string_types): + if isinstance(key, str): for subcontext in self: if key in subcontext: return subcontext[key] @@ -478,7 +478,7 @@ class modify_settings(override_settings): value = list(getattr(settings, name, [])) for action, items in operations.items(): # items my be a single value or an iterable. - if isinstance(items, six.string_types): + if isinstance(items, str): items = [items] if action == 'append': value = value + [item for item in items if item not in value] |
