Permalink
Browse files

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
  • Loading branch information...
1 parent 9bf4bac commit fc8bdc1af48d4c4e5468669af1fd89dfa2092658 @malcolmt malcolmt committed Jul 2, 2007
@@ -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 @@ def reverse(self, lookup_view, *args, **kwargs):
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):
@@ -735,6 +735,7 @@ def test_templates(self):
'url02' : ('{% url regressiontests.templates.views.client_action client.id, action="update" %}', {'client': {'id': 1}}, '/url_tag/client/1/update/'),
'url03' : ('{% url regressiontests.templates.views.index %}', {}, '/url_tag/'),
'url04' : ('{% url named.client client.id %}', {'client': {'id': 1}}, '/url_tag/named-client/1/'),
+ 'url05' : (u'{% url метка_оператора 1 %}', {}, '/url_tag/unicode/1/'),
# Failures
'url-fail01' : ('{% url %}', {}, template.TemplateSyntaxError),
@@ -1,3 +1,4 @@
+# coding: utf-8
from django.conf.urls.defaults import *
from regressiontests.templates import views
@@ -8,4 +9,5 @@
(r'^client/(\d+)/$', views.client),
(r'^client/(\d+)/(?P<action>[^/]+)/$', views.client_action),
url(r'^named-client/(\d+)/$', views.client, name="named.client"),
+ url(r'^unicode/(\d+)/$', views.client, name=u"метка_оператора"),
)

0 comments on commit fc8bdc1

Please sign in to comment.