[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:
Aymeric Augustin 2012-07-20 15:36:52 +02:00
parent bdca5ea345
commit 0d914d08a0
32 changed files with 181 additions and 96 deletions

View file

@ -1,5 +1,9 @@
import urllib
from urlparse import urlparse
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.core.handlers.wsgi import WSGIHandler
@ -42,7 +46,7 @@ class StaticFilesHandler(WSGIHandler):
Returns the relative path to the media file on disk for the given URL.
"""
relative_url = url[len(self.base_url[2]):]
return urllib.url2pathname(relative_url)
return url2pathname(relative_url)
def serve(self, request):
"""

View file

@ -3,8 +3,11 @@ import hashlib
import os
import posixpath
import re
from urllib import unquote
from urlparse import urlsplit, urlunsplit, urldefrag
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.core.cache import (get_cache, InvalidCacheBackendError,

View file

@ -5,7 +5,10 @@ development, and SHOULD NOT be used in a production setting.
"""
import os
import posixpath
import urllib
try:
from urllib.parse import unquote
except ImportError: # Python 2
from urllib import unquote
from django.conf import settings
from django.core.exceptions import ImproperlyConfigured
@ -31,7 +34,7 @@ def serve(request, path, document_root=None, insecure=False, **kwargs):
raise ImproperlyConfigured("The staticfiles view can only be used in "
"debug mode or if the the --insecure "
"option of 'runserver' is used")
normalized_path = posixpath.normpath(urllib.unquote(path)).lstrip('/')
normalized_path = posixpath.normpath(unquote(path)).lstrip('/')
absolute_path = finders.find(normalized_path)
if not absolute_path:
if path.endswith('/') or path == '':