Commits

mtre...@bcc190cf-cafb-0310-a4f2-bffc1f526a37  committed 3630463

unicode: Added support for non-ASCII labels for URL patterns.

  • Participants
  • Parent commits b9d73ea
  • Branches unicode

Comments (0)

Files changed (3)

File django/core/urlresolvers.py

     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)
 
         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):

File tests/regressiontests/templates/tests.py

             '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),

File tests/regressiontests/templates/urls.py

+# coding: utf-8
 from django.conf.urls.defaults import *
 from regressiontests.templates import views
 
     (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"метка_оператора"),
 )