Ticket #6333: django-regexp-flags.2.diff
File django-regexp-flags.2.diff, 1.3 KB (added by , 17 years ago) |
---|
-
django/core/urlresolvers.py
77 77 78 78 >>> reverse_helper(re.compile('^places/(\d+)/$'), 3) 79 79 'places/3/' 80 >>> reverse_helper(re.compile('(?uxi)^places/(\d+)/$'), 3) 81 'places/3/' 82 >>> reverse_helper(re.compile('^places/(\d+)/$(?ui)'), 3) 83 'places/3/' 80 84 >>> reverse_helper(re.compile('^places/(?P<id>\d+)/$'), id=3) 81 85 'places/3/' 82 86 >>> reverse_helper(re.compile('^people/(?P<state>\w\w)/(\w+)/$'), 'adrian', state='il') … … 84 88 85 89 Raises NoReverseMatch if the args/kwargs aren't valid for the regex. 86 90 """ 91 pattern = re.sub(r'^\s*\(\?[iLmsu]*x[iLmsu]*\)', '', regex.pattern) 92 pattern = re.sub(r'\(\?[iLmsu]+\)', '', regex.pattern) 87 93 # TODO: Handle nested parenthesis in the following regex. 88 result = re.sub(r'\(([^)]+)\)', MatchChecker(args, kwargs), regex.pattern)94 result = re.sub(r'\(([^)]+)\)', MatchChecker(args, kwargs), pattern) 89 95 return result.replace('^', '').replace('$', '') 90 96 91 97 class MatchChecker(object): … … 295 301 args = args or [] 296 302 kwargs = kwargs or {} 297 303 return iri_to_uri(u'/' + get_resolver(urlconf).reverse(viewname, *args, **kwargs)) 298