Django

Code

Changeset 5630

Show
Ignore:
Timestamp:
07/07/07 13:24:27 (1 year ago)
Author:
mtredinnick
Message:

Fixed #4772 -- Fixed reverse URL creation to work with non-ASCII arguments.
Also included a test for non-ASCII strings in URL patterns, although that
already worked correctly.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/django/core/urlresolvers.py

    r5609 r5630  
    1010from django.http import Http404 
    1111from django.core.exceptions import ImproperlyConfigured, ViewDoesNotExist 
    12 from django.utils.encoding import iri_to_uri 
     12from django.utils.encoding import iri_to_uri, force_unicode 
    1313from django.utils.functional import memoize 
    1414import re 
     
    102102        # 
    103103        grouped = match_obj.group(1) 
    104         m = re.search(r'^\?P<(\w+)>(.*?)$', grouped
     104        m = re.search(r'^\?P<(\w+)>(.*?)$', grouped, re.UNICODE
    105105        if m: # If this was a named group... 
    106106            # m.group(1) is the name of the group 
     
    128128        # Note we're using re.match here on purpose because the start of 
    129129        # to string needs to match. 
    130         if not re.match(test_regex + '$', str(value)): # TODO: Unicode? 
     130        if not re.match(test_regex + '$', force_unicode(value), re.UNICODE): 
    131131            raise NoReverseMatch("Value %r didn't match regular expression %r" % (value, test_regex)) 
    132         return str(value) # TODO: Unicode? 
     132        return force_unicode(value) 
    133133 
    134134class RegexURLPattern(object): 
     
    138138        # which represents the path to a module and a view function name, or a 
    139139        # callable object (view). 
    140         self.regex = re.compile(regex
     140        self.regex = re.compile(regex, re.UNICODE
    141141        if callable(callback): 
    142142            self._callback = callback 
     
    202202        # regex is a string representing a regular expression. 
    203203        # urlconf_name is a string representing the module containing urlconfs. 
    204         self.regex = re.compile(regex
     204        self.regex = re.compile(regex, re.UNICODE
    205205        self.urlconf_name = urlconf_name 
    206206        self.callback = None 
  • django/trunk/django/template/__init__.py

    r5609 r5630  
    513513 )""" % { 
    514514    'str': r"""[^"\\]*(?:\\.[^"\\]*)*""", 
    515     'var_chars': "A-Za-z0-9\_\." , 
     515    'var_chars': "\w\." , 
    516516    'filter_sep': re.escape(FILTER_SEPARATOR), 
    517517    'arg_sep': re.escape(FILTER_ARGUMENT_SEPARATOR), 
     
    521521 
    522522filter_raw_string = filter_raw_string.replace("\n", "").replace(" ", "") 
    523 filter_re = re.compile(filter_raw_string
     523filter_re = re.compile(filter_raw_string, re.UNICODE
    524524 
    525525class FilterExpression(object): 
  • django/trunk/tests/regressiontests/templates/tests.py

    r5609 r5630  
    736736            'url03' : ('{% url regressiontests.templates.views.index %}', {}, '/url_tag/'), 
    737737            'url04' : ('{% url named.client client.id %}', {'client': {'id': 1}}, '/url_tag/named-client/1/'), 
    738             'url05' : (u'{% url метка_оператора 1 %}', {}, '/url_tag/unicode/1/'), 
     738            'url05' : (u'{% url метка_оператора v %}', {'v': u'Ω'}, 
     739                    '/url_tag/%D0%AE%D0%BD%D0%B8%D0%BA%D0%BE%D0%B4/%CE%A9/'), 
    739740 
    740741            # Failures 
  • django/trunk/tests/regressiontests/templates/urls.py

    r5609 r5630  
    1010    (r'^client/(\d+)/(?P<action>[^/]+)/$', views.client_action), 
    1111    url(r'^named-client/(\d+)/$', views.client, name="named.client"), 
    12     url(r'^unicode/(\d+)/$', views.client, name=u"метка_оператора"), 
     12 
     13    # Unicode strings are permitted everywhere. 
     14    url(ur'^Юникод/(\w+)/$', views.client, name=u"метка_оператора"), 
    1315)