Took advantage of django.utils.six.moves.urllib.*.

This commit is contained in:
Aymeric Augustin 2013-09-05 14:38:59 -05:00
parent ed9cd4fd8b
commit 6a6428a36f
31 changed files with 50 additions and 152 deletions

View File

@ -1,13 +1,10 @@
try:
from urllib.parse import urlparse
except ImportError: # Python 2
from urlparse import urlparse
from functools import wraps from functools import wraps
from django.conf import settings from django.conf import settings
from django.contrib.auth import REDIRECT_FIELD_NAME from django.contrib.auth import REDIRECT_FIELD_NAME
from django.core.exceptions import PermissionDenied from django.core.exceptions import PermissionDenied
from django.utils.decorators import available_attrs from django.utils.decorators import available_attrs
from django.utils.encoding import force_str from django.utils.encoding import force_str
from django.utils.six.moves.urllib.parse import urlparse
from django.shortcuts import resolve_url from django.shortcuts import resolve_url

View File

@ -1,10 +1,6 @@
import itertools import itertools
import os import os
import re import re
try:
from urllib.parse import urlparse, ParseResult
except ImportError: # Python 2
from urlparse import urlparse, ParseResult
from django.conf import global_settings, settings from django.conf import global_settings, settings
from django.contrib.sites.models import Site, RequestSite from django.contrib.sites.models import Site, RequestSite
@ -15,6 +11,7 @@ from django.core.urlresolvers import reverse, NoReverseMatch
from django.http import QueryDict, HttpRequest from django.http import QueryDict, HttpRequest
from django.utils.encoding import force_text from django.utils.encoding import force_text
from django.utils.http import urlquote from django.utils.http import urlquote
from django.utils.six.moves.urllib.parse import urlparse, ParseResult
from django.utils._os import upath from django.utils._os import upath
from django.test import TestCase from django.test import TestCase
from django.test.utils import override_settings, patch_logger from django.test.utils import override_settings, patch_logger

View File

@ -1,14 +1,10 @@
try:
from urllib.parse import urlparse, urlunparse
except ImportError: # Python 2
from urlparse import urlparse, urlunparse
from django.conf import settings from django.conf import settings
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
from django.http import HttpResponseRedirect, QueryDict from django.http import HttpResponseRedirect, QueryDict
from django.template.response import TemplateResponse from django.template.response import TemplateResponse
from django.utils.http import is_safe_url, urlsafe_base64_decode from django.utils.http import is_safe_url, urlsafe_base64_decode
from django.utils.translation import ugettext as _ from django.utils.translation import ugettext as _
from django.utils.six.moves.urllib.parse import urlparse, urlunparse
from django.shortcuts import resolve_url from django.shortcuts import resolve_url
from django.views.decorators.debug import sensitive_post_parameters from django.views.decorators.debug import sensitive_post_parameters
from django.views.decorators.cache import never_cache from django.views.decorators.cache import never_cache

View File

@ -3,10 +3,6 @@ A few bits of helper functions for comment views.
""" """
import textwrap import textwrap
try:
from urllib.parse import urlencode
except ImportError: # Python 2
from urllib import urlencode
from django.http import HttpResponseRedirect from django.http import HttpResponseRedirect
from django.shortcuts import render_to_response, resolve_url from django.shortcuts import render_to_response, resolve_url
@ -14,6 +10,7 @@ from django.template import RequestContext
from django.core.exceptions import ObjectDoesNotExist from django.core.exceptions import ObjectDoesNotExist
from django.contrib import comments from django.contrib import comments
from django.utils.http import is_safe_url from django.utils.http import is_safe_url
from django.utils.six.moves.urllib.parse import urlencode
def next_redirect(request, fallback, **get_kwargs): def next_redirect(request, fallback, **get_kwargs):
""" """

View File

