diff options
author | Georg Brandl <georg@python.org> | 2010-07-29 17:16:10 (GMT) |
---|---|---|
committer | Georg Brandl <georg@python.org> | 2010-07-29 17:16:10 (GMT) |
commit | 056cb93e7accc6cd21d7bec9d25a8d36b16dbb4a (patch) | |
tree | fd95816c3949b3fb737d0cb8f824850063e2027b | |
parent | 1cec3e367c4cdead47eff7ec1f3d65c342daf92f (diff) | |
download | cpython-056cb93e7accc6cd21d7bec9d25a8d36b16dbb4a.zip cpython-056cb93e7accc6cd21d7bec9d25a8d36b16dbb4a.tar.gz cpython-056cb93e7accc6cd21d7bec9d25a8d36b16dbb4a.tar.bz2 |
#6630: allow customizing flags for compiling string.Template.idpattern.
-rw-r--r-- | Doc/library/string.rst | 8 | ||||
-rw-r--r-- | Lib/string.py | 3 | ||||
-rw-r--r-- | Misc/NEWS | 3 |
3 files changed, 13 insertions, 1 deletions
diff --git a/Doc/library/string.rst b/Doc/library/string.rst index 38c872d..68269b9 100644 --- a/Doc/library/string.rst +++ b/Doc/library/string.rst @@ -710,6 +710,14 @@ to parse template strings. To do this, you can override these class attributes: appropriate). The default value is the regular expression ``[_a-z][_a-z0-9]*``. +* *flags* -- The regular expression flags that will be applied when compiling + the regular expression used for recognizing substitutions. The default value + is ``re.IGNORECASE``. Note that ``re.VERBOSE`` will always be added to the + flags, so custom *idpattern*\ s must follow conventions for verbose regular + expressions. + + .. versionadded:: 3.2 + Alternatively, you can provide the entire regular expression pattern by overriding the class attribute *pattern*. If you do this, the value must be a regular expression object with four named capturing groups. The capturing diff --git a/Lib/string.py b/Lib/string.py index 5089193..defe894 100644 --- a/Lib/string.py +++ b/Lib/string.py @@ -81,7 +81,7 @@ class _TemplateMetaclass(type): 'delim' : _re.escape(cls.delimiter), 'id' : cls.idpattern, } - cls.pattern = _re.compile(pattern, _re.IGNORECASE | _re.VERBOSE) + cls.pattern = _re.compile(pattern, cls.flags | _re.VERBOSE) class Template(metaclass=_TemplateMetaclass): @@ -89,6 +89,7 @@ class Template(metaclass=_TemplateMetaclass): delimiter = '$' idpattern = r'[_a-z][_a-z0-9]*' + flags = _re.IGNORECASE def __init__(self, template): self.template = template @@ -475,6 +475,9 @@ C-API Library ------- +- Issue #6630: Allow customizing regex flags when subclassing the + string.Template class. + - Issue #9411: Allow specifying an encoding for config files in the configparser module. |