diff options
| author | Aymeric Augustin <aymeric.augustin@m4x.org> | 2012-07-20 14:22:00 +0200 |
|---|---|---|
| committer | Aymeric Augustin <aymeric.augustin@m4x.org> | 2012-07-22 09:29:54 +0200 |
| commit | 3cb2457f46b3e40ff6b6acffcb3fd44cbea091e5 (patch) | |
| tree | 68e43a061f1a7a122c02d5c5b39586b32959a9dc /django/test/html.py | |
| parent | cacd845996d1245f6aed257bff5f748f46206d3f (diff) | |
[py3] Replaced basestring by six.string_types.
Diffstat (limited to 'django/test/html.py')
| -rw-r--r-- | django/test/html.py | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/django/test/html.py b/django/test/html.py index 79b198f1be..a44eb72322 100644 --- a/django/test/html.py +++ b/django/test/html.py @@ -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 |
