mirror of
https://github.com/django/django.git
synced 2025-10-27 23:56:08 +00:00
Merged Unicode branch into trunk (r4952:5608). This should be fully
backwards compatible for all practical purposes. Fixed #2391, #2489, #2996, #3322, #3344, #3370, #3406, #3432, #3454, #3492, #3582, #3690, #3878, #3891, #3937, #4039, #4141, #4227, #4286, #4291, #4300, #4452, #4702 git-svn-id: http://code.djangoproject.com/svn/django/trunk@5609 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
@@ -9,6 +9,7 @@ a string) and returns a tuple in this format:
|
||||
|
||||
from django.http import Http404
|
||||
from django.core.exceptions import ImproperlyConfigured, ViewDoesNotExist
|
||||
from django.utils.encoding import iri_to_uri
|
||||
from django.utils.functional import memoize
|
||||
import re
|
||||
|
||||
@@ -37,14 +38,20 @@ def get_callable(lookup_view, can_fail=False):
|
||||
If can_fail is True, lookup_view might be a URL pattern label, so errors
|
||||
during the import fail and the string is returned.
|
||||
"""
|
||||
if not callable(lookup_view):
|
||||
mod_name, func_name = get_mod_func(lookup_view)
|
||||
try:
|
||||
if func_name != '':
|
||||
lookup_view = getattr(__import__(mod_name, {}, {}, ['']), func_name)
|
||||
except (ImportError, AttributeError):
|
||||
if not can_fail:
|
||||
raise
|
||||
try:
|
||||
# Bail out early if lookup_view is not ASCII. This can't be a function.
|
||||
lookup_view = lookup_view.encode('ascii')
|
||||
|
||||
if not callable(lookup_view):
|
||||
mod_name, func_name = get_mod_func(lookup_view)
|
||||
try:
|
||||
if func_name != '':
|
||||
lookup_view = getattr(__import__(mod_name, {}, {}, ['']), func_name)
|
||||
except (ImportError, AttributeError):
|
||||
if not can_fail:
|
||||
raise
|
||||
except UnicodeEncodeError:
|
||||
pass
|
||||
return lookup_view
|
||||
get_callable = memoize(get_callable, _callable_cache)
|
||||
|
||||
@@ -265,7 +272,7 @@ class RegexURLResolver(object):
|
||||
except (ImportError, AttributeError):
|
||||
raise NoReverseMatch
|
||||
if lookup_view in self.reverse_dict:
|
||||
return ''.join([reverse_helper(part.regex, *args, **kwargs) for part in self.reverse_dict[lookup_view]])
|
||||
return u''.join([reverse_helper(part.regex, *args, **kwargs) for part in self.reverse_dict[lookup_view]])
|
||||
raise NoReverseMatch
|
||||
|
||||
def reverse_helper(self, lookup_view, *args, **kwargs):
|
||||
@@ -279,5 +286,5 @@ def resolve(path, urlconf=None):
|
||||
def reverse(viewname, urlconf=None, args=None, kwargs=None):
|
||||
args = args or []
|
||||
kwargs = kwargs or {}
|
||||
return '/' + get_resolver(urlconf).reverse(viewname, *args, **kwargs)
|
||||
return iri_to_uri(u'/' + get_resolver(urlconf).reverse(viewname, *args, **kwargs))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user