@ -1,11 +1,8 @@
from django.contrib.sites.models import Site from django.contrib.sites.models import Site
from django.core import urlresolvers, paginator from django.core import urlresolvers, paginator
from django.core.exceptions import ImproperlyConfigured from django.core.exceptions import ImproperlyConfigured
try: from django.utils.six.moves.urllib.parse import urlencode
from urllib.parse import urlencode from django.utils.six.moves.urllib.request import urlopen
from urllib.request import urlopen
except ImportError: # Python 2
from urllib import urlencode, urlopen
PING_URL = "http://www.google.com/webmasters/tools/ping" PING_URL = "http://www.google.com/webmasters/tools/ping"

View File

@ -1,13 +1,8 @@
try:
from urllib.parse import urlparse
from urllib.request import url2pathname
except ImportError: # Python 2
from urllib import url2pathname
from urlparse import urlparse
from django.conf import settings from django.conf import settings
from django.core.handlers.base import get_path_info from django.core.handlers.base import get_path_info
from django.core.handlers.wsgi import WSGIHandler from django.core.handlers.wsgi import WSGIHandler
from django.utils.six.moves.urllib.parse import urlparse
from django.utils.six.moves.urllib.request import url2pathname
from django.contrib.staticfiles import utils from django.contrib.staticfiles import utils
from django.contrib.staticfiles.views import serve from django.contrib.staticfiles.views import serve

View File

