@@ -1524,141 +1524,141 @@ def writedocs(dir, pkgpath='', done=None):
15241524 return
15251525
15261526class Helper :
1527+
1528+ # These dictionaries map a topic name to either an alias, or a tuple
1529+ # (label, seealso-items). The "label" is the label of the corresponding
1530+ # section in the .rst file under Doc/ and an index into the dictionary
1531+ # in pydoc_topics.py.
1532+ #
1533+ # CAUTION: if you change one of these dictionaries, be sure to adapt the
1534+ # list of needed labels in Doc/tools/sphinxext/pyspecific.py and
1535+ # regenerate the pydoc_topics.py file by running
1536+ # make pydoc-topics
1537+ # in Doc/ and copying the output file into the Lib/ directory.
1538+
15271539 keywords = {
15281540 'and' : 'BOOLEAN' ,
15291541 'as' : 'with' ,
1530- 'assert' : ('ref/ assert' , '' ),
1531- 'break' : ('ref/ break' , 'while for' ),
1532- 'class' : ('ref/ class' , 'CLASSES SPECIALMETHODS' ),
1533- 'continue' : ('ref/ continue' , 'while for' ),
1534- 'def' : ('ref/ function' , '' ),
1535- 'del' : ('ref/ del' , 'BASICMETHODS' ),
1542+ 'assert' : ('assert' , '' ),
1543+ 'break' : ('break' , 'while for' ),
1544+ 'class' : ('class' , 'CLASSES SPECIALMETHODS' ),
1545+ 'continue' : ('continue' , 'while for' ),
1546+ 'def' : ('function' , '' ),
1547+ 'del' : ('del' , 'BASICMETHODS' ),
15361548 'elif' : 'if' ,
1537- 'else' : ('ref/if' , 'while for' ),
1538- 'except' : 'try' ,
1539- 'exec' : ('ref/exec' , '' ),
1540- 'finally' : 'try' ,
1541- 'for' : ('ref/for' , 'break continue while' ),
1542- 'from' : 'import' ,
1543- 'global' : ('ref/global' , 'NAMESPACES' ),
1544- 'if' : ('ref/if' , 'TRUTHVALUE' ),
1545- 'import' : ('ref/import' , 'MODULES' ),
1546- 'in' : ('ref/comparisons' , 'SEQUENCEMETHODS2' ),
1549+ 'else' : ('else' , 'while for' ),
1550+ 'except' : 'except' ,
1551+ 'finally' : 'finally' ,
1552+ 'for' : ('for' , 'break continue while' ),
1553+ 'from' : 'from' ,
1554+ 'global' : ('global' , 'NAMESPACES' ),
1555+ 'if' : ('if' , 'TRUTHVALUE' ),
1556+ 'import' : ('import' , 'MODULES' ),
1557+ 'in' : ('in' , 'SEQUENCEMETHODS2' ),
15471558 'is' : 'COMPARISON' ,
1548- 'lambda' : ('ref/lambdas ' , 'FUNCTIONS' ),
1559+ 'lambda' : ('lambda ' , 'FUNCTIONS' ),
15491560 'not' : 'BOOLEAN' ,
15501561 'or' : 'BOOLEAN' ,
1551- 'pass' : ('ref/pass' , '' ),
1552- 'print' : ('ref/print' , '' ),
1553- 'raise' : ('ref/raise' , 'EXCEPTIONS' ),
1554- 'return' : ('ref/return' , 'FUNCTIONS' ),
1555- 'try' : ('ref/try' , 'EXCEPTIONS' ),
1556- 'while' : ('ref/while' , 'break continue if TRUTHVALUE' ),
1557- 'with' : ('ref/with' , 'CONTEXTMANAGERS EXCEPTIONS yield' ),
1558- 'yield' : ('ref/yield' , '' ),
1562+ 'pass' : ('pass' , '' ),
1563+ 'raise' : ('raise' , 'EXCEPTIONS' ),
1564+ 'return' : ('return' , 'FUNCTIONS' ),
1565+ 'try' : ('try' , 'EXCEPTIONS' ),
1566+ 'while' : ('while' , 'break continue if TRUTHVALUE' ),
1567+ 'with' : ('with' , 'CONTEXTMANAGERS EXCEPTIONS yield' ),
1568+ 'yield' : ('yield' , '' ),
15591569 }
15601570
15611571 topics = {
1562- 'TYPES' : ('ref/types' , 'STRINGS UNICODE NUMBERS SEQUENCES MAPPINGS FUNCTIONS CLASSES MODULES FILES inspect' ),
1563- 'STRINGS' : ('ref/strings' , 'str UNICODE SEQUENCES STRINGMETHODS FORMATTING TYPES' ),
1564- 'STRINGMETHODS' : ('lib/string-methods' , 'STRINGS FORMATTING' ),
1565- 'FORMATTING' : ('lib/typesseq-strings' , 'OPERATORS' ),
1566- 'UNICODE' : ('ref/strings' , 'encodings unicode SEQUENCES STRINGMETHODS FORMATTING TYPES' ),
1567- 'NUMBERS' : ('ref/numbers' , 'INTEGER FLOAT COMPLEX TYPES' ),
1568- 'INTEGER' : ('ref/integers' , 'int range' ),
1569- 'FLOAT' : ('ref/floating' , 'float math' ),
1570- 'COMPLEX' : ('ref/imaginary' , 'complex cmath' ),
1571- 'SEQUENCES' : ('lib/typesseq' , 'STRINGMETHODS FORMATTING range LISTS' ),
1572+ 'TYPES' : ('types' , 'STRINGS UNICODE NUMBERS SEQUENCES MAPPINGS '
1573+ 'FUNCTIONS CLASSES MODULES FILES inspect' ),
1574+ 'STRINGS' : ('strings' , 'str UNICODE SEQUENCES STRINGMETHODS '
1575+ 'FORMATTING TYPES' ),
1576+ 'STRINGMETHODS' : ('string-methods' , 'STRINGS FORMATTING' ),
1577+ 'FORMATTING' : ('formatstrings' , 'OPERATORS' ),
1578+ 'UNICODE' : ('strings' , 'encodings unicode SEQUENCES STRINGMETHODS '
1579+ 'FORMATTING TYPES' ),
1580+ 'NUMBERS' : ('numbers' , 'INTEGER FLOAT COMPLEX TYPES' ),
1581+ 'INTEGER' : ('integers' , 'int range' ),
1582+ 'FLOAT' : ('floating' , 'float math' ),
1583+ 'COMPLEX' : ('imaginary' , 'complex cmath' ),
1584+ 'SEQUENCES' : ('typesseq' , 'STRINGMETHODS FORMATTING range LISTS' ),
15721585 'MAPPINGS' : 'DICTIONARIES' ,
1573- 'FUNCTIONS' : ('lib/ typesfunctions' , 'def TYPES' ),
1574- 'METHODS' : ('lib/ typesmethods' , 'class def CLASSES TYPES' ),
1575- 'CODEOBJECTS' : ('lib/ bltin-code-objects' , 'compile FUNCTIONS TYPES' ),
1576- 'TYPEOBJECTS' : ('lib/ bltin-type-objects' , 'types TYPES' ),
1586+ 'FUNCTIONS' : ('typesfunctions' , 'def TYPES' ),
1587+ 'METHODS' : ('typesmethods' , 'class def CLASSES TYPES' ),
1588+ 'CODEOBJECTS' : ('bltin-code-objects' , 'compile FUNCTIONS TYPES' ),
1589+ 'TYPEOBJECTS' : ('bltin-type-objects' , 'types TYPES' ),
15771590 'FRAMEOBJECTS' : 'TYPES' ,
15781591 'TRACEBACKS' : 'TYPES' ,
1579- 'NONE' : ('lib/ bltin-null-object' , '' ),
1580- 'ELLIPSIS' : ('lib/ bltin-ellipsis-object' , 'SLICINGS' ),
1581- 'FILES' : ('lib/ bltin-file-objects' , '' ),
1582- 'SPECIALATTRIBUTES' : ('lib/ specialattrs' , '' ),
1583- 'CLASSES' : ('ref/ types' , 'class SPECIALMETHODS PRIVATENAMES' ),
1584- 'MODULES' : ('lib/ typesmodules' , 'import' ),
1592+ 'NONE' : ('bltin-null-object' , '' ),
1593+ 'ELLIPSIS' : ('bltin-ellipsis-object' , 'SLICINGS' ),
1594+ 'FILES' : ('bltin-file-objects' , '' ),
1595+ 'SPECIALATTRIBUTES' : ('specialattrs' , '' ),
1596+ 'CLASSES' : ('types' , 'class SPECIALMETHODS PRIVATENAMES' ),
1597+ 'MODULES' : ('typesmodules' , 'import' ),
15851598 'PACKAGES' : 'import' ,
1586- 'EXPRESSIONS' : ('ref/summary' , 'lambda or and not in is BOOLEAN COMPARISON BITWISE SHIFTING BINARY FORMATTING POWER UNARY ATTRIBUTES SUBSCRIPTS SLICINGS CALLS TUPLES LISTS DICTIONARIES' ),
1599+ 'EXPRESSIONS' : ('operator-summary' , 'lambda or and not in is BOOLEAN '
1600+ 'COMPARISON BITWISE SHIFTING BINARY FORMATTING POWER '
1601+ 'UNARY ATTRIBUTES SUBSCRIPTS SLICINGS CALLS TUPLES '
1602+ 'LISTS DICTIONARIES' ),
15871603 'OPERATORS' : 'EXPRESSIONS' ,
15881604 'PRECEDENCE' : 'EXPRESSIONS' ,
1589- 'OBJECTS' : ('ref/objects' , 'TYPES' ),
1590- 'SPECIALMETHODS' : ('ref/specialnames' , 'BASICMETHODS ATTRIBUTEMETHODS CALLABLEMETHODS SEQUENCEMETHODS1 MAPPINGMETHODS SEQUENCEMETHODS2 NUMBERMETHODS CLASSES' ),
1591- 'BASICMETHODS' : ('ref/customization' , 'cmp hash repr str SPECIALMETHODS' ),
1592- 'ATTRIBUTEMETHODS' : ('ref/attribute-access' , 'ATTRIBUTES SPECIALMETHODS' ),
1593- 'CALLABLEMETHODS' : ('ref/callable-types' , 'CALLS SPECIALMETHODS' ),
1594- 'SEQUENCEMETHODS1' : ('ref/sequence-types' , 'SEQUENCES SEQUENCEMETHODS2 SPECIALMETHODS' ),
1595- 'SEQUENCEMETHODS2' : ('ref/sequence-methods' , 'SEQUENCES SEQUENCEMETHODS1 SPECIALMETHODS' ),
1596- 'MAPPINGMETHODS' : ('ref/sequence-types' , 'MAPPINGS SPECIALMETHODS' ),
1597- 'NUMBERMETHODS' : ('ref/numeric-types' , 'NUMBERS AUGMENTEDASSIGNMENT SPECIALMETHODS' ),
1598- 'EXECUTION' : ('ref/execmodel' , 'NAMESPACES DYNAMICFEATURES EXCEPTIONS' ),
1599- 'NAMESPACES' : ('ref/naming' , 'global ASSIGNMENT DELETION DYNAMICFEATURES' ),
1600- 'DYNAMICFEATURES' : ('ref/dynamic-features' , '' ),
1605+ 'OBJECTS' : ('objects' , 'TYPES' ),
1606+ 'SPECIALMETHODS' : ('specialnames' , 'BASICMETHODS ATTRIBUTEMETHODS '
1607+ 'CALLABLEMETHODS SEQUENCEMETHODS1 MAPPINGMETHODS '
1608+ 'SEQUENCEMETHODS2 NUMBERMETHODS CLASSES' ),
1609+ 'BASICMETHODS' : ('customization' , 'cmp hash repr str SPECIALMETHODS' ),
1610+ 'ATTRIBUTEMETHODS' : ('attribute-access' , 'ATTRIBUTES SPECIALMETHODS' ),
1611+ 'CALLABLEMETHODS' : ('callable-types' , 'CALLS SPECIALMETHODS' ),
1612+ 'SEQUENCEMETHODS' : ('sequence-types' , 'SEQUENCES SEQUENCEMETHODS2 '
1613+ 'SPECIALMETHODS' ),
1614+ 'MAPPINGMETHODS' : ('sequence-types' , 'MAPPINGS SPECIALMETHODS' ),
1615+ 'NUMBERMETHODS' : ('numeric-types' , 'NUMBERS AUGMENTEDASSIGNMENT '
1616+ 'SPECIALMETHODS' ),
1617+ 'EXECUTION' : ('execmodel' , 'NAMESPACES DYNAMICFEATURES EXCEPTIONS' ),
1618+ 'NAMESPACES' : ('naming' , 'global ASSIGNMENT DELETION DYNAMICFEATURES' ),
1619+ 'DYNAMICFEATURES' : ('dynamic-features' , '' ),
16011620 'SCOPING' : 'NAMESPACES' ,
16021621 'FRAMES' : 'NAMESPACES' ,
1603- 'EXCEPTIONS' : ('ref/ exceptions' , 'try except finally raise' ),
1604- 'COERCIONS ' : ('ref/coercion-rules' , 'CONVERSIONS ' ),
1605- 'CONVERSIONS ' : ('ref/conversions ' , 'COERCIONS ' ),
1606- 'IDENTIFIERS ' : ('ref/identifiers ' , 'keywords SPECIALIDENTIFIERS ' ),
1607- 'SPECIALIDENTIFIERS ' : ('ref/id-classes ' , '' ),
1608- 'PRIVATENAMES ' : ('ref/ atom-identifiers ' , '' ),
1609- 'LITERALS' : ( 'ref/atom-literals' , 'STRINGS NUMBERS TUPLELITERALS LISTLITERALS DICTIONARYLITERALS' ),
1622+ 'EXCEPTIONS' : ('exceptions' , 'try except finally raise' ),
1623+ 'CONVERSIONS ' : ('conversions' , ' ' ),
1624+ 'IDENTIFIERS ' : ('identifiers ' , 'keywords SPECIALIDENTIFIERS ' ),
1625+ 'SPECIALIDENTIFIERS ' : ('id-classes ' , '' ),
1626+ 'PRIVATENAMES ' : ('atom-identifiers ' , '' ),
1627+ 'LITERALS ' : ('atom-literals ' , 'STRINGS NUMBERS TUPLELITERALS '
1628+ ' LISTLITERALS DICTIONARYLITERALS' ),
16101629 'TUPLES' : 'SEQUENCES' ,
1611- 'TUPLELITERALS' : ('ref/ exprlists' , 'TUPLES LITERALS' ),
1612- 'LISTS' : ('lib/ typesseq-mutable' , 'LISTLITERALS' ),
1613- 'LISTLITERALS' : ('ref/ lists' , 'LISTS LITERALS' ),
1614- 'DICTIONARIES' : ('lib/ typesmapping' , 'DICTIONARYLITERALS' ),
1615- 'DICTIONARYLITERALS' : ('ref/ dict' , 'DICTIONARIES LITERALS' ),
1616- 'ATTRIBUTES' : ('ref/ attribute-references' , 'getattr hasattr setattr ATTRIBUTEMETHODS' ),
1617- 'SUBSCRIPTS' : ('ref/ subscriptions' , 'SEQUENCEMETHODS1' ),
1618- 'SLICINGS' : ('ref/ slicings' , 'SEQUENCEMETHODS2' ),
1619- 'CALLS' : ('ref/ calls' , 'EXPRESSIONS' ),
1620- 'POWER' : ('ref/ power' , 'EXPRESSIONS' ),
1621- 'UNARY' : ('ref/ unary' , 'EXPRESSIONS' ),
1622- 'BINARY' : ('ref/ binary' , 'EXPRESSIONS' ),
1623- 'SHIFTING' : ('ref/ shifting' , 'EXPRESSIONS' ),
1624- 'BITWISE' : ('ref/ bitwise' , 'EXPRESSIONS' ),
1625- 'COMPARISON' : ('ref/ comparisons' , 'EXPRESSIONS BASICMETHODS' ),
1626- 'BOOLEAN' : ('ref/Booleans ' , 'EXPRESSIONS TRUTHVALUE' ),
1630+ 'TUPLELITERALS' : ('exprlists' , 'TUPLES LITERALS' ),
1631+ 'LISTS' : ('typesseq-mutable' , 'LISTLITERALS' ),
1632+ 'LISTLITERALS' : ('lists' , 'LISTS LITERALS' ),
1633+ 'DICTIONARIES' : ('typesmapping' , 'DICTIONARYLITERALS' ),
1634+ 'DICTIONARYLITERALS' : ('dict' , 'DICTIONARIES LITERALS' ),
1635+ 'ATTRIBUTES' : ('attribute-references' , 'getattr hasattr setattr ATTRIBUTEMETHODS' ),
1636+ 'SUBSCRIPTS' : ('subscriptions' , 'SEQUENCEMETHODS1' ),
1637+ 'SLICINGS' : ('slicings' , 'SEQUENCEMETHODS2' ),
1638+ 'CALLS' : ('calls' , 'EXPRESSIONS' ),
1639+ 'POWER' : ('power' , 'EXPRESSIONS' ),
1640+ 'UNARY' : ('unary' , 'EXPRESSIONS' ),
1641+ 'BINARY' : ('binary' , 'EXPRESSIONS' ),
1642+ 'SHIFTING' : ('shifting' , 'EXPRESSIONS' ),
1643+ 'BITWISE' : ('bitwise' , 'EXPRESSIONS' ),
1644+ 'COMPARISON' : ('comparisons' , 'EXPRESSIONS BASICMETHODS' ),
1645+ 'BOOLEAN' : ('booleans ' , 'EXPRESSIONS TRUTHVALUE' ),
16271646 'ASSERTION' : 'assert' ,
1628- 'ASSIGNMENT' : ('ref/ assignment' , 'AUGMENTEDASSIGNMENT' ),
1629- 'AUGMENTEDASSIGNMENT' : ('ref/ augassign' , 'NUMBERMETHODS' ),
1647+ 'ASSIGNMENT' : ('assignment' , 'AUGMENTEDASSIGNMENT' ),
1648+ 'AUGMENTEDASSIGNMENT' : ('augassign' , 'NUMBERMETHODS' ),
16301649 'DELETION' : 'del' ,
1631- 'PRINTING' : 'print' ,
16321650 'RETURNING' : 'return' ,
16331651 'IMPORTING' : 'import' ,
16341652 'CONDITIONAL' : 'if' ,
1635- 'LOOPING' : ('ref/ compound' , 'for while break continue' ),
1636- 'TRUTHVALUE' : ('lib/ truth' , 'if while and or not BASICMETHODS' ),
1637- 'DEBUGGING' : ('lib/module-pdb ' , 'pdb' ),
1638- 'CONTEXTMANAGERS' : ('ref/ context-managers' , 'with' ),
1653+ 'LOOPING' : ('compound' , 'for while break continue' ),
1654+ 'TRUTHVALUE' : ('truth' , 'if while and or not BASICMETHODS' ),
1655+ 'DEBUGGING' : ('debugger ' , 'pdb' ),
1656+ 'CONTEXTMANAGERS' : ('context-managers' , 'with' ),
16391657 }
16401658
16411659 def __init__ (self , input , output ):
16421660 self .input = input
16431661 self .output = output
1644- self .docdir = None
1645- execdir = os .path .dirname (sys .executable )
1646- homedir = os .environ .get ('PYTHONHOME' )
1647- join = os .path .join
1648- for dir in [os .environ .get ('PYTHONDOCS' ),
1649- homedir and os .path .join (homedir , 'doc' ),
1650- join (execdir , 'doc' ), # for Windows
1651- join (sys .prefix , 'doc/python-docs-' + sys .version .split ()[0 ]),
1652- join (sys .prefix , 'doc/python-' + sys .version .split ()[0 ]),
1653- join (sys .prefix , 'doc/python-docs-' + sys .version [:3 ]),
1654- join (sys .prefix , 'doc/python-' + sys .version [:3 ]),
1655- join (sys .prefix , 'Resources/English.lproj/Documentation' )]:
1656- if dir and os .path .isdir (join (dir , 'lib' )):
1657- self .docdir = dir
1658- break
1659- if dir and os .path .isdir (join (dir , 'html' , 'lib' )):
1660- self .docdir = join (dir , 'html' )
1661- break
16621662
16631663 def __repr__ (self ):
16641664 if inspect .stack ()[1 ][3 ] == '?' :
@@ -1760,14 +1760,12 @@ def listtopics(self):
17601760 self .list (self .topics .keys ())
17611761
17621762 def showtopic (self , topic ):
1763- if not self .docdir :
1763+ try :
1764+ import pydoc_topics
1765+ except ImportError :
17641766 self .output .write ('''
1765- Sorry, topic and keyword documentation is not available because the Python
1766- HTML documentation files could not be found. If you have installed them,
1767- please set the environment variable PYTHONDOCS to indicate their location.
1768-
1769- On the Microsoft Windows operating system, the files can be built by
1770- running "hh -decompile . PythonNN.chm" in the C:\PythonNN\Doc> directory.
1767+ Sorry, topic and keyword documentation is not available because the
1768+ module "pydoc_topics" could not be found.
17711769''' )
17721770 return
17731771 target = self .topics .get (topic , self .keywords .get (topic ))
@@ -1777,31 +1775,15 @@ def showtopic(self, topic):
17771775 if type (target ) is type ('' ):
17781776 return self .showtopic (target )
17791777
1780- filename , xrefs = target
1781- filename = self .docdir + '/' + filename + '.html'
1778+ label , xrefs = target
17821779 try :
1783- file = open ( filename )
1784- except :
1785- self .output .write ('could not read docs from %s\n ' % filename )
1780+ doc = pydoc_topics . topics [ label ]
1781+ except KeyError :
1782+ self .output .write ('no documentation found for %s\n ' % repr ( topic ) )
17861783 return
1787-
1788- divpat = re .compile ('<div[^>]*navigat.*?</div.*?>' , re .I | re .S )
1789- addrpat = re .compile ('<address.*?>.*?</address.*?>' , re .I | re .S )
1790- document = re .sub (addrpat , '' , re .sub (divpat , '' , file .read ()))
1791- file .close ()
1792-
1793- import htmllib , formatter , io
1794- buffer = io .StringIO ()
1795- parser = htmllib .HTMLParser (
1796- formatter .AbstractFormatter (formatter .DumbWriter (buffer )))
1797- parser .start_table = parser .do_p
1798- parser .end_table = lambda parser = parser : parser .do_p ({})
1799- parser .start_tr = parser .do_br
1800- parser .start_td = parser .start_th = lambda a , b = buffer : b .write ('\t ' )
1801- parser .feed (document )
1802- buffer = replace (buffer .getvalue (), '\xa0 ' , ' ' , '\n ' , '\n ' )
1803- pager (' ' + buffer .strip () + '\n ' )
1784+ pager (doc .strip () + '\n ' )
18041785 if xrefs :
1786+ import io , formatter
18051787 buffer = io .StringIO ()
18061788 formatter .DumbWriter (buffer ).send_flowing_data (
18071789 'Related help topics: ' + ', ' .join (xrefs .split ()) + '\n ' )
0 commit comments