Ticket #6333: django-regexp-flags.diff

File django-regexp-flags.diff, 1.2 KB (added by leif@…, 17 years ago)
  • django/core/urlresolvers.py

     
    7777
    7878        >>> reverse_helper(re.compile('^places/(\d+)/$'), 3)
    7979        'places/3/'
     80        >>> reverse_helper(re.compile('(?ui)^places/(\d+)/$'), 3)
     81        'places/3/'
    8082        >>> reverse_helper(re.compile('^places/(?P<id>\d+)/$'), id=3)
    8183        'places/3/'
    8284        >>> reverse_helper(re.compile('^people/(?P<state>\w\w)/(\w+)/$'), 'adrian', state='il')
     
    8486
    8587    Raises NoReverseMatch if the args/kwargs aren't valid for the regex.
    8688    """
     89    pattern = re.sub(r'^\s*\(\?[iLmsux]+\)', '', regex.pattern)
    8790    # 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)
    8992    return result.replace('^', '').replace('$', '')
    9093
    9194class MatchChecker(object):
     
    295298    args = args or []
    296299    kwargs = kwargs or {}
    297300    return iri_to_uri(u'/' + get_resolver(urlconf).reverse(viewname, *args, **kwargs))
    298 
Back to Top