@ -5,11 +5,6 @@ from importlib import import_module
import os import os
import posixpath import posixpath
import re import re
try:
from urllib.parse import unquote, urlsplit, urlunsplit, urldefrag
except ImportError: # Python 2
from urllib import unquote
from urlparse import urlsplit, urlunsplit, urldefrag
from django.conf import settings from django.conf import settings
from django.core.cache import (get_cache, InvalidCacheBackendError, from django.core.cache import (get_cache, InvalidCacheBackendError,
@ -19,6 +14,7 @@ from django.core.files.base import ContentFile
from django.core.files.storage import FileSystemStorage, get_storage_class from django.core.files.storage import FileSystemStorage, get_storage_class
from django.utils.encoding import force_bytes, force_text from django.utils.encoding import force_bytes, force_text
from django.utils.functional import LazyObject from django.utils.functional import LazyObject
from django.utils.six.moves.urllib.parse import unquote, urlsplit, urlunsplit, urldefrag
from django.utils._os import upath from django.utils._os import upath
from django.contrib.staticfiles.utils import check_settings, matches_patterns from django.contrib.staticfiles.utils import check_settings, matches_patterns

View File

@ -5,13 +5,10 @@ development, and SHOULD NOT be used in a production setting.
""" """
import os import os
import posixpath import posixpath
try:
from urllib.parse import unquote
except ImportError: # Python 2
from urllib import unquote
from django.conf import settings from django.conf import settings
from django.http import Http404 from django.http import Http404
from django.utils.six.moves.urllib.parse import unquote
from django.views import static from django.views import static
from django.contrib.staticfiles import finders from django.contrib.staticfiles import finders

View File

@ -15,10 +15,6 @@ cache class.
See docs/topics/cache.txt for information on the public API. See docs/topics/cache.txt for information on the public API.
""" """
import importlib import importlib
try:
from urllib.parse import parse_qsl
except ImportError: # Python 2
from urlparse import parse_qsl
from django.conf import settings from django.conf import settings
from django.core import signals from django.core import signals
@ -26,6 +22,7 @@ from django.core.cache.backends.base import (
InvalidCacheBackendError, CacheKeyWarning, BaseCache) InvalidCacheBackendError, CacheKeyWarning, BaseCache)
from django.core.exceptions import ImproperlyConfigured from django.core.exceptions import ImproperlyConfigured
from django.utils.module_loading import import_by_path from django.utils.module_loading import import_by_path
from django.utils.six.moves.urllib.parse import parse_qsl
__all__ = [ __all__ = [

View File

@ -1,9 +1,5 @@
import os import os
import errno import errno
try:
from urllib.parse import urljoin
except ImportError: # Python 2
from urlparse import urljoin
import itertools import itertools
from datetime import datetime from datetime import datetime
@ -14,6 +10,7 @@ from django.core.files.move import file_move_safe
from django.utils.encoding import force_text, filepath_to_uri from django.utils.encoding import force_text, filepath_to_uri
from django.utils.functional import LazyObject from django.utils.functional import LazyObject
from django.utils.module_loading import import_by_path from django.utils.module_loading import import_by_path
from django.utils.six.moves.urllib.parse import urljoin
from django.utils.text import get_valid_filename from django.utils.text import get_valid_filename
from django.utils._os import safe_join, abspathu from django.utils._os import safe_join, abspathu

View File

@ -8,10 +8,6 @@ import shutil
import stat import stat
import sys import sys
import tempfile import tempfile
try:
from urllib.request import urlretrieve
except ImportError: # Python 2
from urllib import urlretrieve
from optparse import make_option from optparse import make_option
from os import path from os import path
@ -19,6 +15,7 @@ from os import path
import django import django
from django.template import Template, Context from django.template import Template, Context
from django.utils import archive from django.utils import archive
from django.utils.six.moves.urllib.request import urlretrieve
from django.utils._os import rmtree_errorhandler from django.utils._os import rmtree_errorhandler
from django.core.management.base import BaseCommand, CommandError from django.core.management.base import BaseCommand, CommandError
from django.core.management.utils import handle_extensions from django.core.management.utils import handle_extensions

View File

@ -13,11 +13,6 @@ from io import BytesIO
import socket import socket
import sys import sys
import traceback import traceback
try:
from urllib.parse import urljoin
except ImportError: # Python 2
from urlparse import urljoin
from django.utils.six.moves import socketserver
from wsgiref import simple_server from wsgiref import simple_server
from wsgiref.util import FileWrapper # for backwards compatibility from wsgiref.util import FileWrapper # for backwards compatibility
@ -25,6 +20,8 @@ from django.core.management.color import color_style
from django.core.wsgi import get_wsgi_application from django.core.wsgi import get_wsgi_application
from django.utils.module_loading import import_by_path from django.utils.module_loading import import_by_path
from django.utils import six from django.utils import six
from django.utils.six.moves.urllib.parse import urljoin
from django.utils.six.moves import socketserver
__all__ = ('WSGIServer', 'WSGIRequestHandler', 'MAX_SOCKET_CHUNK_SIZE') __all__ = ('WSGIServer', 'WSGIRequestHandler', 'MAX_SOCKET_CHUNK_SIZE')

View File

@ -1,16 +1,14 @@
from __future__ import unicode_literals from __future__ import unicode_literals
import re import re
try:
from urllib.parse import urlsplit, urlunsplit
except ImportError: # Python 2
from urlparse import urlsplit, urlunsplit
from django.core.exceptions import ValidationError from django.core.exceptions import ValidationError
from django.utils.translation import ugettext_lazy as _, ungettext_lazy from django.utils.translation import ugettext_lazy as _, ungettext_lazy
from django.utils.encoding import force_text from django.utils.encoding import force_text
from django.utils.ipv6 import is_valid_ipv6_address from django.utils.ipv6 import is_valid_ipv6_address
from django.utils import six from django.utils import six
from django.utils.six.moves.urllib.parse import urlsplit, urlunsplit
# These values, if given to validate(), will trigger the self.required check. # These values, if given to validate(), will trigger the self.required check.
EMPTY_VALUES = (None, '', [], (), {}) EMPTY_VALUES = (None, '', [], (), {})

View File

@ -9,10 +9,6 @@ import datetime
import os import os
import re import re
import sys import sys
try:
from urllib.parse import urlsplit, urlunsplit
except ImportError: # Python 2
from urlparse import urlsplit, urlunsplit
from decimal import Decimal, DecimalException from decimal import Decimal, DecimalException
from io import BytesIO from io import BytesIO
@ -29,6 +25,7 @@ from django.utils import formats
from django.utils.encoding import smart_text, force_str, force_text from django.utils.encoding import smart_text, force_str, force_text
from django.utils.ipv6 import clean_ipv6_address from django.utils.ipv6 import clean_ipv6_address
from django.utils import six from django.utils import six
from django.utils.six.moves.urllib.parse import urlsplit, urlunsplit
from django.utils.translation import ugettext_lazy as _, ungettext_lazy from django.utils.translation import ugettext_lazy as _, ungettext_lazy
# Provide this import for backwards compatibility. # Provide this import for backwards compatibility.

View File

@ -6,10 +6,6 @@ from __future__ import unicode_literals
import copy import copy
from itertools import chain from itertools import chain
try:
from urllib.parse import urljoin
except ImportError: # Python 2
from urlparse import urljoin
import warnings import warnings
from django.conf import settings from django.conf import settings
@ -20,6 +16,7 @@ from django.utils.translation import ugettext_lazy
from django.utils.encoding import force_text, python_2_unicode_compatible from django.utils.encoding import force_text, python_2_unicode_compatible
from django.utils.safestring import mark_safe from django.utils.safestring import mark_safe
from django.utils import datetime_safe, formats, six from django.utils import datetime_safe, formats, six
from django.utils.six.moves.urllib.parse import urljoin
__all__ = ( __all__ = (
'Media', 'MediaDefiningClass', 'Widget', 'TextInput', 'Media', 'MediaDefiningClass', 'Widget', 'TextInput',

View File

@ -1,11 +1,7 @@
try:
from urllib.parse import urljoin
except ImportError: # Python 2
from urlparse import urljoin
from django import template from django import template
from django.template.base import Node from django.template.base import Node
from django.utils.encoding import iri_to_uri from django.utils.encoding import iri_to_uri
from django.utils.six.moves.urllib.parse import urljoin
register = template.Library() register = template.Library()

View File

@ -7,11 +7,6 @@ import mimetypes
from copy import copy from copy import copy
from importlib import import_module from importlib import import_module
from io import BytesIO from io import BytesIO
try:
from urllib.parse import unquote, urlparse, urlsplit
except ImportError: # Python 2
from urllib import unquote
from urlparse import urlparse, urlsplit
from django.conf import settings from django.conf import settings
from django.contrib.auth import authenticate, login, logout, get_user_model from django.contrib.auth import authenticate, login, logout, get_user_model
@ -28,6 +23,7 @@ from django.utils.encoding import force_bytes, force_str
from django.utils.http import urlencode from django.utils.http import urlencode
from django.utils.itercompat import is_iterable from django.utils.itercompat import is_iterable
from django.utils import six from django.utils import six
from django.utils.six.moves.urllib.parse import unquote, urlparse, urlsplit
from django.test.utils import ContextList from django.test.utils import ContextList
__all__ = ('Client', 'RequestFactory', 'encode_file', 'encode_multipart') __all__ = ('Client', 'RequestFactory', 'encode_file', 'encode_multipart')

View File

@ -13,12 +13,6 @@ import threading
import unittest import unittest
from unittest import skipIf # Imported here for backward compatibility from unittest import skipIf # Imported here for backward compatibility
from unittest.util import safe_repr from unittest.util import safe_repr
try:
from urllib.parse import urlsplit, urlunsplit, urlparse, unquote
from urllib.request import url2pathname
except ImportError: # Python 2
from urlparse import urlsplit, urlunsplit, urlparse
from urllib import url2pathname, unquote
from django.conf import settings from django.conf import settings
from django.core import mail from django.core import mail
@ -40,8 +34,10 @@ from django.test.html import HTMLParseError, parse_html
from django.test.signals import template_rendered from django.test.signals import template_rendered
from django.test.utils import (CaptureQueriesContext, ContextList, from django.test.utils import (CaptureQueriesContext, ContextList,
override_settings, compare_xml) override_settings, compare_xml)
from django.utils import six
from django.utils.encoding import force_text from django.utils.encoding import force_text
from django.utils import six
from django.utils.six.moves.urllib.parse import urlsplit, urlunsplit, urlparse, unquote
from django.utils.six.moves.urllib.request import url2pathname
from django.views.static import serve from django.views.static import serve

View File

@ -4,13 +4,10 @@ import codecs
import datetime import datetime
from decimal import Decimal from decimal import Decimal
import locale import locale
try:
from urllib.parse import quote
except ImportError: # Python 2
from urllib import quote
from django.utils.functional import Promise from django.utils.functional import Promise
from django.utils import six from django.utils import six
from django.utils.six.moves.urllib.parse import quote
class DjangoUnicodeDecodeError(UnicodeDecodeError): class DjangoUnicodeDecodeError(UnicodeDecodeError):
def __init__(self, obj, *args): def __init__(self, obj, *args):

View File

@ -24,15 +24,12 @@ http://web.archive.org/web/20110718035220/http://diveintomark.org/archives/2004/
from __future__ import unicode_literals from __future__ import unicode_literals
import datetime import datetime
try:
from urllib.parse import urlparse
except ImportError: # Python 2
from urlparse import urlparse
from django.utils.xmlutils import SimplerXMLGenerator from django.utils.xmlutils import SimplerXMLGenerator
from django.utils.encoding import force_text, iri_to_uri from django.utils.encoding import force_text, iri_to_uri
from django.utils import datetime_safe from django.utils import datetime_safe
from django.utils import six from django.utils import six
from django.utils.six import StringIO from django.utils.six import StringIO
from django.utils.six.moves.urllib.parse import urlparse
from django.utils.timezone import is_aware from django.utils.timezone import is_aware
def rfc2822_date(date): def rfc2822_date(date):

View File

@ -3,16 +3,12 @@
from __future__ import unicode_literals from __future__ import unicode_literals
import re import re
try:
from urllib.parse import quote, unquote, urlsplit, urlunsplit
except ImportError: # Python 2
from urllib import quote, unquote
from urlparse import urlsplit, urlunsplit
from django.utils.safestring import SafeData, mark_safe from django.utils.safestring import SafeData, mark_safe
from django.utils.encoding import force_text, force_str from django.utils.encoding import force_text, force_str
from django.utils.functional import allow_lazy from django.utils.functional import allow_lazy
from django.utils import six from django.utils import six
from django.utils.six.moves.urllib.parse import quote, unquote, urlsplit, urlunsplit
from django.utils.text import normalize_newlines from django.utils.text import normalize_newlines
from .html_parser import HTMLParser, HTMLParseError from .html_parser import HTMLParser, HTMLParseError

View File

@ -5,12 +5,6 @@ import calendar
import datetime import datetime
import re import re
import sys import sys
try:
from urllib import parse as urllib_parse
except ImportError: # Python 2
import urllib as urllib_parse
import urlparse
urllib_parse.urlparse = urlparse.urlparse
from binascii import Error as BinasciiError from binascii import Error as BinasciiError
from email.utils import formatdate from email.utils import formatdate
@ -19,6 +13,9 @@ from django.utils.datastructures import MultiValueDict
from django.utils.encoding import force_str, force_text from django.utils.encoding import force_str, force_text
from django.utils.functional import allow_lazy from django.utils.functional import allow_lazy
from django.utils import six from django.utils import six
from django.utils.six.moves.urllib.parse import (
quote, quote_plus, unquote, unquote_plus, urlparse,
urlencode as original_urlencode)
ETAG_MATCH = re.compile(r'(?:W/)?"((?:\\.|[^"])*)"') ETAG_MATCH = re.compile(r'(?:W/)?"((?:\\.|[^"])*)"')
@ -40,7 +37,7 @@ def urlquote(url, safe='/'):
can safely be used as part of an argument to a subsequent iri_to_uri() call can safely be used as part of an argument to a subsequent iri_to_uri() call
without double-quoting occurring. without double-quoting occurring.
""" """
return force_text(urllib_parse.quote(force_str(url), force_str(safe))) return force_text(quote(force_str(url), force_str(safe)))
urlquote = allow_lazy(urlquote, six.text_type) urlquote = allow_lazy(urlquote, six.text_type)
def urlquote_plus(url, safe=''): def urlquote_plus(url, safe=''):
@ -50,7 +47,7 @@ def urlquote_plus(url, safe=''):
returned string can safely be used as part of an argument to a subsequent returned string can safely be used as part of an argument to a subsequent
iri_to_uri() call without double-quoting occurring. iri_to_uri() call without double-quoting occurring.
""" """
return force_text(urllib_parse.quote_plus(force_str(url), force_str(safe))) return force_text(quote_plus(force_str(url), force_str(safe)))
urlquote_plus = allow_lazy(urlquote_plus, six.text_type) urlquote_plus = allow_lazy(urlquote_plus, six.text_type)
def urlunquote(quoted_url): def urlunquote(quoted_url):
@ -58,7 +55,7 @@ def urlunquote(quoted_url):
A wrapper for Python's urllib.unquote() function that can operate on A wrapper for Python's urllib.unquote() function that can operate on
the result of django.utils.http.urlquote(). the result of django.utils.http.urlquote().
""" """
return force_text(urllib_parse.unquote(force_str(quoted_url))) return force_text(unquote(force_str(quoted_url)))
urlunquote = allow_lazy(urlunquote, six.text_type) urlunquote = allow_lazy(urlunquote, six.text_type)
def urlunquote_plus(quoted_url): def urlunquote_plus(quoted_url):
@ -66,7 +63,7 @@ def urlunquote_plus(quoted_url):
A wrapper for Python's urllib.unquote_plus() function that can operate on A wrapper for Python's urllib.unquote_plus() function that can operate on
the result of django.utils.http.urlquote_plus(). the result of django.utils.http.urlquote_plus().
""" """
return force_text(urllib_parse.unquote_plus(force_str(quoted_url))) return force_text(unquote_plus(force_str(quoted_url)))
urlunquote_plus = allow_lazy(urlunquote_plus, six.text_type) urlunquote_plus = allow_lazy(urlunquote_plus, six.text_type)
def urlencode(query, doseq=0): def urlencode(query, doseq=0):
@ -79,7 +76,7 @@ def urlencode(query, doseq=0):
query = query.lists() query = query.lists()
elif hasattr(query, 'items'): elif hasattr(query, 'items'):
query = query.items() query = query.items()
return urllib_parse.urlencode( return original_urlencode(
[(force_str(k), [(force_str(k),
[force_str(i) for i in v] if isinstance(v, (list,tuple)) else force_str(v)) [force_str(i) for i in v] if isinstance(v, (list,tuple)) else force_str(v))
for k, v in query], for k, v in query],
@ -243,7 +240,7 @@ def same_origin(url1, url2):
""" """
Checks if two URLs are 'same-origin' Checks if two URLs are 'same-origin'
""" """
p1, p2 = urllib_parse.urlparse(url1), urllib_parse.urlparse(url2) p1, p2 = urlparse(url1), urlparse(url2)
try: try:
return (p1.scheme, p1.hostname, p1.port) == (p2.scheme, p2.hostname, p2.port) return (p1.scheme, p1.hostname, p1.port) == (p2.scheme, p2.hostname, p2.port)
except ValueError: except ValueError:
@ -258,6 +255,6 @@ def is_safe_url(url, host=None):
""" """
if not url: if not url:
return False return False
url_info = urllib_parse.urlparse(url) url_info = urlparse(url)
return (not url_info.netloc or url_info.netloc == host) and \ return (not url_info.netloc or url_info.netloc == host) and \
(not url_info.scheme or url_info.scheme in ['http', 'https']) (not url_info.scheme or url_info.scheme in ['http', 'https'])

View File

@ -9,15 +9,12 @@ import os
import stat import stat
import posixpath import posixpath
import re import re
try:
from urllib.parse import unquote
except ImportError: # Python 2
from urllib import unquote
from django.http import (Http404, HttpResponse, HttpResponseRedirect, from django.http import (Http404, HttpResponse, HttpResponseRedirect,
HttpResponseNotModified, StreamingHttpResponse) HttpResponseNotModified, StreamingHttpResponse)
from django.template import loader, Template, Context, TemplateDoesNotExist from django.template import loader, Template, Context, TemplateDoesNotExist
from django.utils.http import http_date, parse_http_date from django.utils.http import http_date, parse_http_date
from django.utils.six.moves.urllib.parse import unquote
from django.utils.translation import ugettext as _, ugettext_noop from django.utils.translation import ugettext as _, ugettext_noop
def serve(request, path, document_root=None, show_indexes=False): def serve(request, path, document_root=None, show_indexes=False):

View File

@ -367,15 +367,6 @@ Moved modules
Some modules were renamed in Python 3. The :mod:`django.utils.six.moves Some modules were renamed in Python 3. The :mod:`django.utils.six.moves
<six.moves>` module provides a compatible location to import them. <six.moves>` module provides a compatible location to import them.
The ``urllib``, ``urllib2`` and ``urlparse`` modules were reworked in depth
and :mod:`django.utils.six.moves <six.moves>` doesn't handle them. Django
explicitly tries both locations, as follows::
try:
from urllib.parse import urlparse, urlunparse
except ImportError: # Python 2
from urlparse import urlparse, urlunparse
PY2 PY2
~~~ ~~~

View File

@ -5,10 +5,6 @@ import os
import re import re
import datetime import datetime
import unittest import unittest
try:
from urllib.parse import urljoin
except ImportError: # Python 2
from urlparse import urljoin
from django.conf import settings, global_settings from django.conf import settings, global_settings
from django.core import mail from django.core import mail
@ -30,15 +26,16 @@ from django.forms.util import ErrorList
from django.template.response import TemplateResponse from django.template.response import TemplateResponse
from django.test import TestCase from django.test import TestCase
from django.test.utils import patch_logger from django.test.utils import patch_logger
from django.test.utils import override_settings
from django.utils import formats from django.utils import formats
from django.utils import translation from django.utils import translation
from django.utils.cache import get_max_age from django.utils.cache import get_max_age
from django.utils.encoding import iri_to_uri, force_bytes from django.utils.encoding import iri_to_uri, force_bytes
from django.utils.html import escape from django.utils.html import escape
from django.utils.http import urlencode, urlquote from django.utils.http import urlencode, urlquote
from django.utils.six.moves.urllib.parse import urljoin
from django.utils._os import upath from django.utils._os import upath
from django.utils import six from django.utils import six
from django.test.utils import override_settings
# local test models # local test models
from .models import (Article, BarAccount, CustomArticle, EmptyModel, FooAccount, from .models import (Article, BarAccount, CustomArticle, EmptyModel, FooAccount,

View File

@ -8,10 +8,6 @@ import sys
import tempfile import tempfile
import time import time
import unittest import unittest
try:
from urllib.request import urlopen
except ImportError: # Python 2
from urllib2 import urlopen
import zlib import zlib
from datetime import datetime, timedelta from datetime import datetime, timedelta
from io import BytesIO from io import BytesIO
@ -28,9 +24,10 @@ from django.core.files.images import get_image_dimensions
from django.core.files.storage import FileSystemStorage, get_storage_class from django.core.files.storage import FileSystemStorage, get_storage_class
from django.core.files.uploadedfile import UploadedFile from django.core.files.uploadedfile import UploadedFile
from django.test import LiveServerTestCase, SimpleTestCase from django.test import LiveServerTestCase, SimpleTestCase
from django.utils import six
from django.utils._os import upath
from django.test.utils import override_settings from django.test.utils import override_settings
from django.utils import six
from django.utils.six.moves.urllib.request import urlopen
from django.utils._os import upath
try: try:
from django.utils.image import Image from django.utils.image import Image

View File

@ -18,6 +18,7 @@ from django.test.client import FakePayload
from django.test.utils import override_settings, str_prefix from django.test.utils import override_settings, str_prefix
from django.utils import six from django.utils import six
from django.utils.http import cookie_date, urlencode from django.utils.http import cookie_date, urlencode
from django.utils.six.moves.urllib.parse import urlencode as original_urlencode
from django.utils.timezone import utc from django.utils.timezone import utc
@ -279,8 +280,7 @@ class RequestsTests(SimpleTestCase):
""" """
Test a POST with non-utf-8 payload encoding. Test a POST with non-utf-8 payload encoding.
""" """
from django.utils.http import urllib_parse payload = FakePayload(original_urlencode({'key': 'España'.encode('latin-1')}))
payload = FakePayload(urllib_parse.urlencode({'key': 'España'.encode('latin-1')}))
request = WSGIRequest({ request = WSGIRequest({
'REQUEST_METHOD': 'POST', 'REQUEST_METHOD': 'POST',
'CONTENT_LENGTH': len(payload), 'CONTENT_LENGTH': len(payload),

View File

@ -5,16 +5,14 @@ Tests for django.core.servers.
from __future__ import unicode_literals from __future__ import unicode_literals
import os import os
try:
from urllib.request import urlopen, HTTPError
except ImportError: # Python 2
from urllib2 import urlopen, HTTPError
from django.core.exceptions import ImproperlyConfigured from django.core.exceptions import ImproperlyConfigured
from django.test import LiveServerTestCase from django.test import LiveServerTestCase
from django.core.servers.basehttp import WSGIServerException from django.core.servers.basehttp import WSGIServerException
from django.test.utils import override_settings from django.test.utils import override_settings
from django.utils.http import urlencode from django.utils.http import urlencode
from django.utils.six.moves.urllib.error import HTTPError
from django.utils.six.moves.urllib.request import urlopen
from django.utils._os import upath from django.utils._os import upath
from .models import Person from .models import Person

View File

@ -5,13 +5,10 @@ django.test.LiveServerTestCase.
""" """
import os import os
try:
from urllib.request import urlopen
except ImportError: # Python 2
from urllib2 import urlopen
from django.core.exceptions import ImproperlyConfigured from django.core.exceptions import ImproperlyConfigured
from django.test.utils import override_settings from django.test.utils import override_settings
from django.utils.six.moves.urllib.request import urlopen
from django.utils._os import upath from django.utils._os import upath
from django.contrib.staticfiles.testing import StaticLiveServerCase from django.contrib.staticfiles.testing import StaticLiveServerCase

View File

@ -13,10 +13,6 @@ import os
import sys import sys
import traceback import traceback
import unittest import unittest
try:
from urllib.parse import urljoin
except ImportError: # Python 2
from urlparse import urljoin
import warnings import warnings
from django import template from django import template
@ -33,6 +29,7 @@ from django.utils._os import upath
from django.utils.translation import activate, deactivate from django.utils.translation import activate, deactivate
from django.utils.safestring import mark_safe from django.utils.safestring import mark_safe
from django.utils import six from django.utils import six
from django.utils.six.moves.urllib.parse import urljoin
from i18n import TransRealMixin from i18n import TransRealMixin

View File

@ -1,7 +1,3 @@
try:
from urllib.parse import urlencode
except ImportError: # Python 2
from urllib import urlencode
from xml.dom.minidom import parseString from xml.dom.minidom import parseString
from django.contrib.auth.decorators import login_required, permission_required from django.contrib.auth.decorators import login_required, permission_required
@ -13,6 +9,7 @@ from django.http import HttpResponse, HttpResponseRedirect, HttpResponseNotFound
from django.shortcuts import render_to_response from django.shortcuts import render_to_response
from django.template import Context, Template from django.template import Context, Template
from django.utils.decorators import method_decorator from django.utils.decorators import method_decorator
from django.utils.six.moves.urllib.parse import urlencode
def get_view(request): def get_view(request):
"A simple view that expects a GET request, and returns a rendered template" "A simple view that expects a GET request, and returns a rendered template"