You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
string.Template not flexible enough to subclass (regexes) #41966
The regular expressions in string.Template can be
overidden, but there's not an easy way to override the
expression for variables inside braces and to a
different expression than variables not in braces.
E.g., you might allow full expressions in braces
(including arbitrary punctuation), but only normal
variable names outside. An example of using this kind
of technique:
So, in summary, idpattern should be split into two,
idpattern and bracepattern. (Maybe a default of None
for bracepattern, and use idpattern if bracepattern is
None -- this would be backward compatible so that
overriding only idpattern will effect both)
Activity
ianbicking commentedon May 9, 2005
The regular expressions in string.Template can be
overidden, but there's not an easy way to override the
expression for variables inside braces and to a
different expression than variables not in braces.
E.g., you might allow full expressions in braces
(including arbitrary punctuation), but only normal
variable names outside. An example of using this kind
of technique:
http://svn.colorstudy.com/home/ianb/recipes/sub_expr.py
So, in summary, idpattern should be split into two,
idpattern and bracepattern. (Maybe a default of None
for bracepattern, and use idpattern if bracepattern is
None -- this would be backward compatible so that
overriding only idpattern will effect both)
devdanzin commentedon Feb 16, 2009
IIUC, Ian's link has a doctest for this feature.
warsaw commentedon Nov 10, 2013
This seems like a reasonable request. Do you care to submit a patch with tests and doc updates?
warsaw commentedon Sep 4, 2017
Sorry for the long delay. It looks like Ian's original link is no longer valid. Do you have an updated link to a possible doctest or example?
warsaw commentedon Sep 4, 2017
Never mind; I crafted a decent test for the PR.
warsaw commentedon Sep 4, 2017
New changeset ba42796 by Barry Warsaw in branch 'master':
bpo-1198569: Allow string.Template braced pattern to be different (bpo-3288)
ba42796
warsaw commentedon Sep 4, 2017
New changeset 973b901 by Barry Warsaw in branch 'master':
What's New for bpo-1198569 (bpo-3303)
973b901