Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[py3] Switched to Python 3-compatible imports.

xrange/range will be dealt with in a separate commit due to the huge
number of changes.
  • Loading branch information...
commit ca07fda2efea24cb43423b884fa4648d44e52963 1 parent 0d914d0
@aaugustin aaugustin authored
View
6 django/contrib/auth/tests/basic.py
@@ -1,8 +1,8 @@
-from django.test import TestCase
-from django.utils.unittest import skipUnless
from django.contrib.auth.models import User, AnonymousUser
from django.core.management import call_command
-from StringIO import StringIO
+from django.test import TestCase
+from django.utils.six import StringIO
+from django.utils.unittest import skipUnless
try:
import crypt as crypt_module
View
3  django/contrib/auth/tests/management.py
@@ -1,11 +1,10 @@
from __future__ import unicode_literals
-from StringIO import StringIO
-
from django.contrib.auth import models, management
from django.contrib.auth.management.commands import changepassword
from django.core.management.base import CommandError
from django.test import TestCase
+from django.utils.six import StringIO
class GetDefaultUsernameTestCase(TestCase):
View
2  django/contrib/gis/db/models/sql/compiler.py
@@ -1,4 +1,4 @@
-from future_builtins import zip
+from django.utils.six.moves import zip
from django.db.backends.util import truncate_name, typecast_timestamp
from django.db.models.sql import compiler
View
2  django/contrib/gis/gdal/tests/test_geom.py
@@ -1,6 +1,6 @@
from binascii import b2a_hex
try:
- import cPickle as pickle
+ from django.utils.six.moves import cPickle as pickle
except ImportError:
import pickle
View
3  django/contrib/gis/geos/tests/test_geos.py
@@ -952,7 +952,8 @@ def test_extent(self):
def test_pickle(self):
"Testing pickling and unpickling support."
# Using both pickle and cPickle -- just 'cause.
- import pickle, cPickle
+ from django.utils.six.moves import cPickle
+ import pickle
# Creating a list of test geometries for pickling,
# and setting the SRID on some of them.
View
2  django/contrib/gis/utils/ogrinspect.py
@@ -5,7 +5,7 @@
Author: Travis Pinney, Dane Springmeyer, & Justin Bronn
"""
-from future_builtins import zip
+from django.utils.six.moves import zip
# Requires GDAL to use.
from django.contrib.gis.gdal import DataSource
from django.contrib.gis.gdal.field import OFTDate, OFTDateTime, OFTInteger, OFTReal, OFTString, OFTTime
View
2  django/contrib/sessions/backends/base.py
@@ -2,7 +2,7 @@
import time
from datetime import datetime, timedelta
try:
- import cPickle as pickle
+ from django.utils.six.moves import cPickle as pickle
except ImportError:
import pickle
View
2  django/contrib/sessions/backends/signed_cookies.py
@@ -1,5 +1,5 @@
try:
- import cPickle as pickle
+ from django.utils.six.moves import cPickle as pickle
except ImportError:
import pickle
View
2  django/core/cache/backends/db.py
@@ -4,7 +4,7 @@
from datetime import datetime
try:
- import cPickle as pickle
+ from django.utils.six.moves import cPickle as pickle
except ImportError:
import pickle
View
2  django/core/cache/backends/filebased.py
@@ -5,7 +5,7 @@
import shutil
import time
try:
- import cPickle as pickle
+ from django.utils.six.moves import cPickle as pickle
except ImportError:
import pickle
View
2  django/core/cache/backends/locmem.py
@@ -2,7 +2,7 @@
import time
try:
- import cPickle as pickle
+ from django.utils.six.moves import cPickle as pickle
except ImportError:
import pickle
View
4 django/core/servers/basehttp.py
@@ -16,7 +16,7 @@
except ImportError: # Python 2
from urllib import unquote
from urlparse import urljoin
-from SocketServer import ThreadingMixIn
+from django.utils.six.moves import socketserver
from wsgiref import simple_server
from wsgiref.util import FileWrapper # for backwards compatibility
@@ -200,7 +200,7 @@ def log_message(self, format, *args):
def run(addr, port, wsgi_handler, ipv6=False, threading=False):
server_address = (addr, port)
if threading:
- httpd_cls = type('WSGIServer', (ThreadingMixIn, WSGIServer), {})
+ httpd_cls = type('WSGIServer', (socketserver.ThreadingMixIn, WSGIServer), {})
else:
httpd_cls = WSGIServer
httpd = httpd_cls(server_address, WSGIRequestHandler, ipv6=ipv6)
View
2  django/db/backends/__init__.py
@@ -3,7 +3,7 @@
try:
import thread
except ImportError:
- import dummy_thread as thread
+ from django.utils.six.moves import _dummy_thread as thread
from contextlib import contextmanager
from django.conf import settings
View
2  django/db/models/base.py
@@ -3,7 +3,7 @@
import copy
import sys
from functools import update_wrapper
-from future_builtins import zip
+from django.utils.six.moves import zip
import django.db.models.manager # Imported to register signal handler.
from django.conf import settings
View
2  django/db/models/sql/compiler.py
@@ -1,4 +1,4 @@
-from future_builtins import zip
+from django.utils.six.moves import zip
from django.core.exceptions import FieldError
from django.db import transaction
View
22 django/http/__init__.py
@@ -16,23 +16,23 @@
from urllib import quote, urlencode
from urlparse import parse_qsl, urljoin
-import Cookie
+from django.utils.six.moves import http_cookies
# Some versions of Python 2.7 and later won't need this encoding bug fix:
-_cookie_encodes_correctly = Cookie.SimpleCookie().value_encode(';') == (';', '"\\073"')
+_cookie_encodes_correctly = http_cookies.SimpleCookie().value_encode(';') == (';', '"\\073"')
# See ticket #13007, http://bugs.python.org/issue2193 and http://trac.edgewall.org/ticket/2256
-_tc = Cookie.SimpleCookie()
+_tc = http_cookies.SimpleCookie()
try:
_tc.load(b'foo:bar=1')
_cookie_allows_colon_in_names = True
-except Cookie.CookieError:
+except http_cookies.CookieError:
_cookie_allows_colon_in_names = False
if _cookie_encodes_correctly and _cookie_allows_colon_in_names:
- SimpleCookie = Cookie.SimpleCookie
+ SimpleCookie = http_cookies.SimpleCookie
else:
- Morsel = Cookie.Morsel
+ Morsel = http_cookies.Morsel
- class SimpleCookie(Cookie.SimpleCookie):
+ class SimpleCookie(http_cookies.SimpleCookie):
if not _cookie_encodes_correctly:
def value_encode(self, val):
# Some browsers do not support quoted-string from RFC 2109,
@@ -73,9 +73,9 @@ def _BaseCookie__set(self, key, real_value, coded_value):
M = self.get(key, Morsel())
M.set(key, real_value, coded_value)
dict.__setitem__(self, key, M)
- except Cookie.CookieError:
+ except http_cookies.CookieError:
self.bad_cookies.add(key)
- dict.__setitem__(self, key, Cookie.Morsel())
+ dict.__setitem__(self, key, http_cookies.Morsel())
from django.conf import settings
@@ -495,11 +495,11 @@ def urlencode(self, safe=None):
def parse_cookie(cookie):
if cookie == '':
return {}
- if not isinstance(cookie, Cookie.BaseCookie):
+ if not isinstance(cookie, http_cookies.BaseCookie):
try:
c = SimpleCookie()
c.load(cookie)
- except Cookie.CookieError:
+ except http_cookies.CookieError:
# Invalid cookie
return {}
else:
View
2  django/test/_doctest.py
@@ -103,9 +103,9 @@ def _test():
import sys, traceback, inspect, linecache, os, re
import unittest, difflib, pdb, tempfile
import warnings
-from StringIO import StringIO
from django.utils import six
+from django.utils.six import StringIO
if sys.platform.startswith('java'):
# On Jython, isclass() reports some modules as classes. Patch it.
View
3  django/test/html.py
@@ -5,9 +5,8 @@
from __future__ import unicode_literals
import re
-from HTMLParser import HTMLParseError
from django.utils.encoding import force_unicode
-from django.utils.html_parser import HTMLParser
+from django.utils.html_parser import HTMLParser, HTMLParseError
from django.utils import six
View
2  django/utils/autoreload.py
@@ -33,7 +33,7 @@
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 .
View
18 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 @@ def parse_starttag(self, i):
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 @@ def parse_starttag(self, i):
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 ***
View
6 django/utils/itercompat.py
@@ -4,7 +4,7 @@
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)
View
5 django/utils/six.py
@@ -351,3 +351,8 @@ def write(data):
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"))
View
4 django/utils/text.py
@@ -4,7 +4,7 @@
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)
View
2  django/utils/translation/trans_real.py
@@ -6,11 +6,11 @@
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.
Please sign in to comment.
Something went wrong with that request. Please try again.