mirror of
https://github.com/django/django.git
synced 2025-10-24 06:06:09 +00:00
[py3] Replaced basestring by six.string_types.
This commit is contained in:
@@ -480,7 +480,7 @@ class DocTest:
|
||||
Create a new DocTest containing the given examples. The
|
||||
DocTest's globals are initialized with a copy of `globs`.
|
||||
"""
|
||||
assert not isinstance(examples, basestring), \
|
||||
assert not isinstance(examples, six.string_types), \
|
||||
"DocTest no longer accepts str; use DocTestParser instead"
|
||||
self.examples = examples
|
||||
self.docstring = docstring
|
||||
@@ -906,13 +906,13 @@ class DocTestFinder:
|
||||
# Look for tests in a module's __test__ dictionary.
|
||||
if inspect.ismodule(obj) and self._recurse:
|
||||
for valname, val in getattr(obj, '__test__', {}).items():
|
||||
if not isinstance(valname, basestring):
|
||||
if not isinstance(valname, six.string_types):
|
||||
raise ValueError("DocTestFinder.find: __test__ keys "
|
||||
"must be strings: %r" %
|
||||
(type(valname),))
|
||||
if not (inspect.isfunction(val) or inspect.isclass(val) or
|
||||
inspect.ismethod(val) or inspect.ismodule(val) or
|
||||
isinstance(val, basestring)):
|
||||
isinstance(val, six.string_types)):
|
||||
raise ValueError("DocTestFinder.find: __test__ values "
|
||||
"must be strings, functions, methods, "
|
||||
"classes, or modules: %r" %
|
||||
@@ -945,7 +945,7 @@ class DocTestFinder:
|
||||
"""
|
||||
# Extract the object's docstring. If it doesn't have one,
|
||||
# then return None (no test for this object).
|
||||
if isinstance(obj, basestring):
|
||||
if isinstance(obj, six.string_types):
|
||||
docstring = obj
|
||||
else:
|
||||
try:
|
||||
@@ -953,7 +953,7 @@ class DocTestFinder:
|
||||
docstring = ''
|
||||
else:
|
||||
docstring = obj.__doc__
|
||||
if not isinstance(docstring, basestring):
|
||||
if not isinstance(docstring, six.string_types):
|
||||
docstring = str(docstring)
|
||||
except (TypeError, AttributeError):
|
||||
docstring = ''
|
||||
|
||||
@@ -116,7 +116,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, basestring) and is_iterable(value):
|
||||
elif not isinstance(value, six.string_types) and is_iterable(value):
|
||||
for item in value:
|
||||
if is_file(item):
|
||||
lines.extend(encode_file(boundary, key, item))
|
||||
|
||||
@@ -8,6 +8,7 @@ import re
|
||||
from HTMLParser import HTMLParseError
|
||||
from django.utils.encoding import force_unicode
|
||||
from django.utils.html_parser import HTMLParser
|
||||
from django.utils import six
|
||||
|
||||
|
||||
WHITESPACE = re.compile('\s+')
|
||||
@@ -24,11 +25,11 @@ class Element(object):
|
||||
self.children = []
|
||||
|
||||
def append(self, element):
|
||||
if isinstance(element, basestring):
|
||||
if isinstance(element, six.string_types):
|
||||
element = force_unicode(element)
|
||||
element = normalize_whitespace(element)
|
||||
if self.children:
|
||||
if isinstance(self.children[-1], basestring):
|
||||
if isinstance(self.children[-1], six.string_types):
|
||||
self.children[-1] += element
|
||||
self.children[-1] = normalize_whitespace(self.children[-1])
|
||||
return
|
||||
@@ -36,7 +37,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], basestring):
|
||||
if isinstance(self.children[-1], six.string_types):
|
||||
if self.children[-1].isspace():
|
||||
self.children.pop()
|
||||
if element:
|
||||
@@ -45,7 +46,7 @@ class Element(object):
|
||||
def finalize(self):
|
||||
def rstrip_last_element(children):
|
||||
if children:
|
||||
if isinstance(children[-1], basestring):
|
||||
if isinstance(children[-1], six.string_types):
|
||||
children[-1] = children[-1].rstrip()
|
||||
if not children[-1]:
|
||||
children.pop()
|
||||
@@ -54,7 +55,7 @@ class Element(object):
|
||||
|
||||
rstrip_last_element(self.children)
|
||||
for i, child in enumerate(self.children):
|
||||
if isinstance(child, basestring):
|
||||
if isinstance(child, six.string_types):
|
||||
self.children[i] = child.strip()
|
||||
elif hasattr(child, 'finalize'):
|
||||
child.finalize()
|
||||
@@ -87,15 +88,15 @@ class Element(object):
|
||||
return not self.__eq__(element)
|
||||
|
||||
def _count(self, element, count=True):
|
||||
if not isinstance(element, basestring):
|
||||
if not isinstance(element, six.string_types):
|
||||
if self == element:
|
||||
return 1
|
||||
i = 0
|
||||
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, basestring):
|
||||
if isinstance(element, basestring):
|
||||
if isinstance(child, six.string_types):
|
||||
if isinstance(element, six.string_types):
|
||||
if count:
|
||||
i += child.count(element)
|
||||
elif element in child:
|
||||
@@ -219,6 +220,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], basestring):
|
||||
if not isinstance(document.children[0], six.string_types):
|
||||
document = document.children[0]
|
||||
return document
|
||||
|
||||
@@ -6,6 +6,7 @@ from django.template import Template, loader, TemplateDoesNotExist
|
||||
from django.template.loaders import cached
|
||||
from django.utils.translation import deactivate
|
||||
from django.utils.functional import wraps
|
||||
from django.utils import six
|
||||
|
||||
|
||||
__all__ = (
|
||||
@@ -35,7 +36,7 @@ class ContextList(list):
|
||||
in a list of context objects.
|
||||
"""
|
||||
def __getitem__(self, key):
|
||||
if isinstance(key, basestring):
|
||||
if isinstance(key, six.string_types):
|
||||
for subcontext in self:
|
||||
if key in subcontext:
|
||||
return subcontext[key]
|
||||
|
||||
Reference in New Issue
Block a user