mirror of
https://github.com/django/django.git
synced 2025-11-07 07:15:35 +00:00
[py3] Updated urllib/urllib2/urlparse imports.
Lots of functions were moved. Use explicit imports in all cases to keey it easy to identify where the functions come from.
This commit is contained in:
5
django/core/cache/__init__.py
vendored
5
django/core/cache/__init__.py
vendored
@@ -14,7 +14,10 @@ cache class.
|
||||
|
||||
See docs/topics/cache.txt for information on the public API.
|
||||
"""
|
||||
from urlparse import parse_qsl
|
||||
try:
|
||||
from urllib.parse import parse_qsl
|
||||
except ImportError: # Python 2
|
||||
from urlparse import parse_qsl
|
||||
|
||||
from django.conf import settings
|
||||
from django.core import signals
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
import os
|
||||
import errno
|
||||
import urlparse
|
||||
try:
|
||||
from urllib.parse import urljoin
|
||||
except ImportError: # Python 2
|
||||
from urlparse import urljoin
|
||||
import itertools
|
||||
from datetime import datetime
|
||||
|
||||
@@ -252,7 +255,7 @@ class FileSystemStorage(Storage):
|
||||
def url(self, name):
|
||||
if self.base_url is None:
|
||||
raise ValueError("This file is not accessible via a URL.")
|
||||
return urlparse.urljoin(self.base_url, filepath_to_uri(name))
|
||||
return urljoin(self.base_url, filepath_to_uri(name))
|
||||
|
||||
def accessed_time(self, name):
|
||||
return datetime.fromtimestamp(os.path.getatime(self.path(name)))
|
||||
|
||||
@@ -8,7 +8,10 @@ import shutil
|
||||
import stat
|
||||
import sys
|
||||
import tempfile
|
||||
import urllib
|
||||
try:
|
||||
from urllib.request import urlretrieve
|
||||
except ImportError: # Python 2
|
||||
from urllib import urlretrieve
|
||||
|
||||
from optparse import make_option
|
||||
from os import path
|
||||
@@ -227,8 +230,7 @@ class TemplateCommand(BaseCommand):
|
||||
if self.verbosity >= 2:
|
||||
self.stdout.write("Downloading %s\n" % display_url)
|
||||
try:
|
||||
the_path, info = urllib.urlretrieve(url,
|
||||
path.join(tempdir, filename))
|
||||
the_path, info = urlretrieve(url, path.join(tempdir, filename))
|
||||
except IOError as e:
|
||||
raise CommandError("couldn't download URL %s to %s: %s" %
|
||||
(url, filename, e))
|
||||
|
||||
@@ -11,8 +11,11 @@ import os
|
||||
import socket
|
||||
import sys
|
||||
import traceback
|
||||
import urllib
|
||||
import urlparse
|
||||
try:
|
||||
from urllib.parse import unquote, urljoin
|
||||
except ImportError: # Python 2
|
||||
from urllib import unquote
|
||||
from urlparse import urljoin
|
||||
from SocketServer import ThreadingMixIn
|
||||
from wsgiref import simple_server
|
||||
from wsgiref.util import FileWrapper # for backwards compatibility
|
||||
@@ -127,7 +130,7 @@ class WSGIRequestHandler(simple_server.WSGIRequestHandler, object):
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
from django.conf import settings
|
||||
self.admin_static_prefix = urlparse.urljoin(settings.STATIC_URL, 'admin/')
|
||||
self.admin_static_prefix = urljoin(settings.STATIC_URL, 'admin/')
|
||||
# We set self.path to avoid crashes in log_message() on unsupported
|
||||
# requests (like "OPTIONS").
|
||||
self.path = ''
|
||||
@@ -143,7 +146,7 @@ class WSGIRequestHandler(simple_server.WSGIRequestHandler, object):
|
||||
else:
|
||||
path,query = self.path,''
|
||||
|
||||
env['PATH_INFO'] = urllib.unquote(path)
|
||||
env['PATH_INFO'] = unquote(path)
|
||||
env['QUERY_STRING'] = query
|
||||
env['REMOTE_ADDR'] = self.client_address[0]
|
||||
env['CONTENT_TYPE'] = self.headers.get('content-type', 'text/plain')
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import re
|
||||
import urlparse
|
||||
try:
|
||||
from urllib.parse import urlsplit, urlunsplit
|
||||
except ImportError: # Python 2
|
||||
from urlparse import urlsplit, urlunsplit
|
||||
|
||||
from django.core.exceptions import ValidationError
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
@@ -52,12 +55,12 @@ class URLValidator(RegexValidator):
|
||||
# Trivial case failed. Try for possible IDN domain
|
||||
if value:
|
||||
value = smart_unicode(value)
|
||||
scheme, netloc, path, query, fragment = urlparse.urlsplit(value)
|
||||
scheme, netloc, path, query, fragment = urlsplit(value)
|
||||
try:
|
||||
netloc = netloc.encode('idna') # IDN -> ACE
|
||||
except UnicodeError: # invalid domain part
|
||||
raise e
|
||||
url = urlparse.urlunsplit((scheme, netloc, path, query, fragment))
|
||||
url = urlunsplit((scheme, netloc, path, query, fragment))
|
||||
super(URLValidator, self).__call__(url)
|
||||
else:
|
||||
raise
|
||||
|
||||
Reference in New Issue
Block a user