[py3] Ported django.utils.regex_helper.

This commit is contained in:
Aymeric Augustin 2012-08-04 11:12:21 +02:00
parent fe8484efda
commit 17da0aa893
1 changed files with 6 additions and 5 deletions

View File

@ -8,6 +8,7 @@ should be good enough for a large class of URLS, however.
from __future__ import unicode_literals
from django.utils import six
from django.utils.six.moves import zip
# Mapping of an escape character to a representative of that class. So, e.g.,
# "\w" is replaced by "x" in a reverse URL. A value of None means to ignore
@ -44,8 +45,8 @@ class NonCapture(list):
def normalize(pattern):
"""
Given a reg-exp pattern, normalizes it to a list of forms that suffice for
reverse matching. This does the following:
Given a reg-exp pattern, normalizes it to an iterable of forms that
suffice for reverse matching. This does the following:
(1) For any repeating sections, keeps the minimum number of occurrences
permitted (this means zero for optional groups).
@ -80,7 +81,7 @@ def normalize(pattern):
try:
ch, escaped = next(pattern_iter)
except StopIteration:
return zip([''], [[]])
return [('', [])]
try:
while True:
@ -193,9 +194,9 @@ def normalize(pattern):
pass
except NotImplementedError:
# A case of using the disjunctive form. No results for you!
return zip([''], [[]])
return [('', [])]
return zip(*flatten_result(result))
return list(zip(*flatten_result(result)))
def next_char(input_iter):
"""