summaryrefslogtreecommitdiffstats
path: root/Lib/string.py
diff options
context:
space:
mode:
authorYury Selivanov <yselivanov@sprymix.com>2015-05-30 14:57:56 (GMT)
committerYury Selivanov <yselivanov@sprymix.com>2015-05-30 14:57:56 (GMT)
commit7aa5341164794efc5367f63636cbe8327ca40393 (patch)
tree72cabf6ebcc9d1319649e7e60043f8624837693f /Lib/string.py
parent802d45b6604b82ee636fdd795cc6a7d9e655855d (diff)
downloadcpython-7aa5341164794efc5367f63636cbe8327ca40393.zip
cpython-7aa5341164794efc5367f63636cbe8327ca40393.tar.gz
cpython-7aa5341164794efc5367f63636cbe8327ca40393.tar.bz2
Reverting my previous commit.
Something went horribly wrong when I was doing `hg rebase`.
Diffstat (limited to 'Lib/string.py')
-rw-r--r--Lib/string.py9
1 files changed, 7 insertions, 2 deletions
diff --git a/Lib/string.py b/Lib/string.py
index e7b692d..f3365c6 100644
--- a/Lib/string.py
+++ b/Lib/string.py
@@ -112,7 +112,10 @@ class Template(metaclass=_TemplateMetaclass):
# Check the most common path first.
named = mo.group('named') or mo.group('braced')
if named is not None:
- return str(mapping[named])
+ val = mapping[named]
+ # We use this idiom instead of str() because the latter will
+ # fail if val is a Unicode containing non-ASCII characters.
+ return '%s' % (val,)
if mo.group('escaped') is not None:
return self.delimiter
if mo.group('invalid') is not None:
@@ -139,7 +142,9 @@ class Template(metaclass=_TemplateMetaclass):
named = mo.group('named') or mo.group('braced')
if named is not None:
try:
- return str(mapping[named])
+ # 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 mo.group()
if mo.group('escaped') is not None: