Back to index

python3.2  3.2.2
Public Member Functions | Static Public Attributes | Properties | Private Member Functions | Private Attributes | Static Private Attributes
pydoc.Helper Class Reference
Collaboration diagram for pydoc.Helper:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def __init__
def __repr__
def __call__
def interact
def getline
def help
def intro
def list
def listkeywords
def listsymbols
def listtopics
def showtopic
def showsymbol
def listmodules

Static Public Attributes

dictionary keywords
dictionary symbols
tuple topics = symbols.get(symbol, topic)
string topics = ' '
dictionary topics

Properties

 input = property(lambda self: self._input or sys.stdin)
 output = property(lambda self: self._output or sys.stdout)

Private Member Functions

def _gettopic

Private Attributes

 _input
 _output

Static Private Attributes

dictionary _symbols_inverse
tuple _GoInteractive = object()

Detailed Description

Definition at line 1565 of file pydoc.py.


Constructor & Destructor Documentation

def pydoc.Helper.__init__ (   self,
  input = None,
  output = None 
)

Definition at line 1738 of file pydoc.py.

01738 
01739     def __init__(self, input=None, output=None):
01740         self._input = input
01741         self._output = output

Here is the caller graph for this function:


Member Function Documentation

def pydoc.Helper.__call__ (   self,
  request = _GoInteractive 
)

Definition at line 1752 of file pydoc.py.

01752 
01753     def __call__(self, request=_GoInteractive):
01754         if request is not self._GoInteractive:
01755             self.help(request)
01756         else:
01757             self.intro()
01758             self.interact()
01759             self.output.write('''
01760 You are now leaving help and returning to the Python interpreter.
01761 If you want to ask for help on a particular object directly from the
01762 interpreter, you can type "help(object)".  Executing "help('string')"
01763 has the same effect as typing a particular string at the help> prompt.
01764 ''')

Here is the call graph for this function:

def pydoc.Helper.__repr__ (   self)

Definition at line 1745 of file pydoc.py.

01745 
01746     def __repr__(self):
01747         if inspect.stack()[1][3] == '?':
01748             self()
01749             return ''
01750         return '<pydoc.Helper instance>'

Here is the call graph for this function:

def pydoc.Helper._gettopic (   self,
  topic,
  more_xrefs = '' 
) [private]
Return unbuffered tuple of (topic, xrefs).

If an error occurs here, the exception is caught and displayed by
the url handler.

This function duplicates the showtopic method but returns its
result directly so it can be formatted for display in an html page.

Definition at line 1891 of file pydoc.py.

01891 
01892     def _gettopic(self, topic, more_xrefs=''):
01893         """Return unbuffered tuple of (topic, xrefs).
01894 
01895         If an error occurs here, the exception is caught and displayed by
01896         the url handler.
01897 
01898         This function duplicates the showtopic method but returns its
01899         result directly so it can be formatted for display in an html page.
01900         """
01901         try:
01902             import pydoc_data.topics
01903         except ImportError:
01904             return('''
01905 Sorry, topic and keyword documentation is not available because the
01906 module "pydoc_data.topics" could not be found.
01907 ''' , '')
01908         target = self.topics.get(topic, self.keywords.get(topic))
01909         if not target:
01910             raise ValueError('could not find topic')
01911         if isinstance(target, str):
01912             return self._gettopic(target, more_xrefs)
01913         label, xrefs = target
01914         doc = pydoc_data.topics.topics[label]
01915         if more_xrefs:
01916             xrefs = (xrefs or '') + ' ' + more_xrefs
01917         return doc, xrefs

Here is the call graph for this function:

Here is the caller graph for this function:

def pydoc.Helper.getline (   self,
  prompt 
)
Read one line, using input() when appropriate.

Definition at line 1777 of file pydoc.py.

01777 
01778     def getline(self, prompt):
01779         """Read one line, using input() when appropriate."""
01780         if self.input is sys.stdin:
01781             return input(prompt)
01782         else:
01783             self.output.write(prompt)
01784             self.output.flush()
01785             return self.input.readline()

Here is the caller graph for this function:

def pydoc.Helper.help (   self,
  request 
)

Definition at line 1786 of file pydoc.py.

01786 
01787     def help(self, request):
01788         if type(request) is type(''):
01789             request = request.strip()
01790             if request == 'help': self.intro()
01791             elif request == 'keywords': self.listkeywords()
01792             elif request == 'symbols': self.listsymbols()
01793             elif request == 'topics': self.listtopics()
01794             elif request == 'modules': self.listmodules()
01795             elif request[:8] == 'modules ':
01796                 self.listmodules(request.split()[1])
01797             elif request in self.symbols: self.showsymbol(request)
01798             elif request in ['True', 'False', 'None']:
01799                 # special case these keywords since they are objects too
01800                 doc(eval(request), 'Help on %s:')
01801             elif request in self.keywords: self.showtopic(request)
01802             elif request in self.topics: self.showtopic(request)
01803             elif request: doc(request, 'Help on %s:', output=self._output)
01804         elif isinstance(request, Helper): self()
01805         else: doc(request, 'Help on %s:', output=self._output)
01806         self.output.write('\n')

Here is the call graph for this function:

Here is the caller graph for this function:

def pydoc.Helper.interact (   self)

Definition at line 1765 of file pydoc.py.

01765 
01766     def interact(self):
01767         self.output.write('\n')
01768         while True:
01769             try:
01770                 request = self.getline('help> ')
01771                 if not request: break
01772             except (KeyboardInterrupt, EOFError):
01773                 break
01774             request = replace(request, '"', '', "'", '').strip()
01775             if request.lower() in ('q', 'quit'): break
01776             self.help(request)

Here is the call graph for this function:

Here is the caller graph for this function:

def pydoc.Helper.intro (   self)

Definition at line 1807 of file pydoc.py.

01807 
01808     def intro(self):
01809         self.output.write('''
01810 Welcome to Python %s!  This is the online help utility.
01811 
01812 If this is your first time using Python, you should definitely check out
01813 the tutorial on the Internet at http://docs.python.org/tutorial/.
01814 
01815 Enter the name of any module, keyword, or topic to get help on writing
01816 Python programs and using Python modules.  To quit this help utility and
01817 return to the interpreter, just type "quit".
01818 
01819 To get a list of available modules, keywords, or topics, type "modules",
01820 "keywords", or "topics".  Each module also comes with a one-line summary
01821 of what it does; to list the modules whose summaries contain a given word
01822 such as "spam", type "modules spam".
01823 ''' % sys.version[:3])

Here is the caller graph for this function:

def pydoc.Helper.list (   self,
  items,
  columns = 4,
  width = 80 
)

Definition at line 1824 of file pydoc.py.

01824 
01825     def list(self, items, columns=4, width=80):
01826         items = list(sorted(items))
01827         colw = width // columns
01828         rows = (len(items) + columns - 1) // columns
01829         for row in range(rows):
01830             for col in range(columns):
01831                 i = col * rows + row
01832                 if i < len(items):
01833                     self.output.write(items[i])
01834                     if col < columns - 1:
01835                         self.output.write(' ' + ' ' * (colw - 1 - len(items[i])))
01836             self.output.write('\n')

Here is the call graph for this function:

Here is the caller graph for this function:

def pydoc.Helper.listkeywords (   self)

Definition at line 1837 of file pydoc.py.

01837 
01838     def listkeywords(self):
01839         self.output.write('''
01840 Here is a list of the Python keywords.  Enter any keyword to get more help.
01841 
01842 ''')
01843         self.list(self.keywords.keys())

Here is the call graph for this function:

Here is the caller graph for this function:

def pydoc.Helper.listmodules (   self,
  key = '' 
)

Definition at line 1923 of file pydoc.py.

01923 
01924     def listmodules(self, key=''):
01925         if key:
01926             self.output.write('''
01927 Here is a list of matching modules.  Enter any module name to get more help.
01928 
01929 ''')
01930             apropos(key)
01931         else:
01932             self.output.write('''
01933 Please wait a moment while I gather a list of all available modules...
01934 
01935 ''')
01936             modules = {}
01937             def callback(path, modname, desc, modules=modules):
01938                 if modname and modname[-9:] == '.__init__':
01939                     modname = modname[:-9] + ' (package)'
01940                 if modname.find('.') < 0:
01941                     modules[modname] = 1
01942             def onerror(modname):
01943                 callback(None, modname, None)
01944             ModuleScanner().run(callback, onerror=onerror)
01945             self.list(modules.keys())
01946             self.output.write('''
01947 Enter any module name to get more help.  Or, type "modules spam" to search
01948 for modules whose descriptions contain the word "spam".
01949 ''')

Here is the call graph for this function:

Here is the caller graph for this function:

def pydoc.Helper.listsymbols (   self)

Definition at line 1844 of file pydoc.py.

01844 
01845     def listsymbols(self):
01846         self.output.write('''
01847 Here is a list of the punctuation symbols which Python assigns special meaning
01848 to. Enter any symbol to get more help.
01849 
01850 ''')
01851         self.list(self.symbols.keys())

Here is the call graph for this function:

Here is the caller graph for this function:

def pydoc.Helper.listtopics (   self)

Definition at line 1852 of file pydoc.py.

01852 
01853     def listtopics(self):
01854         self.output.write('''
01855 Here is a list of available topics.  Enter any topic name to get more help.
01856 
01857 ''')
01858         self.list(self.topics.keys())

Here is the call graph for this function:

Here is the caller graph for this function:

def pydoc.Helper.showsymbol (   self,
  symbol 
)

Definition at line 1918 of file pydoc.py.

01918 
01919     def showsymbol(self, symbol):
01920         target = self.symbols[symbol]
01921         topic, _, xrefs = target.partition(' ')
01922         self.showtopic(topic, xrefs)

Here is the call graph for this function:

Here is the caller graph for this function:

def pydoc.Helper.showtopic (   self,
  topic,
  more_xrefs = '' 
)

Definition at line 1859 of file pydoc.py.

01859 
01860     def showtopic(self, topic, more_xrefs=''):
01861         try:
01862             import pydoc_data.topics
01863         except ImportError:
01864             self.output.write('''
01865 Sorry, topic and keyword documentation is not available because the
01866 module "pydoc_data.topics" could not be found.
01867 ''')
01868             return
01869         target = self.topics.get(topic, self.keywords.get(topic))
01870         if not target:
01871             self.output.write('no documentation found for %s\n' % repr(topic))
01872             return
01873         if type(target) is type(''):
01874             return self.showtopic(target, more_xrefs)
01875 
01876         label, xrefs = target
01877         try:
01878             doc = pydoc_data.topics.topics[label]
01879         except KeyError:
01880             self.output.write('no documentation found for %s\n' % repr(topic))
01881             return
01882         pager(doc.strip() + '\n')
01883         if more_xrefs:
01884             xrefs = (xrefs or '') + ' ' + more_xrefs
01885         if xrefs:
01886             import formatter
01887             buffer = io.StringIO()
01888             formatter.DumbWriter(buffer).send_flowing_data(
01889                 'Related help topics: ' + ', '.join(xrefs.split()) + '\n')
01890             self.output.write('\n%s\n' % buffer.getvalue())

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

tuple pydoc.Helper._GoInteractive = object() [static, private]

Definition at line 1751 of file pydoc.py.

Definition at line 1739 of file pydoc.py.

Definition at line 1740 of file pydoc.py.

Initial value:
{
        'STRINGS' : ("'", "'''", "r'", "b'", '"""', '"', 'r"', 'b"'),
        'OPERATORS' : ('+', '-', '*', '**', '/', '//', '%', '<<', '>>', '&',
                       '|', '^', '~', '<', '>', '<=', '>=', '==', '!=', '<>'),
        'COMPARISON' : ('<', '>', '<=', '>=', '==', '!=', '<>'),
        'UNARY' : ('-', '~'),
        'AUGMENTEDASSIGNMENT' : ('+=', '-=', '*=', '/=', '%=', '&=', '|=',
                                '^=', '<<=', '>>=', '**=', '//='),
        'BITWISE' : ('<<', '>>', '&', '|', '^', '~'),
        'COMPLEX' : ('j', 'J')
    }

Definition at line 1615 of file pydoc.py.

Definition at line 1578 of file pydoc.py.

Initial value:
{
        '%': 'OPERATORS FORMATTING',
        '**': 'POWER',
        ',': 'TUPLES LISTS FUNCTIONS',
        '.': 'ATTRIBUTES FLOAT MODULES OBJECTS',
        '...': 'ELLIPSIS',
        ':': 'SLICINGS DICTIONARYLITERALS',
        '@': 'def class',
        '\\': 'STRINGS',
        '_': 'PRIVATENAMES',
        '__': 'PRIVATENAMES SPECIALMETHODS',
        '`': 'BACKQUOTES',
        '(': 'TUPLES FUNCTIONS CALLS',
        ')': 'TUPLES FUNCTIONS CALLS',
        '[': 'LISTS SUBSCRIPTS SLICINGS',
        ']': 'LISTS SUBSCRIPTS SLICINGS'
    }

Definition at line 1626 of file pydoc.py.

tuple pydoc.Helper.topics = symbols.get(symbol, topic) [static]

Definition at line 1645 of file pydoc.py.

string pydoc.Helper.topics = ' ' [static]

Definition at line 1647 of file pydoc.py.

Definition at line 1650 of file pydoc.py.


Property Documentation

pydoc.Helper.input = property(lambda self: self._input or sys.stdin) [static]

Definition at line 1742 of file pydoc.py.

pydoc.Helper.output = property(lambda self: self._output or sys.stdout) [static]

Definition at line 1743 of file pydoc.py.


The documentation for this class was generated from the following file: