summaryrefslogtreecommitdiff
path: root/Lib/string.py
diff options
context:
space:
mode:
authorSteve Dower <steve.dower@microsoft.com>2017-02-04 15:39:38 -0800
committerSteve Dower <steve.dower@microsoft.com>2017-02-04 15:39:38 -0800
commit1a5780aabb550cae175ad8711e2f33ba644d0ddb (patch)
tree68e47eaafb4ccc17bbdb7668c6058984945b332d /Lib/string.py
parent956c7cfa7111ab5458e2f69868a05b7b84fc6843 (diff)
parentd1d8706cdb77e2adbbb4110338dcda0e1811f892 (diff)
downloadcpython-1a5780aabb550cae175ad8711e2f33ba644d0ddb.tar.gz
Issue #29319: Prevent RunMainFromImporter overwriting sys.path[0].
Diffstat (limited to 'Lib/string.py')
-rw-r--r--Lib/string.py11
1 files changed, 3 insertions, 8 deletions
diff --git a/Lib/string.py b/Lib/string.py
index 89287c4c0a..c902007643 100644
--- a/Lib/string.py
+++ b/Lib/string.py
@@ -28,7 +28,7 @@ ascii_letters = ascii_lowercase + ascii_uppercase
digits = '0123456789'
hexdigits = digits + 'abcdef' + 'ABCDEF'
octdigits = '01234567'
-punctuation = """!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~"""
+punctuation = r"""!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~"""
printable = digits + ascii_letters + punctuation + whitespace
# Functions which aren't available as string methods.
@@ -116,10 +116,7 @@ class Template(metaclass=_TemplateMetaclass):
# Check the most common path first.
named = mo.group('named') or mo.group('braced')
if named is not None:
- 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,)
+ return str(mapping[named])
if mo.group('escaped') is not None:
return self.delimiter
if mo.group('invalid') is not None:
@@ -146,9 +143,7 @@ class Template(metaclass=_TemplateMetaclass):
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],)
+ return str(mapping[named])
except KeyError:
return mo.group()
if mo.group('escaped') is not None: