--- /usr/lib/python2.5/pydoc.py 2008-07-31 19:41:00.000000000 +0100 +++ pydoc.py 2008-12-24 16:18:19.000000000 +0000 @@ -1535,6 +1535,42 @@ 'with': ('ref/with', 'CONTEXTMANAGERS EXCEPTIONS yield'), 'yield': ('ref/yield', ''), } + # Either add symbols to this dictionary or to the symbols dictionary + # directly: Whichever is easier. They are merged later. + symbols_inverse = { + 'STRINGS' : ("'", "'''", "r'", "u'", '"""', '"', 'r"', 'u"'), + 'OPERATORS' : ('+', '-', '*', '**', '/', '//', '%', '<<', '>>', '&', + '|', '^', '~', '<', '>', '<=', '>=', '==', '!=', '<>'), + 'COMPARISON' : ('<', '>', '<=', '>=', '==', '!=', '<>'), + 'UNARY' : ('-', '~'), + 'AUGMENTEDASSIGNMENT' : ('+=', '-=', '*=', '/=', '%=', '&=', '|=', + '^=', '<<=', '>>=', '**=', '//='), + 'BITWISE' : ('<<', '>>', '&', '|', '^', '~'), + 'COMPLEX' : ('j', 'J') + } + symbols = { + '%': 'OPERATORS FORMATTING', + '**': 'POWER', + ',': 'TUPLES LISTS FUNCTIONS', + '.': 'ATTRIBUTES FLOAT MODULES OBJECTS', + '...': 'ELLIPSIS', + ':': 'SLICINGS DICTIONARYLITERALS class def elif else except finally for if lambda try while',#I think that's all of the : related keywords. Really should check against the grammar. + '@': 'def class', + '\\': 'STRINGS', + '_': 'PRIVATENAMES', + '__': 'PRIVATENAMES SPECIALMETHODS', + '`': 'BACKQUOTES', + '(': 'TUPLES FUNCTIONS CALLS', + ')': 'TUPLES FUNCTIONS CALLS', + '[': 'LISTS SUBSCRIPTS SLICINGS', + ']': 'LISTS SUBSCRIPTS SLICINGS' + } + for topic, symbols_ in symbols_inverse.iteritems(): + for symbol in symbols_: + topics = symbols.get(symbol, topic) + if topic not in topics: + topics = topics + ' ' + topic + symbols[symbol] = topics topics = { 'TYPES': ('ref/types', 'STRINGS UNICODE NUMBERS SEQUENCES MAPPINGS FUNCTIONS CLASSES MODULES FILES inspect'), @@ -1679,10 +1715,12 @@ if type(request) is type(''): if request == 'help': self.intro() elif request == 'keywords': self.listkeywords() + elif request == 'symbols': self.listsymbols() elif request == 'topics': self.listtopics() elif request == 'modules': self.listmodules() elif request[:8] == 'modules ': self.listmodules(split(request)[1]) + elif request in self.symbols: self.showsymbol(request) elif request in self.keywords: self.showtopic(request) elif request in self.topics: self.showtopic(request) elif request: doc(request, 'Help on %s:') @@ -1728,6 +1766,14 @@ ''') self.list(self.keywords.keys()) + def listsymbols(self): + self.output.write(''' +Here is a list of the punctuation symbols which Python assigns special meaning +to. Enter any symbol to get more help. + +''') + self.list(self.symbols.keys()) + def listtopics(self): self.output.write(''' Here is a list of available topics. Enter any topic name to get more help. @@ -1735,7 +1781,9 @@ ''') self.list(self.topics.keys()) - def showtopic(self, topic): + def showtopic(self, topic, more_xrefs=''): + """Shows help on keywords and topics, and adds more cross references + if supplied.""" if not self.docdir: self.output.write(''' Sorry, topic and keyword documentation is not available because the Python @@ -1751,9 +1799,11 @@ self.output.write('no documentation found for %s\n' % repr(topic)) return if type(target) is type(''): - return self.showtopic(target) + return self.showtopic(target, more_xrefs) filename, xrefs = target + if more_xrefs: + xrefs = xrefs + ' ' + more_xrefs filename = self.docdir + '/' + filename + '.html' try: file = open(filename) @@ -1783,6 +1833,14 @@ 'Related help topics: ' + join(split(xrefs), ', ') + '\n') self.output.write('\n%s\n' % buffer.getvalue()) + def showsymbol(self, symbol): + """Shows help on symbols (basically anything that's google-proof). + The first word in self.symbols[symbol] is shown, and the rest are + added as extra cross-references.""" + target = self.symbols[symbol] + topic, _, xrefs = target.partition(' ') + self.showtopic(topic, xrefs) + def listmodules(self, key=''): if key: self.output.write('''