Functions for reversing a regular expression (used in reverse URL resolving). Used internally by Django and not intended for external use.
This is not, and is not intended to be, a complete reg-exp decompiler. It should be good enough for a large class of URLS, however.
Constant | ESCAPE_MAPPINGS |
Undocumented |
Class | Choice |
Represent multiple possibilities at this point in a pattern string. |
Class | Group |
Represent a capturing group in the pattern string. |
Class | NonCapture |
Represent a non-capturing group in the pattern string. |
Function | _lazy_re_compile |
Lazily compile a regex with flags. |
Function | contains |
Return True if the "source" contains an instance of "inst". False, otherwise. |
Function | flatten_result |
Turn the given source sequence into a list of reg-exp possibilities and their arguments. Return a list of strings and a list of argument lists. Each of the two lists will be of the same length. |
Function | get_quantifier |
Parse a quantifier from the input, where "ch" is the first character in the quantifier. |
Function | next_char |
No summary |
Function | normalize |
Given a reg-exp pattern, normalize it to an iterable of forms that suffice for reverse matching. This does the following: |
Function | walk_to_end |
The iterator is currently inside a capturing group. Walk to the close of this group, skipping over any nested groups and handling escaped parentheses correctly. |
dict
=
Undocumented
Value |
|
Parse a quantifier from the input, where "ch" is the first character in the quantifier.
Return the minimum number of occurrences permitted by the quantifier and either None or the next character from the input_iter if the next character is not part of the quantifier.
An iterator that yields the next character from "pattern_iter", respecting escape sequences. An escaped character is replaced by a representative of its class (e.g. w -> "x"). If the escaped character is one that is skipped, it is not returned (the next character is returned instead).
Yield the next character, along with a boolean indicating whether it is a raw (unescaped) character or not.
Given a reg-exp pattern, normalize it to an iterable of forms that suffice for reverse matching. This does the following:
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.