Here is a list of the Python keywords. Enter any keyword to get more help.
self.list(self.keywords.keys())
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())
Here is a list of available topics. Enter any topic name to get more help.
self.list(self.topics.keys())
def showtopic(self, topic, more_xrefs=''):
Sorry, topic and keyword documentation is not available because the
module "pydoc_data.topics" could not be found.
target = self.topics.get(topic, self.keywords.get(topic))
self.output.write('no documentation found for %s\n' % repr(topic))
if type(target) is type(''):
return self.showtopic(target, more_xrefs)
doc = pydoc_data.topics.topics[label]
self.output.write('no documentation found for %s\n' % repr(topic))
xrefs = (xrefs or '') + ' ' + more_xrefs
text = 'Related help topics: ' + ', '.join(xrefs.split()) + '\n'
wrapped_text = textwrap.wrap(text, 72)
doc += '\n%s\n' % '\n'.join(wrapped_text)
def _gettopic(self, topic, more_xrefs=''):
"""Return unbuffered tuple of (topic, xrefs).
If an error occurs here, the exception is caught and displayed by
This function duplicates the showtopic method but returns its
result directly so it can be formatted for display in an html page.
Sorry, topic and keyword documentation is not available because the
module "pydoc_data.topics" could not be found.
target = self.topics.get(topic, self.keywords.get(topic))
raise ValueError('could not find topic')
if isinstance(target, str):
return self._gettopic(target, more_xrefs)
doc = pydoc_data.topics.topics[label]
xrefs = (xrefs or '') + ' ' + more_xrefs
def showsymbol(self, symbol):
target = self.symbols[symbol]
topic, _, xrefs = target.partition(' ')
self.showtopic(topic, xrefs)
def listmodules(self, key=''):
Here is a list of modules whose name or summary contains '{}'.
If there are any, enter a module name to get more help.
Please wait a moment while I gather a list of all available modules...
def callback(path, modname, desc, modules=modules):
if modname and modname[-9:] == '.__init__':
modname = modname[:-9] + ' (package)'
if modname.find('.') < 0:
callback(None, modname, None)
ModuleScanner().run(callback, onerror=onerror)
self.list(modules.keys())
Enter any module name to get more help. Or, type "modules spam" to search
for modules whose name or summary contain the string "spam".
"""An interruptible scanner that searches module synopses."""
def run(self, callback, key=None, completer=None, onerror=None):
if key: key = key.lower()
for modname in sys.builtin_module_names:
if modname != '__main__':
callback(None, modname, '')
name = __import__(modname).__doc__ or ''
desc = name.split('\n')[0]
name = modname + ' - ' + desc
if name.lower().find(key) >= 0:
callback(None, modname, desc)
for importer, modname, ispkg in pkgutil.walk_packages(onerror=onerror):
callback(None, modname, '')
spec = pkgutil._get_spec(importer, modname)
# raised by tests for bad coding cookies or BOM
if hasattr(loader, 'get_source'):
source = loader.get_source(modname)
desc = source_synopsis(io.StringIO(source)) or ''
if hasattr(loader, 'get_filename'):
path = loader.get_filename(modname)
module = importlib._bootstrap._load(spec)
desc = module.__doc__.splitlines()[0] if module.__doc__ else ''
path = getattr(module,'__file__',None)
name = modname + ' - ' + desc
if name.lower().find(key) >= 0:
callback(path, modname, desc)
"""Print all the one-line module summaries that contain a substring."""
def callback(path, modname, desc):
if modname[-9:] == '.__init__':
modname = modname[:-9] + ' (package)'
print(modname, desc and '- ' + desc)
with warnings.catch_warnings():
warnings.filterwarnings('ignore') # ignore problems during import
ModuleScanner().run(callback, key, onerror=onerror)
# --------------------------------------- enhanced Web browser interface
def _start_server(urlhandler, hostname, port):
"""Start an HTTP server thread on a specific port.
Start an HTML/text server thread, so HTML or text documents can be
browsed dynamically and interactively with a Web browser. Example use:
Define a URL handler. To determine what the client is asking
for, check the URL and content_type.
Then get or generate some text or HTML code and return it.
>>> def my_url_handler(url, content_type):
... text = 'the URL sent was: (%s, %s)' % (url, content_type)
Start server thread on port 0.
If you use port 0, the server will pick a random port number.
You can then use serverthread.port to get the port number.
>>> serverthread = pydoc._start_server(my_url_handler, port)
Check that the server is really started. If it is, open browser
and get first page. Use serverthread.url as the starting page.
>>> if serverthread.serving:
The next two lines are commented out so a browser doesn't open if
doctest is run on this module.
#... webbrowser.open(serverthread.url)
Let the server do its thing. We just need to monitor its status.
Use time.sleep so the loop doesn't hog the CPU.
>>> starttime = time.monotonic()
This is a short timeout for testing purposes.
>>> while serverthread.serving:
... if serverthread.serving and time.monotonic() - starttime > timeout:
Print any errors that may have occurred.
>>> print(serverthread.error)
class DocHandler(http.server.BaseHTTPRequestHandler):
"""Process a request from an HTML browser.
The URL received is in self.path.
Get an HTML page from self.urlhandler and send it.
if self.path.endswith('.css'):
content_type = 'text/css'
content_type = 'text/html'
self.send_header('Content-Type', '%s; charset=UTF-8' % content_type)
self.wfile.write(self.urlhandler(
self.path, content_type).encode('utf-8'))
def log_message(self, *args):
class DocServer(http.server.HTTPServer):
def __init__(self, host, port, callback):
self.address = (self.host, port)
self.base.__init__(self, self.address, self.handler)
def serve_until_quit(self):
rd, wr, ex = select.select([self.socket.fileno()], [], [], 1)
def server_activate(self):
self.base.server_activate(self)
class ServerThread(threading.Thread):
def __init__(self, urlhandler, host, port):
self.urlhandler = urlhandler
threading.Thread.__init__(self)
DocServer.base = http.server.HTTPServer
DocServer.handler = DocHandler
DocHandler.MessageClass = email.message.Message
DocHandler.urlhandler = staticmethod(self.urlhandler)
docsvr = DocServer(self.host, self.port, self.ready)
docsvr.serve_until_quit()
self.port = server.server_port
self.url = 'http://%s:%d/' % (self.host, self.port)
"""Stop the server and this thread nicely"""
self.docserver.quit = True
# explicitly break a reference cycle: DocServer.callback
# has indirectly a reference to ServerThread.
thread = ServerThread(urlhandler, hostname, port)
# Wait until thread.serving is True to make sure we are
# really up before returning.
while not thread.error and not thread.serving:
def _url_handler(url, content_type="text/html"):
"""The pydoc url handler for use with the pydoc server.
If the content_type is 'text/css', the _pydoc.css style
sheet is read and returned if it exits.
If the content_type is 'text/html', then the result of
get_html_page(url) is returned.
def page(self, title, contents):
"""Format an HTML page."""
css_path = "pydoc_data/_pydoc.css"
'<link rel="stylesheet" type="text/css" href="%s">' %
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head><title>Pydoc: %s</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
%s</head><body bgcolor="#f0f0f8">%s<div style="clear:both;padding-top:.5em;">%s</div>
</body></html>''' % (title, css_link, html_navbar(), contents)
version = html.escape("%s [%s, %s]" % (platform.python_version(),
platform.python_build()[0],
platform.python_compiler()))
<div style='float:right'>
<div style='text-align:center'>
<a href="index.html">Module Index</a>
: <a href="topics.html">Topics</a>
: <a href="keywords.html">Keywords</a>
<form action="get" style='display:inline;'>
<input type=text name=key size=15>
<input type=submit value="Get">
<form action="search" style='display:inline;'>
<input type=text name=key size=15>
<input type=submit value="Search">
""" % (version, html.escape(platform.platform(terse=True)))
return '<a href="%s.html">%s</a>' % (name, name)
'<big><big><strong>Index of Modules</strong></big></big>',
names = [name for name in sys.builtin_module_names
contents = html.multicolumn(names, bltinlink)
contents = [heading, '<p>' + html.bigsection(
'Built-in Modules', '#ffffff', '#ee77aa', contents)]
contents.append(html.index(dir, seen))
'<p align=right><font color="#909090" face="helvetica,'
'arial"><strong>pydoc</strong> by Ka-Ping Yee'
'<ping@lfw.org></font>')
return 'Index of Modules', ''.join(contents)
"""Search results page."""
def callback(path, modname, desc):
if modname[-9:] == '.__init__':
modname = modname[:-9] + ' (package)'
search_result.append((modname, desc and '- ' + desc))
with warnings.catch_warnings():
warnings.filterwarnings('ignore') # ignore problems during import
ModuleScanner().run(callback, key, onerror=onerror)
return '<a href="%s.html">%s</a>' % (name, name)
'<big><big><strong>Search Results</strong></big></big>',
for name, desc in search_result:
results.append(bltinlink(name) + desc)
contents = heading + html.bigsection(
'key = %s' % key, '#ffffff', '#ee77aa', '<br>'.join(results))
return 'Search Results', contents
"""Index of topic texts available."""
return '<a href="topic?key=%s">%s</a>' % (name, name)
'<big><big><strong>INDEX</strong></big></big>',
names = sorted(Helper.topics.keys())
contents = html.multicolumn(names, bltinlink)
contents = heading + html.bigsection(
'Topics', '#ffffff', '#ee77aa', contents)
return 'Topics', contents
'<big><big><strong>INDEX</strong></big></big>',
names = sorted(Helper.keywords.keys())
return '<a href="topic?key=%s">%s</a>' % (name, name)
contents = html.multicolumn(names, bltinlink)
contents = heading + html.bigsection(
'Keywords', '#ffffff', '#ee77aa', contents)
return 'Keywords', contents
def html_topicpage(topic):
"""Topic or keyword help page."""
htmlhelp = Helper(buf, buf)
contents, xrefs = htmlhelp._gettopic(topic)
if topic in htmlhelp.keywords:
'<big><big><strong>%s</strong></big></big>' % title,
contents = '<pre>%s</pre>' % html.markup(contents)
contents = html.bigsection(topic , '#ffffff','#ee77aa', contents)
xrefs = sorted(xrefs.split())