# HG changeset patch
# Parent db9fe49069edccee480196978e670968e271d2e8
diff -r db9fe49069ed Lib/pydoc.py
--- a/Lib/pydoc.py Sun Jul 14 12:45:18 2013 -0700
+++ b/Lib/pydoc.py Mon Jul 15 13:26:54 2013 -0500
@@ -67,7 +67,7 @@
from collections import deque
from reprlib import Repr
from traceback import extract_tb, format_exception_only
-
+from html import escape as html_escape
# --------------------------------------------------------- common routines
@@ -398,9 +398,6 @@
self.maxdict = 10
self.maxstring = self.maxother = 100
- def escape(self, text):
- return replace(text, '&', '&', '<', '<', '>', '>')
-
def repr(self, object):
return Repr.repr(self, object)
@@ -409,7 +406,7 @@
methodname = 'repr_' + '_'.join(type(x).__name__.split())
if hasattr(self, methodname):
return getattr(self, methodname)(x, level)
- return self.escape(cram(stripid(repr(x)), self.maxother))
+ return html_escape(cram(stripid(repr(x)), self.maxother))
def repr_string(self, x, level):
test = cram(x, self.maxstring)
@@ -417,18 +414,18 @@
if '\\' in test and '\\' not in replace(testrepr, r'\\', ''):
# Backslashes are only literal in the string and are never
# needed to make any special characters, so show a raw string.
- return 'r' + testrepr[0] + self.escape(test) + testrepr[0]
+ return 'r' + testrepr[0] + html_escape(test) + testrepr[0]
return re.sub(r'((\\[\\abfnrtv\'"]|\\[0-9]..|\\x..|\\u....)+)',
r'\1',
- self.escape(testrepr))
+ html_escape(testrepr, quote=False))
repr_str = repr_string
def repr_instance(self, x, level):
try:
- return self.escape(cram(stripid(repr(x)), self.maxstring))
+ return html_escape(cram(stripid(repr(x)), self.maxstring))
except:
- return self.escape('<%s instance>' % x.__class__.__name__)
+ return html_escape('<%s instance>' % x.__class__.__name__)
repr_unicode = repr_string
@@ -439,7 +436,6 @@
_repr_instance = HTMLRepr()
repr = _repr_instance.repr
- escape = _repr_instance.escape
def page(self, title, contents):
"""Format an HTML page."""
@@ -491,7 +487,7 @@
def preformat(self, text):
"""Format literal preformatted text."""
- text = self.escape(text.expandtabs())
+ text = html_escape(text.expandtabs(), quote=False)
return replace(text, '\n\n', '\n \n', '\n\n', '\n \n',
' ', ' ', '\n', '
\n')
@@ -550,7 +546,7 @@
def markup(self, text, escape=None, funcs={}, classes={}, methods={}):
"""Mark up some plain text, given a context of symbols to look for.
Each context dictionary maps object names to anchor names."""
- escape = escape or self.escape
+ escape = escape or html_escape
results = []
here = 0
pattern = re.compile(r'\b((http|ftp)://\S+[\w/]|'
@@ -633,9 +629,9 @@
version = str(object.__version__)
if version[:11] == '$' + 'Revision: ' and version[-1:] == '$':
version = version[11:-1].strip()
- info.append('version %s' % self.escape(version))
+ info.append('version %s' % html_escape(version))
if hasattr(object, '__date__'):
- info.append(self.escape(str(object.__date__)))
+ info.append(html_escape(str(object.__date__)))
if info:
head = head + ' (%s)' % ', '.join(info)
docloc = self.getdocloc(object)
@@ -1649,7 +1645,7 @@
'STRINGS' : ("'", "'''", "r'", "b'", '"""', '"', 'r"', 'b"'),
'OPERATORS' : ('+', '-', '*', '**', '/', '//', '%', '<<', '>>', '&',
'|', '^', '~', '<', '>', '<=', '>=', '==', '!=', '<>'),
- 'COMPARISON' : ('<', '>', '<=', '>=', '==', '!=', '<>'),
+ 'COMPARISON' : ('<', '>', '<=', '>=', '==', '!='),
'UNARY' : ('-', '~'),
'AUGMENTEDASSIGNMENT' : ('+=', '-=', '*=', '/=', '%=', '&=', '|=',
'^=', '<<=', '>>=', '**=', '//='),
@@ -1667,7 +1663,6 @@
'\\': 'STRINGS',
'_': 'PRIVATENAMES',
'__': 'PRIVATENAMES SPECIALMETHODS',
- '`': 'BACKQUOTES',
'(': 'TUPLES FUNCTIONS CALLS',
')': 'TUPLES FUNCTIONS CALLS',
'[': 'LISTS SUBSCRIPTS SLICINGS',
@@ -1953,6 +1948,11 @@
topic, _, xrefs = target.partition(' ')
self.showtopic(topic, xrefs)
+ def _getsymbol(self, symbol):
+ target = self.symbols[symbol]
+ topic, _, xrefs = target.partition(' ')
+ return self._gettopic(topic, xrefs)
+
def listmodules(self, key=''):
if key:
self.output.write('''
@@ -2117,6 +2117,7 @@
import email.message
import select
import threading
+ from urllib.parse import unquote
class DocHandler(http.server.BaseHTTPRequestHandler):
@@ -2134,7 +2135,7 @@
self.send_header('Content-Type', '%s; charset=UTF-8' % content_type)
self.end_headers()
self.wfile.write(self.urlhandler(
- self.path, content_type).encode('utf-8'))
+ unquote(self.path), content_type).encode('utf-8'))
def log_message(self, *args):
# Don't log messages.
@@ -2214,7 +2215,6 @@
get_html_page(url) is returned.
"""
class _HTMLDoc(HTMLDoc):
-
def page(self, title, contents):
"""Format an HTML page."""
css_path = "pydoc_data/_pydoc.css"
@@ -2229,13 +2229,14 @@