summaryrefslogtreecommitdiff
path: root/Lib/string.py
diff options
context:
space:
mode:
authorFlorent Xicluna <florent.xicluna@gmail.com>2010-09-18 23:34:07 +0000
committerFlorent Xicluna <florent.xicluna@gmail.com>2010-09-18 23:34:07 +0000
commit1600e8c4b4b8952faf90e8a0bda1707f70eb85d7 (patch)
tree3c44c2a53b9b466a8091a746a8cf1f0884985b31 /Lib/string.py
parentd5e15c6021d1555f5052f6550c627e11eb94bbc2 (diff)
downloadcpython-1600e8c4b4b8952faf90e8a0bda1707f70eb85d7.tar.gz
Issue #1686: Fix string.Template when overriding the pattern attribute.
Diffstat (limited to 'Lib/string.py')
-rw-r--r--Lib/string.py12
1 files changed, 3 insertions, 9 deletions
diff --git a/Lib/string.py b/Lib/string.py
index 2a450cd962..d4fee391c1 100644
--- a/Lib/string.py
+++ b/Lib/string.py
@@ -145,24 +145,18 @@ class Template(metaclass=_TemplateMetaclass):
mapping = args[0]
# Helper function for .sub()
def convert(mo):
- named = mo.group('named')
+ named = mo.group('named') or mo.group('braced')
if named is not None:
try:
# We use this idiom instead of str() because the latter
# will fail if val is a Unicode containing non-ASCII
return '%s' % (mapping[named],)
except KeyError:
- return self.delimiter + named
- braced = mo.group('braced')
- if braced is not None:
- try:
- return '%s' % (mapping[braced],)
- except KeyError:
- return self.delimiter + '{' + braced + '}'
+ return mo.group()
if mo.group('escaped') is not None:
return self.delimiter
if mo.group('invalid') is not None:
- return self.delimiter
+ return mo.group()
raise ValueError('Unrecognized named group in pattern',
self.pattern)
return self.pattern.sub(convert, self.template)