Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
056cb93e
Commit
056cb93e
authored
Jul 29, 2010
by
Georg Brandl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#6630: allow customizing flags for compiling string.Template.idpattern.
parent
1cec3e36
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
13 additions
and
1 deletion
+13
-1
Doc/library/string.rst
Doc/library/string.rst
+8
-0
Lib/string.py
Lib/string.py
+2
-1
Misc/NEWS
Misc/NEWS
+3
-0
No files found.
Doc/library/string.rst
View file @
056cb93e
...
...
@@ -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
...
...
Lib/string.py
View file @
056cb93e
...
...
@@ -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
...
...
Misc/NEWS
View file @
056cb93e
...
...
@@ -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.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment