Code

Ticket #6333: django-regexp-flags.2.diff

File django-regexp-flags.2.diff, 1.3 KB (added by leif@…, 6 years ago)
Line 
1Index: django/core/urlresolvers.py
2===================================================================
3--- django/core/urlresolvers.py (revision 7003)
4+++ django/core/urlresolvers.py (working copy)
5@@ -77,6 +77,10 @@
6 
7         >>> reverse_helper(re.compile('^places/(\d+)/$'), 3)
8         'places/3/'
9+        >>> reverse_helper(re.compile('(?uxi)^places/(\d+)/$'), 3)
10+        'places/3/'
11+        >>> reverse_helper(re.compile('^places/(\d+)/$(?ui)'), 3)
12+        'places/3/'
13         >>> reverse_helper(re.compile('^places/(?P<id>\d+)/$'), id=3)
14         'places/3/'
15         >>> reverse_helper(re.compile('^people/(?P<state>\w\w)/(\w+)/$'), 'adrian', state='il')
16@@ -84,8 +88,10 @@
17 
18     Raises NoReverseMatch if the args/kwargs aren't valid for the regex.
19     """
20+    pattern = re.sub(r'^\s*\(\?[iLmsu]*x[iLmsu]*\)', '', regex.pattern)
21+    pattern = re.sub(r'\(\?[iLmsu]+\)', '', regex.pattern)
22     # TODO: Handle nested parenthesis in the following regex.
23-    result = re.sub(r'\(([^)]+)\)', MatchChecker(args, kwargs), regex.pattern)
24+    result = re.sub(r'\(([^)]+)\)', MatchChecker(args, kwargs), pattern)
25     return result.replace('^', '').replace('$', '')
26 
27 class MatchChecker(object):
28@@ -295,4 +301,3 @@
29     args = args or []
30     kwargs = kwargs or {}
31     return iri_to_uri(u'/' + get_resolver(urlconf).reverse(viewname, *args, **kwargs))
32-