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

File django-regexp-flags.2.diff, 1.3 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('(?uxi)^places/(\d+)/$'), 3)
     81        'places/3/'
     82        >>> reverse_helper(re.compile('^places/(\d+)/$(?ui)'), 3)
     83        'places/3/'
    8084        >>> reverse_helper(re.compile('^places/(?P<id>\d+)/$'), id=3)
    8185        'places/3/'
    8286        >>> reverse_helper(re.compile('^people/(?P<state>\w\w)/(\w+)/$'), 'adrian', state='il')
     
    8488
    8589    Raises NoReverseMatch if the args/kwargs aren't valid for the regex.
    8690    """
     91    pattern = re.sub(r'^\s*\(\?[iLmsu]*x[iLmsu]*\)', '', regex.pattern)
     92    pattern = re.sub(r'\(\?[iLmsu]+\)', '', regex.pattern)
    8793    # 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)
    8995    return result.replace('^', '').replace('$', '')
    9096
    9197class MatchChecker(object):
     
    295301    args = args or []
    296302    kwargs = kwargs or {}
    297303    return iri_to_uri(u'/' + get_resolver(urlconf).reverse(viewname, *args, **kwargs))
    298 
Back to Top