summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorMalcolm Tredinnick <malcolm.tredinnick@gmail.com>2007-07-02 12:24:58 +0000
committerMalcolm Tredinnick <malcolm.tredinnick@gmail.com>2007-07-02 12:24:58 +0000
commitfc8bdc1af48d4c4e5468669af1fd89dfa2092658 (patch)
tree97c0978905fbaa0a7bd8db9f9d232e38699a95d5 /django
parent9bf4bacf1346d9f8e3ffff85ece5d52c1d24b902 (diff)
unicode: Added support for non-ASCII labels for URL patterns.
git-svn-id: http://code.djangoproject.com/svn/django/branches/unicode@5585 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django')
-rw-r--r--django/core/urlresolvers.py24
1 files changed, 15 insertions, 9 deletions
diff --git a/django/core/urlresolvers.py b/django/core/urlresolvers.py
index 7de840d578..000a56a726 100644
--- a/django/core/urlresolvers.py
+++ b/django/core/urlresolvers.py
@@ -38,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)
@@ -266,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):