@@ -1574,6 +1574,42 @@ class Helper:
1574
1574
'with' : ('with' , 'CONTEXTMANAGERS EXCEPTIONS yield' ),
1575
1575
'yield' : ('yield' , '' ),
1576
1576
}
1577
+ # Either add symbols to this dictionary or to the symbols dictionary
1578
+ # directly: Whichever is easier. They are merged later.
1579
+ _symbols_inverse = {
1580
+ 'STRINGS' : ("'" , "'''" , "r'" , "u'" , '"""' , '"' , 'r"' , 'u"' ),
1581
+ 'OPERATORS' : ('+' , '-' , '*' , '**' , '/' , '//' , '%' , '<<' , '>>' , '&' ,
1582
+ '|' , '^' , '~' , '<' , '>' , '<=' , '>=' , '==' , '!=' , '<>' ),
1583
+ 'COMPARISON' : ('<' , '>' , '<=' , '>=' , '==' , '!=' , '<>' ),
1584
+ 'UNARY' : ('-' , '~' ),
1585
+ 'AUGMENTEDASSIGNMENT' : ('+=' , '-=' , '*=' , '/=' , '%=' , '&=' , '|=' ,
1586
+ '^=' , '<<=' , '>>=' , '**=' , '//=' ),
1587
+ 'BITWISE' : ('<<' , '>>' , '&' , '|' , '^' , '~' ),
1588
+ 'COMPLEX' : ('j' , 'J' )
1589
+ }
1590
+ symbols = {
1591
+ '%' : 'OPERATORS FORMATTING' ,
1592
+ '**' : 'POWER' ,
1593
+ ',' : 'TUPLES LISTS FUNCTIONS' ,
1594
+ '.' : 'ATTRIBUTES FLOAT MODULES OBJECTS' ,
1595
+ '...' : 'ELLIPSIS' ,
1596
+ ':' : 'SLICINGS DICTIONARYLITERALS' ,
1597
+ '@' : 'def class' ,
1598
+ '\\ ' : 'STRINGS' ,
1599
+ '_' : 'PRIVATENAMES' ,
1600
+ '__' : 'PRIVATENAMES SPECIALMETHODS' ,
1601
+ '`' : 'BACKQUOTES' ,
1602
+ '(' : 'TUPLES FUNCTIONS CALLS' ,
1603
+ ')' : 'TUPLES FUNCTIONS CALLS' ,
1604
+ '[' : 'LISTS SUBSCRIPTS SLICINGS' ,
1605
+ ']' : 'LISTS SUBSCRIPTS SLICINGS'
1606
+ }
1607
+ for topic , symbols_ in _symbols_inverse .iteritems ():
1608
+ for symbol in symbols_ :
1609
+ topics = symbols .get (symbol , topic )
1610
+ if topic not in topics :
1611
+ topics = topics + ' ' + topic
1612
+ symbols [symbol ] = topics
1577
1613
1578
1614
topics = {
1579
1615
'TYPES' : ('types' , 'STRINGS UNICODE NUMBERS SEQUENCES MAPPINGS '
@@ -1717,10 +1753,12 @@ def help(self, request):
1717
1753
if type (request ) is type ('' ):
1718
1754
if request == 'help' : self .intro ()
1719
1755
elif request == 'keywords' : self .listkeywords ()
1756
+ elif request == 'symbols' : self .listsymbols ()
1720
1757
elif request == 'topics' : self .listtopics ()
1721
1758
elif request == 'modules' : self .listmodules ()
1722
1759
elif request [:8 ] == 'modules ' :
1723
1760
self .listmodules (split (request )[1 ])
1761
+ elif request in self .symbols : self .showsymbol (request )
1724
1762
elif request in self .keywords : self .showtopic (request )
1725
1763
elif request in self .topics : self .showtopic (request )
1726
1764
elif request : doc (request , 'Help on %s:' )
@@ -1766,14 +1804,22 @@ def listkeywords(self):
1766
1804
''' )
1767
1805
self .list (self .keywords .keys ())
1768
1806
1807
+ def listsymbols (self ):
1808
+ self .output .write ('''
1809
+ Here is a list of the punctuation symbols which Python assigns special meaning
1810
+ to. Enter any symbol to get more help.
1811
+
1812
+ ''' )
1813
+ self .list (self .symbols .keys ())
1814
+
1769
1815
def listtopics (self ):
1770
1816
self .output .write ('''
1771
1817
Here is a list of available topics. Enter any topic name to get more help.
1772
1818
1773
1819
''' )
1774
1820
self .list (self .topics .keys ())
1775
1821
1776
- def showtopic (self , topic ):
1822
+ def showtopic (self , topic , more_xrefs = '' ):
1777
1823
try :
1778
1824
import pydoc_topics
1779
1825
except ImportError :
@@ -1787,7 +1833,7 @@ def showtopic(self, topic):
1787
1833
self .output .write ('no documentation found for %s\n ' % repr (topic ))
1788
1834
return
1789
1835
if type (target ) is type ('' ):
1790
- return self .showtopic (target )
1836
+ return self .showtopic (target , more_xrefs )
1791
1837
1792
1838
label , xrefs = target
1793
1839
try :
@@ -1796,13 +1842,20 @@ def showtopic(self, topic):
1796
1842
self .output .write ('no documentation found for %s\n ' % repr (topic ))
1797
1843
return
1798
1844
pager (strip (doc ) + '\n ' )
1845
+ if more_xrefs :
1846
+ xrefs = (xrefs or '' ) + ' ' + more_xrefs
1799
1847
if xrefs :
1800
1848
import StringIO , formatter
1801
1849
buffer = StringIO .StringIO ()
1802
1850
formatter .DumbWriter (buffer ).send_flowing_data (
1803
1851
'Related help topics: ' + join (split (xrefs ), ', ' ) + '\n ' )
1804
1852
self .output .write ('\n %s\n ' % buffer .getvalue ())
1805
1853
1854
+ def showsymbol (self , symbol ):
1855
+ target = self .symbols [symbol ]
1856
+ topic , _ , xrefs = target .partition (' ' )
1857
+ self .showtopic (topic , xrefs )
1858
+
1806
1859
def listmodules (self , key = '' ):
1807
1860
if key :
1808
1861
self .output .write ('''
0 commit comments