diff options
author | Malcolm Tredinnick <malcolm.tredinnick@gmail.com> | 2008-08-31 22:47:25 +0000 |
---|---|---|
committer | Malcolm Tredinnick <malcolm.tredinnick@gmail.com> | 2008-08-31 22:47:25 +0000 |
commit | 7838493b9efa4ef17111599ed6bfaa05ed70645c (patch) | |
tree | 88056fe8c6a5068531a44b5f915a676a28ecfe68 /django/utils/regex_helper.py | |
parent | ab13303ea44c51f09ccd26ddaee485ddf9c9b1d4 (diff) | |
download | django-7838493b9efa4ef17111599ed6bfaa05ed70645c.tar.gz |
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.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@8777 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/utils/regex_helper.py')
-rw-r--r-- | django/utils/regex_helper.py | 30 |
1 files changed, 15 insertions, 15 deletions
diff --git a/django/utils/regex_helper.py b/django/utils/regex_helper.py index 181285da4f..545bf8899c 100644 --- a/django/utils/regex_helper.py +++ b/django/utils/regex_helper.py @@ -13,12 +13,12 @@ ESCAPE_MAPPINGS = { "A": None, "b": None, "B": None, - "d": '0', - "D": "x", - "s": " ", - "S": "x", - "w": "x", - "W": "!", + "d": u"0", + "D": u"x", + "s": u" ", + "S": u"x", + "w": u"x", + "W": u"!", "Z": None, } @@ -77,7 +77,7 @@ def normalize(pattern): try: ch, escaped = pattern_iter.next() except StopIteration: - return zip([''], [[]]) + return zip([u''], [[]]) try: while True: @@ -85,7 +85,7 @@ def normalize(pattern): result.append(ch) elif ch == '.': # Replace "any character" with an arbitrary representative. - result.append("x") + result.append(u"x") elif ch == '|': # FIXME: One day we'll should do this, but not in 1.0. raise NotImplementedError @@ -117,7 +117,7 @@ def normalize(pattern): # A positional group name = "_%d" % num_args num_args += 1 - result.append(Group((("%%(%s)s" % name), name))) + result.append(Group(((u"%%(%s)s" % name), name))) walk_to_end(ch, pattern_iter) else: ch, escaped = pattern_iter.next() @@ -144,7 +144,7 @@ def normalize(pattern): name.append(ch) ch, escaped = pattern_iter.next() param = ''.join(name) - result.append(Group((("%%(%s)s" % param), param))) + result.append(Group(((u"%%(%s)s" % param), param))) walk_to_end(ch, pattern_iter) elif ch in "*?+{": # Quanitifers affect the previous item in the result list. @@ -180,7 +180,7 @@ def normalize(pattern): pass except NotImplementedError: # A case of using the disjunctive form. No results for you! - return zip([''], [[]]) + return zip([u''], [[]]) return zip(*flatten_result(result)) @@ -279,20 +279,20 @@ def flatten_result(source): Each of the two lists will be of the same length. """ if source is None: - return [''], [[]] + return [u''], [[]] if isinstance(source, Group): if source[1] is None: params = [] else: params = [source[1]] return [source[0]], [params] - result = [''] + result = [u''] result_args = [[]] pos = last = 0 for pos, elt in enumerate(source): if isinstance(elt, basestring): continue - piece = ''.join(source[last:pos]) + piece = u''.join(source[last:pos]) if isinstance(elt, Group): piece += elt[0] param = elt[1] @@ -320,7 +320,7 @@ def flatten_result(source): result = new_result result_args = new_args if pos >= last: - piece = ''.join(source[last:]) + piece = u''.join(source[last:]) for i in range(len(result)): result[i] += piece return result, result_args |