| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -710,6 +710,14 @@ to parse template strings. To do this, you can override these class attributes: | |||
| 710 | 710 | appropriate). The default value is the regular expression | |
| 711 | 711 | ``[_a-z][_a-z0-9]*``. | |
| 712 | 712 | ||
| 713 | + * *flags* -- The regular expression flags that will be applied when compiling | ||
| 714 | + the regular expression used for recognizing substitutions. The default value | ||
| 715 | + is ``re.IGNORECASE``. Note that ``re.VERBOSE`` will always be added to the | ||
| 716 | + flags, so custom *idpattern*\ s must follow conventions for verbose regular | ||
| 717 | + expressions. | ||
| 718 | + | ||
| 719 | + .. versionadded:: 3.2 | ||
| 720 | + | ||
| 713 | 721 | Alternatively, you can provide the entire regular expression pattern by | |
| 714 | 722 | overriding the class attribute *pattern*. If you do this, the value must be a | |
| 715 | 723 | regular expression object with four named capturing groups. The capturing | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -81,14 +81,15 @@ def __init__(cls, name, bases, dct): | |||
| 81 | 81 | 'delim' : _re.escape(cls.delimiter), | |
| 82 | 82 | 'id' : cls.idpattern, | |
| 83 | 83 | } | |
| 84 | - cls.pattern = _re.compile(pattern, _re.IGNORECASE | _re.VERBOSE) | ||
| 84 | + cls.pattern = _re.compile(pattern, cls.flags | _re.VERBOSE) | ||
| 85 | 85 | ||
| 86 | 86 | ||
| 87 | 87 | class Template(metaclass=_TemplateMetaclass): | |
| 88 | 88 | """A string class for supporting $-substitutions.""" | |
| 89 | 89 | ||
| 90 | 90 | delimiter = '$' | |
| 91 | 91 | idpattern = r'[_a-z][_a-z0-9]*' | |
| 92 | + flags = _re.IGNORECASE | ||
| 92 | 93 | ||
| 93 | 94 | def __init__(self, template): | |
| 94 | 95 | self.template = template | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -475,6 +475,9 @@ C-API | |||
| 475 | 475 | Library | |
| 476 | 476 | ------- | |
| 477 | 477 | ||
| 478 | + - Issue #6630: Allow customizing regex flags when subclassing the | ||
| 479 | + string.Template class. | ||
| 480 | + | ||
| 478 | 481 | - Issue #9411: Allow specifying an encoding for config files in the | |
| 479 | 482 | configparser module. | |
| 480 | 483 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments