normalize
Given a reg-exp pattern, normalize 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). (2) If an optional group includes parameters, include one occurrence of that group (along with the zero occurrence case from step (1)). (3) Select the first (essentially an arbitrary) element from any character class. Select an arbitrary character for any unordered class (e.g. '.' or '\w') in the pattern. (4) Ignore look-ahead and look-behind assertions. (5) Raise an error on any disjunctive ('|') constructs.
Django's URLs for forward resolving are either all positional arguments or all keyword arguments. That is assumed here, as well. Although reverse resolving can be done using positional args when keyword args are specified, the two cannot be mixed in the same reverse() call.
def normalize(
pattern: string
) - > list
Given a reg-exp pattern, normalize 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). (2) If an optional group includes parameters, include one occurrence of that group (along with the zero occurrence case from step (1)). (3) Select the first (essentially an arbitrary) element from any character class. Select an arbitrary character for any unordered class (e.g. '.' or '\w') in the pattern. (4) Ignore look-ahead and look-behind assertions. (5) Raise an error on any disjunctive ('|') constructs.
Parameters
| Name | Type | Description |
|---|---|---|
| pattern | string | The regular expression pattern string used for URL routing that needs to be normalized for reverse resolution. |
Returns
| Type | Description |
|---|---|
list | A list of tuples, where each tuple contains a format string and a list of parameter names required to reconstruct the URL. |