Django

Code

Changeset 8777

Show
Ignore:
Timestamp:
08/31/08 17:47:25 (3 months ago)
Author:
mtredinnick
Message:

Fixed #8726 -- When doing reverse URL resolving, make sure we're consistently
dealing with unicode strings throughout by promoting up from UTF-8 as necessary.

Files:

Legend:

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

    r8760 r8777  
    229229                if len(args) != len(params): 
    230230                    continue 
    231                 candidate =  result % dict(zip(params, args)) 
     231                unicode_args = [force_unicode(val) for val in args] 
     232                candidate =  result % dict(zip(params, unicode_args)) 
    232233            else: 
    233234                if set(kwargs.keys()) != set(params): 
    234235                    continue 
    235                 candidate = result % kwargs 
    236             if re.search('^%s' % pattern, candidate, re.UNICODE): 
     236                unicode_kwargs = dict([(k, force_unicode(v)) for (k, v) in kwargs.items()]) 
     237                candidate = result % unicode_kwargs 
     238            if re.search(u'^%s' % pattern, candidate, re.UNICODE): 
    237239                return candidate 
    238240        raise NoReverseMatch("Reverse for '%s' with arguments '%s' and keyword " 
  • django/trunk/django/utils/regex_helper.py

    r8763 r8777  
    1414    "b": None, 
    1515    "B": None, 
    16     "d": '0'
    17     "D": "x", 
    18     "s": " ", 
    19     "S": "x", 
    20     "w": "x", 
    21     "W": "!", 
     16    "d": u"0"
     17    "D": u"x", 
     18    "s": u" ", 
     19    "S": u"x", 
     20    "w": u"x", 
     21    "W": u"!", 
    2222    "Z": None, 
    2323} 
     
    7878        ch, escaped = pattern_iter.next() 
    7979    except StopIteration: 
    80         return zip([''],  [[]]) 
     80        return zip([u''],  [[]]) 
    8181 
    8282    try: 
     
    8686            elif ch == '.': 
    8787                # Replace "any character" with an arbitrary representative. 
    88                 result.append("x") 
     88                result.append(u"x") 
    8989            elif ch == '|': 
    9090                # FIXME: One day we'll should do this, but not in 1.0. 
     
    118118                    name = "_%d" % num_args 
    119119                    num_args += 1 
    120                     result.append(Group((("%%(%s)s" % name), name))) 
     120                    result.append(Group(((u"%%(%s)s" % name), name))) 
    121121                    walk_to_end(ch, pattern_iter) 
    122122                else: 
     
    145145                            ch, escaped = pattern_iter.next() 
    146146                        param = ''.join(name) 
    147                         result.append(Group((("%%(%s)s" % param), param))) 
     147                        result.append(Group(((u"%%(%s)s" % param), param))) 
    148148                        walk_to_end(ch, pattern_iter) 
    149149            elif ch in "*?+{": 
     
    181181    except NotImplementedError: 
    182182        # A case of using the disjunctive form. No results for you! 
    183         return zip([''],  [[]]) 
     183        return zip([u''],  [[]]) 
    184184 
    185185    return zip(*flatten_result(result)) 
     
    280280    """ 
    281281    if source is None: 
    282         return [''], [[]] 
     282        return [u''], [[]] 
    283283    if isinstance(source, Group): 
    284284        if source[1] is None: 
     
    287287            params = [source[1]] 
    288288        return [source[0]], [params] 
    289     result = [''] 
     289    result = [u''] 
    290290    result_args = [[]] 
    291291    pos = last = 0 
     
    293293        if isinstance(elt, basestring): 
    294294            continue 
    295         piece = ''.join(source[last:pos]) 
     295        piece = u''.join(source[last:pos]) 
    296296        if isinstance(elt, Group): 
    297297            piece += elt[0] 
     
    321321            result_args = new_args 
    322322    if pos >= last: 
    323         piece = ''.join(source[last:]) 
     323        piece = u''.join(source[last:]) 
    324324        for i in range(len(result)): 
    325325            result[i] += piece 
  • django/trunk/tests/regressiontests/templates/tests.py

    r8769 r8777  
    195195                except Exception, e: 
    196196                    if e.__class__ != result: 
     197                        raise 
    197198                        failures.append("Template test (TEMPLATE_STRING_IF_INVALID='%s'): %s -- FAILED. Got %s, exception: %s" % (invalid_str, name, e.__class__, e)) 
    198199                    continue 
     
    900901            'url06': (u'{% url метка_оператора_2 tag=v %}', {'v': u'Ω'}, '/url_tag/%D0%AE%D0%BD%D0%B8%D0%BA%D0%BE%D0%B4/%CE%A9/'), 
    901902            'url07': (u'{% url regressiontests.templates.views.client2 tag=v %}', {'v': u'Ω'}, '/url_tag/%D0%AE%D0%BD%D0%B8%D0%BA%D0%BE%D0%B4/%CE%A9/'), 
     903            'url08': (u'{% url метка_оператора v %}', {'v': 'Ω'}, '/url_tag/%D0%AE%D0%BD%D0%B8%D0%BA%D0%BE%D0%B4/%CE%A9/'), 
     904            'url09': (u'{% url метка_оператора_2 tag=v %}', {'v': 'Ω'}, '/url_tag/%D0%AE%D0%BD%D0%B8%D0%BA%D0%BE%D0%B4/%CE%A9/'), 
    902905 
    903906            # Failures