summaryrefslogtreecommitdiff
path: root/django/utils
diff options
context:
space:
mode:
authorAymeric Augustin <aymeric.augustin@m4x.org>2012-07-20 16:16:57 +0200
committerAymeric Augustin <aymeric.augustin@m4x.org>2012-07-22 09:29:56 +0200
commitca07fda2efea24cb43423b884fa4648d44e52963 (patch)
tree5c172bf2155b58e380363d3e82ca2ef14afd163f /django/utils
parent0d914d08a0d7b5a1521f498a8047971fe6cd61e7 (diff)
[py3] Switched to Python 3-compatible imports.
xrange/range will be dealt with in a separate commit due to the huge number of changes.
Diffstat (limited to 'django/utils')
-rw-r--r--django/utils/autoreload.py2
-rw-r--r--django/utils/html_parser.py18
-rw-r--r--django/utils/itercompat.py6
-rw-r--r--django/utils/six.py5
-rw-r--r--django/utils/text.py4
-rw-r--r--django/utils/translation/trans_real.py2
6 files changed, 22 insertions, 15 deletions
diff --git a/django/utils/autoreload.py b/django/utils/autoreload.py
index 85d9907856..b6c055383c 100644
--- a/django/utils/autoreload.py
+++ b/django/utils/autoreload.py
@@ -33,7 +33,7 @@ import os, sys, time, signal
try:
import thread
except ImportError:
- import dummy_thread as thread
+ from django.utils.six.moves import _dummy_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 .
diff --git a/django/utils/html_parser.py b/django/utils/html_parser.py
index 98f6545c41..ee56c01aec 100644
--- a/django/utils/html_parser.py
+++ b/django/utils/html_parser.py
@@ -1,26 +1,28 @@
-import HTMLParser as _HTMLParser
+from django.utils.six.moves import html_parser as _html_parser
import re
tagfind = re.compile('([a-zA-Z][-.a-zA-Z0-9:_]*)(?:\s|/(?!>))*')
-class HTMLParser(_HTMLParser.HTMLParser):
+HTMLParseError = _html_parser.HTMLParseError
+
+class HTMLParser(_html_parser.HTMLParser):
"""
Patched version of stdlib's HTMLParser with patch from:
http://bugs.python.org/issue670664
"""
def __init__(self):
- _HTMLParser.HTMLParser.__init__(self)
+ _html_parser.HTMLParser.__init__(self)
self.cdata_tag = None
def set_cdata_mode(self, tag):
try:
- self.interesting = _HTMLParser.interesting_cdata
+ self.interesting = _html_parser.interesting_cdata
except AttributeError:
self.interesting = re.compile(r'</\s*%s\s*>' % tag.lower(), re.I)
self.cdata_tag = tag.lower()
def clear_cdata_mode(self):
- self.interesting = _HTMLParser.interesting_normal
+ self.interesting = _html_parser.interesting_normal
self.cdata_tag = None
# Internal -- handle starttag, return end or -1 if not terminated
@@ -40,7 +42,7 @@ class HTMLParser(_HTMLParser.HTMLParser):
self.lasttag = tag = match.group(1).lower()
while k < endpos:
- m = _HTMLParser.attrfind.match(rawdata, k)
+ m = _html_parser.attrfind.match(rawdata, k)
if not m:
break
attrname, rest, attrvalue = m.group(1, 2, 3)
@@ -78,11 +80,11 @@ class HTMLParser(_HTMLParser.HTMLParser):
def parse_endtag(self, i):
rawdata = self.rawdata
assert rawdata[i:i + 2] == "</", "unexpected call to parse_endtag"
- match = _HTMLParser.endendtag.search(rawdata, i + 1) # >
+ match = _html_parser.endendtag.search(rawdata, i + 1) # >
if not match:
return -1
j = match.end()
- match = _HTMLParser.endtagfind.match(rawdata, i) # </ + tag + >
+ match = _html_parser.endtagfind.match(rawdata, i) # </ + tag + >
if not match:
if self.cdata_tag is not None: # *** add ***
self.handle_data(rawdata[i:j]) # *** add ***
diff --git a/django/utils/itercompat.py b/django/utils/itercompat.py
index 2f016b1c3f..aa329c152e 100644
--- a/django/utils/itercompat.py
+++ b/django/utils/itercompat.py
@@ -4,7 +4,7 @@ Where possible, we try to use the system-native version and only fall back to
these implementations if necessary.
"""
-import __builtin__
+from django.utils.six.moves import builtins
import itertools
import warnings
@@ -25,9 +25,9 @@ def product(*args, **kwds):
def all(iterable):
warnings.warn("django.utils.itercompat.all is deprecated; use the native version instead",
DeprecationWarning)
- return __builtin__.all(iterable)
+ return builtins.all(iterable)
def any(iterable):
warnings.warn("django.utils.itercompat.any is deprecated; use the native version instead",
DeprecationWarning)
- return __builtin__.any(iterable)
+ return builtins.any(iterable)
diff --git a/django/utils/six.py b/django/utils/six.py
index b1d58e5668..c74f9fa7df 100644
--- a/django/utils/six.py
+++ b/django/utils/six.py
@@ -351,3 +351,8 @@ _add_doc(reraise, """Reraise an exception.""")
def with_metaclass(meta, base=object):
"""Create a base class with a metaclass."""
return meta("NewBase", (base,), {})
+
+
+### Additional customizations for Django ###
+
+add_move(MovedModule("_dummy_thread", "dummy_thread"))
diff --git a/django/utils/text.py b/django/utils/text.py
index 9f773ad41b..43056aa634 100644
--- a/django/utils/text.py
+++ b/django/utils/text.py
@@ -4,7 +4,7 @@ import re
import unicodedata
import warnings
from gzip import GzipFile
-from htmlentitydefs import name2codepoint
+from django.utils.six.moves import html_entities
from io import BytesIO
from django.utils.encoding import force_unicode
@@ -349,7 +349,7 @@ def _replace_entity(match):
return match.group(0)
else:
try:
- return unichr(name2codepoint[text])
+ return unichr(html_entities.name2codepoint[text])
except (ValueError, KeyError):
return match.group(0)
diff --git a/django/utils/translation/trans_real.py b/django/utils/translation/trans_real.py
index 0cd13fd6f5..9ebcbf5441 100644
--- a/django/utils/translation/trans_real.py
+++ b/django/utils/translation/trans_real.py
@@ -6,11 +6,11 @@ import os
import re
import sys
import gettext as gettext_module
-from io import StringIO
from threading import local
from django.utils.importlib import import_module
from django.utils.safestring import mark_safe, SafeData
+from django.utils.six import StringIO
# Translations are cached in a dictionary for every language+app tuple.