@@ -71,6 +71,7 @@ class or function within a module or module in a package. If the
7171import textwrap
7272import time
7373import tokenize
74+ import urllib .parse
7475import warnings
7576from annotationlib import Format
7677from collections import deque
@@ -2314,6 +2315,9 @@ def _gettopic(self, topic, more_xrefs=''):
23142315Sorry, topic and keyword documentation is not available because the
23152316module "pydoc_data.topics" could not be found.
23162317''' , '' )
2318+ if topic in self .symbols :
2319+ topic , _ , xrefs = self .symbols [topic ].partition (' ' )
2320+ more_xrefs = ' ' .join ([xrefs , more_xrefs ]).strip ()
23172321 target = self .topics .get (topic , self .keywords .get (topic ))
23182322 if not target :
23192323 raise ValueError ('could not find topic' )
@@ -2687,14 +2691,14 @@ def onerror(modname):
26872691
26882692 # format page
26892693 def bltinlink (name ):
2690- return '<a href="%s.html">%s</a>' % (name , name )
2694+ return '<a href="%s.html">%s</a>' % (urllib . parse . quote ( name ), html . escape ( name ) )
26912695
26922696 results = []
26932697 heading = html .heading ('Search Results' )
26942698 for name , desc in search_result :
26952699 results .append ('<li>%s%s</li>' % (bltinlink (name ), desc ))
26962700 contents = heading + html .bigsection (
2697- 'key = %s' % key , 'index' , '<ul>\n %s\n </ul>' % '\n ' .join (results ))
2701+ 'key = %s' % html . escape ( key ) , 'index' , '<ul>\n %s\n </ul>' % '\n ' .join (results ))
26982702 return 'Search Results' , contents
26992703
27002704 def html_topics ():
@@ -2720,13 +2724,27 @@ def bltinlink(name):
27202724 contents = heading + html .multicolumn (names , bltinlink )
27212725 return 'Keywords' , contents
27222726
2727+ def html_symbols ():
2728+ """Index of symbols available."""
2729+
2730+ def bltinlink (name ):
2731+ return '<a href="topic?key=%s">%s</a>' % (urllib .parse .quote (name ), html .escape (name ))
2732+
2733+ heading = html .heading ('Symbols' )
2734+ names = sorted (Helper .symbols .keys ())
2735+
2736+ contents = heading + html .multicolumn (names , bltinlink )
2737+ return 'Symbols' , contents
2738+
27232739 def html_topicpage (topic ):
27242740 """Topic or keyword help page."""
27252741 buf = io .StringIO ()
27262742 htmlhelp = Helper (buf , buf )
27272743 contents , xrefs = htmlhelp ._gettopic (topic )
27282744 if topic in htmlhelp .keywords :
27292745 title = 'KEYWORD'
2746+ elif topic in htmlhelp .symbols :
2747+ title = 'SYMBOL'
27302748 else :
27312749 title = 'TOPIC'
27322750 heading = html .heading ('%s %s' % (title .capitalize (), topic ))
@@ -2755,7 +2773,7 @@ def html_error(url, exc):
27552773 heading = html .heading ('Error' )
27562774 contents = '<br>' .join (html .escape (line ) for line in
27572775 format_exception_only (type (exc ), exc ))
2758- contents = heading + html .bigsection (url , 'error' , contents )
2776+ contents = heading + html .bigsection (html . escape ( url ) , 'error' , contents )
27592777 return "Error - %s" % url , contents
27602778
27612779 def get_html_page (url ):
@@ -2770,8 +2788,11 @@ def get_html_page(url):
27702788 title , content = html_topics ()
27712789 elif url == "keywords" :
27722790 title , content = html_keywords ()
2791+ elif url == "symbols" :
2792+ title , content = html_symbols ()
27732793 elif '=' in url :
27742794 op , _ , url = url .partition ('=' )
2795+ url = urllib .parse .unquote (url ).strip ()
27752796 if op == "search?key" :
27762797 title , content = html_search (url )
27772798 elif op == "topic?key" :
0 commit comments