# HG changeset patch # Parent 49a9c734304d3e0e9e7a8272d02fda827a76aff8 diff -r 49a9c734304d Lib/pydoc.py --- a/Lib/pydoc.py Sat Jul 06 09:07:06 2013 -1000 +++ b/Lib/pydoc.py Sun Jul 07 07:58: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,14 @@ ''' % (title, css_link, html_navbar(), contents) def filelink(self, url, path): - return '%s' % (url, path) + return ('%s' % + (html_escape(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 +2253,7 @@ Module Index : Topics : Keywords + : Symbols
@@ -2259,7 +2266,7 @@
- """ % (version, html.escape(platform.platform(terse=True))) + """ % (version, html_escape(platform.platform(terse=True))) def html_index(): """Module Index page.""" @@ -2318,7 +2325,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', @@ -2327,46 +2334,42 @@ 'File: %s' % path, '#ffffff', '#ee77aa', body) return 'getfile %s' % path, contents - def html_topics(): + def html_topicindex(title): """Index of topic texts available.""" def bltinlink(name): - return '%s' % (name, name) + return ('%s' % + (html_escape(name), html_escape(name))) heading = html.heading( - 'INDEX', + '%s' % title.upper(), '#ffffff', '#7799ee') - names = sorted(Helper.topics.keys()) - + keys = { + 'topics': Helper.topics.keys, + 'keywords': Helper.keywords.keys, + 'symbols': Helper.symbols.keys, + } + names = sorted(keys[title]()) contents = html.multicolumn(names, bltinlink) contents = heading + html.bigsection( - 'Topics', '#ffffff', '#ee77aa', contents) - return 'Topics', contents - - def html_keywords(): - """Index of keywords.""" - heading = html.heading( - 'INDEX', - '#ffffff', '#7799ee') - names = sorted(Helper.keywords.keys()) - - def bltinlink(name): - return '%s' % (name, name) - - contents = html.multicolumn(names, bltinlink) - contents = heading + html.bigsection( - 'Keywords', '#ffffff', '#ee77aa', contents) - return 'Keywords', contents + title, '#ffffff', '#ee77aa', contents) + return title, 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 +2399,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) @@ -2410,10 +2413,8 @@ try: if url in ("", "index"): title, content = html_index() - elif url == "topics": - title, content = html_topics() - elif url == "keywords": - title, content = html_keywords() + elif url in ("topics", "keywords", "symbols"): + title, content = html_topicindex(url) elif '=' in url: op, _, url = url.partition('=') if op == "search?key": @@ -2585,3 +2586,4 @@ if __name__ == '__main__': cli() + diff -r 49a9c734304d Lib/test/test_pydoc.py --- a/Lib/test/test_pydoc.py Sat Jul 06 09:07:06 2013 -1000 +++ b/Lib/test/test_pydoc.py Sun Jul 07 07:58:29 2013 -0500 @@ -606,8 +606,9 @@ ("", "Pydoc: Index of Modules"), ("get?key=", "Pydoc: Index of Modules"), ("index", "Pydoc: Index of Modules"), - ("topics", "Pydoc: Topics"), - ("keywords", "Pydoc: Keywords"), + ("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"),