Title: string.Template custom pattern not working
Type: enhancement Stage:
Components: Library (Lib) Versions: Python 3.2, Python 2.7
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: barry Nosy List: barry, eric.smith, georg.brandl, jcollado, rhettinger
Priority: normal Keywords:

Created on 2009-08-03 06:47 by jcollado, last changed 2010-07-29 17:16 by georg.brandl. This issue is now closed.

Messages (5)
msg91217 - (view) Author: Javier Collado (jcollado) Date: 2009-08-03 06:47
In the string.Template documentation
( it's explained that if a
custom regular expression for pattern substitution is needed, it's
possible to override idpattern class attribute (whose default value is

However, if the custom pattern that is needed is just uppercase
letters, something like [A-Z]+ won't work because of the following line
in the _TemplateMetaclass class __init__ method:
cls.pattern = _re.compile(pattern, _re.IGNORECASE | _re.VERBOSE)

I would say that this is an error (IGNORECASE just shouldn't be there)
and that the line above should be:
cls.pattern = _re.compile(pattern, _re.VERBOSE)
and the default value for idpattern:

Do you agree on this? Is there any reason for the IGNORECASE option to
be passed to re.compile?
msg91224 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2009-08-03 16:34
Better to add a flags argument and leave the default flag as-is.
msg91230 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2009-08-03 16:58
I agree with Raymond. I think it should either take a string and flags,
or a compiled regex object.
msg91238 - (view) Author: Barry A. Warsaw (barry) * (Python committer) Date: 2009-08-03 19:52
I agree w/Raymond.  string + flags
msg111974 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2010-07-29 17:16
Added in r83236.
Date User Action Args
2010-07-29 17:16:25georg.brandlsetstatus: open -> closed

nosy: + georg.brandl
messages: + msg111974

resolution: fixed
2009-08-03 19:52:10barrysetmessages: + msg91238
2009-08-03 16:58:37eric.smithsetnosy: + eric.smith
messages: + msg91230
2009-08-03 16:34:03rhettingersetassignee: barry
type: behavior -> enhancement
components: + Library (Lib), - Regular Expressions, IO
versions: + Python 2.7, Python 3.2, - Python 2.6, Python 3.0
nosy: + barry, rhettinger

messages: + msg91224
2009-08-03 06:47:40jcolladocreate