[2.7] bpo-33422: Fix quotation marks getting deleted when looking up byte/string literals on pydoc. (GH-6701) (GH-6712)
Also update the list of string prefixes.
(cherry picked from commit b2043bbe6034b53f5ad337887f4741b74b70b00d)
diff --git a/Lib/pydoc.py b/Lib/pydoc.py
index b4b190f..62cc262 100755
--- a/Lib/pydoc.py
+++ b/Lib/pydoc.py
@@ -1647,8 +1647,9 @@
}
# 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 @@
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)