From fb055d1a42e1960f2b8f181a886ced9ad8edd9d6 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Thu, 28 May 2015 20:45:29 +0300 Subject: Issue #24309: Removed Python 2 idioms. --- Lib/string.py | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) (limited to 'Lib/string.py') diff --git a/Lib/string.py b/Lib/string.py index f3365c67fb..e7b692d7f7 100644 --- a/Lib/string.py +++ b/Lib/string.py @@ -112,10 +112,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: @@ -142,9 +139,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: -- cgit v1.2.1 From d10868c4ee511a38632289d969e79c89157a7b53 Mon Sep 17 00:00:00 2001 From: Yury Selivanov Date: Sat, 30 May 2015 10:57:56 -0400 Subject: Reverting my previous commit. Something went horribly wrong when I was doing `hg rebase`. --- Lib/string.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'Lib/string.py') diff --git a/Lib/string.py b/Lib/string.py index e7b692d7f7..f3365c67fb 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: -- cgit v1.2.1 From 03c8a473999b08710ae3661724cf1bf1d76bc555 Mon Sep 17 00:00:00 2001 From: R David Murray Date: Thu, 8 Sep 2016 13:59:53 -0400 Subject: #27364: fix "incorrect" uses of escape character in the stdlib. And most of the tools. Patch by Emanual Barry, reviewed by me, Serhiy Storchaka, and Martin Panter. --- Lib/string.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Lib/string.py') diff --git a/Lib/string.py b/Lib/string.py index 7298c89087..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. -- cgit v1.2.1