]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[2.7] bpo-33422: Fix quotation marks getting deleted when looking up byte/string...
authorAndrés Delfino <adelfino@gmail.com>
Mon, 7 May 2018 05:44:03 +0000 (02:44 -0300)
committerSerhiy Storchaka <storchaka@gmail.com>
Mon, 7 May 2018 05:44:03 +0000 (08:44 +0300)
Also update the list of string prefixes.
(cherry picked from commit b2043bbe6034b53f5ad337887f4741b74b70b00d)

Lib/pydoc.py
Misc/NEWS.d/next/Library/2018-05-05-09-53-05.bpo-33422.4FtQ0q.rst [new file with mode: 0644]

index b4b190f3f9a6597b08c5ed2984e34a123d661c7d..62cc262ccb83ff189ba0476d8900169c0d20af2d 100755 (executable)
@@ -1647,8 +1647,9 @@ class Helper:
     }
     # Either add symbols to this dictionary or to the symbols dictionary
     # directly: Whichever is easier. They are merged later.
+    _strprefixes = tuple(p + q for p in ('b', 'r', 'u') for q in ("'", '"'))
     _symbols_inverse = {
-        'STRINGS' : ("'", "'''", "r'", "u'", '"""', '"', 'r"', 'u"'),
+        'STRINGS' : ("'", "'''", '"""', '"') + _strprefixes,
         'OPERATORS' : ('+', '-', '*', '**', '/', '//', '%', '<<', '>>', '&',
                        '|', '^', '~', '<', '>', '<=', '>=', '==', '!=', '<>'),
         'COMPARISON' : ('<', '>', '<=', '>=', '==', '!=', '<>'),
@@ -1811,7 +1812,12 @@ has the same effect as typing a particular string at the help> prompt.
                 if not request: break
             except (KeyboardInterrupt, EOFError):
                 break
-            request = strip(replace(request, '"', '', "'", ''))
+            request = strip(request)
+            # Make sure significant trailing quotation marks of literals don't
+            # get deleted while cleaning input
+            if (len(request) > 2 and request[0] == request[-1] in ("'", '"')
+                    and request[0] not in request[1:-1]):
+                request = request[1:-1]
             if lower(request) in ('q', 'quit'): break
             self.help(request)
 
diff --git a/Misc/NEWS.d/next/Library/2018-05-05-09-53-05.bpo-33422.4FtQ0q.rst b/Misc/NEWS.d/next/Library/2018-05-05-09-53-05.bpo-33422.4FtQ0q.rst
new file mode 100644 (file)
index 0000000..0d284d5
--- /dev/null
@@ -0,0 +1,2 @@
+Fix trailing quotation marks getting deleted when looking up byte/string
+literals on pydoc. Patch by Andrés Delfino.