Issue 6630: string.Template custom pattern not working
Created on 2009-08-03 06:47 by jcollado, last changed 2022-04-11 14:56 by admin. This issue is now closed.
| Messages (5) | |||
|---|---|---|---|
| msg91217 - (view) | Author: Javier Collado (jcollado) | Date: 2009-08-03 06:47 | |
In the string.Template documentation (http://docs.python.org/library/string.html) 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 [_a-z][_a-z0-9]*). 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: [_a-zA-Z][_a-zA-Z0-9]* 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) * ![]() |
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) * ![]() |
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) * ![]() |
Date: 2009-08-03 19:52 | |
I agree w/Raymond. string + flags |
|||
| msg111974 - (view) | Author: Georg Brandl (georg.brandl) * ![]() |
Date: 2010-07-29 17:16 | |
Added in r83236. |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022-04-11 14:56:51 | admin | set | github: 50879 |
| 2010-07-29 17:16:25 | georg.brandl | set | status: open -> closed nosy:
+ georg.brandl resolution: fixed |
| 2009-08-03 19:52:10 | barry | set | messages: + msg91238 |
| 2009-08-03 16:58:37 | eric.smith | set | nosy:
+ eric.smith messages: + msg91230 |
| 2009-08-03 16:34:03 | rhettinger | set | assignee: 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:40 | jcollado | create | |
