Group#
- class Group(definition, idx)#
Bases:
objectManage a group inside the filename pattern.
- Parameters:
- Raises:
GroupParseError – Invalid group definition.
- _check_duplicates(m)#
Check if the definition does not contain duplicates.
The matching pattern (
PATTERN) is written so that specs (rgx, fmt, …) can be given in any order, while still matching the full string.The pattern is made of every possible spec in a OR list, which can be repeated up to 5 times. Regex only keep the last captured group. We must be a bit sly to check duplicates. For that I check that the groups we have account for the whole string. If part of the string is not in our match, something has been overwritten.
- Parameters:
m (Match)
- _parse_group_definition()#
Parse group definition against a regex to retrieve specs.
See
_check_duplicate()for details on the pattern matching.- Return type:
None
- _replace_regex_defaults(regex)#
Recursively replace defaults regexes of the form
%[a-zA-Z].Replacements are taken from
Group.DEFAULT_GROUPS.A ‘%’ in the regex should be escaped by another: ‘%%’.
- fix_value(fix)#
Fix the group regex to a specific value.
- get_regex()#
Get group regex.
Returns the fixed value if previously specified. Insert the regex into a capturing group, and make it optional if the
:optwas indicated- Return type:
- unfix()#
Unfix value.
- DEFAULT_GROUPS = {'B': ['[a-zA-Z]*', 's'], 'F': ['%Y-%m-%d', 's'], 'H': ['\\d\\d', '02d'], 'I': ['\\d+', 'd'], 'M': ['\\d\\d', '02d'], 'S': ['\\d\\d', '02d'], 'X': ['%H%M%S', '06d'], 'Y': ['\\d{4}', '04d'], 'char': ['\\S*', 's'], 'd': ['\\d\\d', '02d'], 'j': ['\\d{3}', '03d'], 'm': ['\\d\\d', '02d'], 'text': ['\\w', 's'], 'x': ['%Y%m%d', '08d']}#
Regex and format strings for various default groups.
See the Name section of documentation for details.
- PATTERN = re.compile('(?P<name>[^:]+?)(?:(?P<fmt>:fmt=.+?)|(?P<rgx>:rgx=.*?)|(?P<bool>:bool=.*?(?::.*?)??)|(?P<opt>:opt)|(?P<discard>:discard)){,5}')#
Pattern used to find properties in group definition.
See
_check_duplicates()for details on the pattern matching.
- definition#
The string that created the group
%(definition).
- fmt: FormatAbstract#
Format string object.
- optional: bool#
If True, the whole group is marked as optional (
()?). Is set to False unless specification ‘:opt’ is indicated.