# HG changeset patch # Parent d5536c06a0824143adb620de2d64ccc54e65d38e diff -r d5536c06a082 Lib/pydoc.py --- a/Lib/pydoc.py Fri Jul 05 01:40:52 2013 +0200 +++ b/Lib/pydoc.py Sat Jul 06 12:13:29 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 @@ -1953,6 +1953,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 +2122,7 @@ import email.message import select import threading + from urllib.parse import unquote_plus class DocHandler(http.server.BaseHTTPRequestHandler): @@ -2134,7 +2140,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_plus(self.path), content_type).encode('utf-8')) def log_message(self, *args): # Don't log messages. @@ -2214,7 +2220,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 +2234,13 @@ ''' % (title, css_link, html_navbar(), contents) def filelink(self, url, path): - return '%s' % (url, path) + return '%s' % (url, html_escape(path)) html = _HTMLDoc() def html_navbar(): - version = html.escape("%s [%s, %s]" % (platform.python_version(), + version = html_escape("%s [%s, %s]" % (platform.python_version(), platform.python_build()[0], platform.python_compiler())) return """ @@ -2247,6 +2252,7 @@ Module Index : Topics : Keywords + : Symbols
@@ -2259,7 +2265,7 @@
- """ % (version, html.escape(platform.platform(terse=True))) + """ % (version, html_escape(platform.platform(terse=True))) def html_index(): """Module Index page.""" @@ -2318,7 +2324,7 @@ """Get and display a source file listing safely.""" path = path.replace('%20', ' ') with tokenize.open(path) as fp: - lines = html.escape(fp.read()) + lines = html_escape(fp.read()) body = '
%s
' % lines heading = html.heading( 'File Listing', @@ -2358,15 +2364,38 @@ 'Keywords', '#ffffff', '#ee77aa', contents) return 'Keywords', contents + def html_symbols(): + """Index of symbol texts available.""" + + def bltinlink(name): + return ('%s' % + (html_escape(name), html_escape(name))) + + heading = html.heading( + 'INDEX', + '#ffffff', '#7799ee') + names = sorted(Helper.symbols.keys()) + + contents = html.multicolumn(names, bltinlink) + contents = heading + html.bigsection( + 'Symbols', '#ffffff', '#ee77aa', contents) + return 'Symbols', contents + def html_topicpage(topic): """Topic or keyword help page.""" buf = io.StringIO() htmlhelp = Helper(buf, buf) - contents, xrefs = htmlhelp._gettopic(topic) if topic in htmlhelp.keywords: title = 'KEYWORD' + contents, xrefs = htmlhelp._gettopic(topic) + elif topic in htmlhelp.topics: + title = 'TOPIC' + contents, xrefs = htmlhelp._gettopic(topic) + elif topic in htmlhelp.symbols: + title = 'SYMBOL' + contents, xrefs = htmlhelp._getsymbol(topic) else: - title = 'TOPIC' + raise ValueError('could not find topic') heading = html.heading( '%s' % title, '#ffffff', '#7799ee') @@ -2396,7 +2425,7 @@ heading = html.heading( 'Error', '#ffffff', '#7799ee') - contents = '
'.join(html.escape(line) for line in + contents = '
'.join(html_escape(line) for line in format_exception_only(type(exc), exc)) contents = heading + html.bigsection(url, '#ffffff', '#bb0000', contents) @@ -2414,6 +2443,8 @@ title, content = html_topics() elif url == "keywords": title, content = html_keywords() + elif url == "symbols": + title, content = html_symbols() elif '=' in url: op, _, url = url.partition('=') if op == "search?key": @@ -2585,3 +2616,4 @@ if __name__ == '__main__': cli() + diff -r d5536c06a082 Lib/test/test_pydoc.py --- a/Lib/test/test_pydoc.py Fri Jul 05 01:40:52 2013 +0200 +++ b/Lib/test/test_pydoc.py Sat Jul 06 12:13:29 2013 -0500 @@ -608,6 +608,7 @@ ("index", "Pydoc: Index of Modules"), ("topics", "Pydoc: Topics"), ("keywords", "Pydoc: Keywords"), + ("symbols", "Pydoc: Symbols"), ("pydoc", "Pydoc: module pydoc"), ("get?key=pydoc", "Pydoc: module pydoc"), ("search?key=pydoc", "Pydoc: Search Results"),