Ticket #6333: django-regexp-flags.diff
File django-regexp-flags.diff, 1.2 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('(?ui)^places/(\d+)/$'), 3) 81 'places/3/' 80 82 >>> reverse_helper(re.compile('^places/(?P<id>\d+)/$'), id=3) 81 83 'places/3/' 82 84 >>> reverse_helper(re.compile('^people/(?P<state>\w\w)/(\w+)/$'), 'adrian', state='il') … … 84 86 85 87 Raises NoReverseMatch if the args/kwargs aren't valid for the regex. 86 88 """ 89 pattern = re.sub(r'^\s*\(\?[iLmsux]+\)', '', regex.pattern) 87 90 # TODO: Handle nested parenthesis in the following regex. 88 result = re.sub(r'\(([^)]+)\)', MatchChecker(args, kwargs), regex.pattern)91 result = re.sub(r'\(([^)]+)\)', MatchChecker(args, kwargs), pattern) 89 92 return result.replace('^', '').replace('$', '') 90 93 91 94 class MatchChecker(object): … … 295 298 args = args or [] 296 299 kwargs = kwargs or {} 297 300 return iri_to_uri(u'/' + get_resolver(urlconf).reverse(viewname, *args, **kwargs)) 298