filefinder.format#
Generate regex from string format, and parse strings.
Parameters of the format-string are retrieved. See Format Mini Language Specification.
Thoses parameters are then used to generate a regular expression, or to parse a string formed from the format.
Only ‘s’, ‘d’, ‘f’, ‘e’ and ‘E’ formats types are supported.
The width of the format string is not respected when matching with a regular expression.
Module Attributes
The regular expression used to parse a format string. |
Functions
|
Parse format parameters and return appropriate Format object. |
|
Parse format parameters and return appropriate Format object. |
Classes
|
Represent a format string. |
|
Represent a format string for floats (type f, e, E). |
|
Represent a format string for integers (type d). |
|
Represent a format string for numbers (type d, f, e, E). |
|
Represent a format string for strings (type s). |
Exceptions
Dangerous format-string leading to ambiguities. |
|
Error related to Format object. |
|
Could not parse a format-string. |
|
Could not parse value. |
|
Unsupported type of format-string. |
- exception DangerousFormatError#
Dangerous format-string leading to ambiguities.
- exception FormatError#
Error related to Format object.
- exception FormatParsingError#
Could not parse a format-string.
- exception FormatValueParsingError#
Could not parse value.
- exception InvalidFormatTypeError#
Unsupported type of format-string.
- class FormatAbstract(fmt, params)#
Represent a format string.
Can generate an appropriate regular expression corresponding to that format string (to some limitations), generate a string from a value, or parse such a string into a value.
Users are not meant to instanciate those objects directly, use
get_format()
instead (or its alias for retro-compatibilityFormat()
).- Parameters:
- add_outer_alignement(rgx)#
Add necessary regex for alignement characters.
If width is not specified, does nothing.
- generate_expression(capture=False)#
Generate a regular expression matching strings created with this format.
- Parameters:
capture – If true, add capturing groups that will be used to parse the value by selecting only relevant information. Default is false.
- Return type:
- get_fill_regex()#
Return regex for matching fill characters.
- class FormatFloat(*args, **kwargs)#
Represent a format string for floats (type f, e, E).
- generate_expression(capture=False)#
Generate a regular expression matching strings created with this format.
- Return type:
- get_left_of_decimal()#
Get regex for the numbers left of decimal point.
Will deal with grouping if present. Some simplifications for eE formats. Only use groupings for ‘0=’ alignment and enforce single digits grouping.
- Return type:
- get_right_of_decimal()#
Return regex for numbers after decimal points.
Including the decimal point itself. It will respect ‘alternate’ option and the specified precision.
- Return type:
- class FormatInteger(*args, **kwargs)#
Represent a format string for integers (type d).
- class FormatNumberAbstract(*args, **kwargs)#
Represent a format string for numbers (type d, f, e, E).
- get_left_of_decimal()#
Get regex for the numbers left of decimal point.
Will deal with grouping if present.
- Return type:
- class FormatString(*args, **kwargs)#
Represent a format string for strings (type s).
- generate_expression(capture=False)#
Generate a regular expression matching strings created with this format.
- Return type:
- Format(format)#
Parse format parameters and return appropriate Format object.
- Parameters:
format (str) –
- Return type:
- get_format(format)#
Parse format parameters and return appropriate Format object.
- Parameters:
format (str) –
- Return type:
- FORMAT_REGEX = '((?P<fill>.)?(?P<align>[<>=^]))?(?P<sign>[-+ ])?(?P<z>z)?(?P<alternate>#)?(?P<zero>0)?(?P<width>\\d+?)?(?P<grouping>[,_])?(?P<precision>\\.\\d+?)?(?P<type>[a-zA-Z])'#
The regular expression used to parse a format string.
Follows the Format Specification Mini-Language.
[[fill]align][sign]["z"]["#"]["0"][width][grouping_option]["." precision][type]