diff options
author | Florent Xicluna <florent.xicluna@gmail.com> | 2010-09-18 23:34:07 (GMT) |
---|---|---|
committer | Florent Xicluna <florent.xicluna@gmail.com> | 2010-09-18 23:34:07 (GMT) |
commit | eb19dce085de9723678acb8909b403a4c459c86a (patch) | |
tree | 750a297a6ad1b5983411b52c6b16c726fcf09453 /Lib/string.py | |
parent | 98b46702d2798d0db258a02f6a1854dfc5f659fd (diff) | |
download | cpython-eb19dce085de9723678acb8909b403a4c459c86a.zip cpython-eb19dce085de9723678acb8909b403a4c459c86a.tar.gz cpython-eb19dce085de9723678acb8909b403a4c459c86a.tar.bz2 |
Issue #1686: Fix string.Template when overriding the pattern attribute.
Diffstat (limited to 'Lib/string.py')
-rw-r--r-- | Lib/string.py | 12 |
1 files changed, 3 insertions, 9 deletions
diff --git a/Lib/string.py b/Lib/string.py index 2a450cd..d4fee39 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) |