Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/AnonR/anonr.TX.../opt/imh-pyth.../lib/python3....
File: pydoc.py
#! /usr/libexec/platform-python -s
[0] Fix | Delete
"""Generate Python documentation in HTML or text for interactive use.
[1] Fix | Delete
[2] Fix | Delete
At the Python interactive prompt, calling help(thing) on a Python object
[3] Fix | Delete
documents the object, and calling help() starts up an interactive
[4] Fix | Delete
help session.
[5] Fix | Delete
[6] Fix | Delete
Or, at the shell command line outside of Python:
[7] Fix | Delete
[8] Fix | Delete
Run "pydoc <name>" to show documentation on something. <name> may be
[9] Fix | Delete
the name of a function, module, package, or a dotted reference to a
[10] Fix | Delete
class or function within a module or module in a package. If the
[11] Fix | Delete
argument contains a path segment delimiter (e.g. slash on Unix,
[12] Fix | Delete
backslash on Windows) it is treated as the path to a Python source file.
[13] Fix | Delete
[14] Fix | Delete
Run "pydoc -k <keyword>" to search for a keyword in the synopsis lines
[15] Fix | Delete
of all available modules.
[16] Fix | Delete
[17] Fix | Delete
Run "pydoc -n <hostname>" to start an HTTP server with the given
[18] Fix | Delete
hostname (default: localhost) on the local machine.
[19] Fix | Delete
[20] Fix | Delete
Run "pydoc -p <port>" to start an HTTP server on the given port on the
[21] Fix | Delete
local machine. Port number 0 can be used to get an arbitrary unused port.
[22] Fix | Delete
[23] Fix | Delete
Run "pydoc -b" to start an HTTP server on an arbitrary unused port and
[24] Fix | Delete
open a Web browser to interactively browse documentation. Combine with
[25] Fix | Delete
the -n and -p options to control the hostname and port used.
[26] Fix | Delete
[27] Fix | Delete
Run "pydoc -w <name>" to write out the HTML documentation for a module
[28] Fix | Delete
to a file named "<name>.html".
[29] Fix | Delete
[30] Fix | Delete
Module docs for core modules are assumed to be in
[31] Fix | Delete
[32] Fix | Delete
https://docs.python.org/X.Y/library/
[33] Fix | Delete
[34] Fix | Delete
This can be overridden by setting the PYTHONDOCS environment variable
[35] Fix | Delete
to a different URL or to a local directory containing the Library
[36] Fix | Delete
Reference Manual pages.
[37] Fix | Delete
"""
[38] Fix | Delete
__all__ = ['help']
[39] Fix | Delete
__author__ = "Ka-Ping Yee <ping@lfw.org>"
[40] Fix | Delete
__date__ = "26 February 2001"
[41] Fix | Delete
[42] Fix | Delete
__credits__ = """Guido van Rossum, for an excellent programming language.
[43] Fix | Delete
Tommy Burnette, the original creator of manpy.
[44] Fix | Delete
Paul Prescod, for all his work on onlinehelp.
[45] Fix | Delete
Richard Chamberlain, for the first implementation of textdoc.
[46] Fix | Delete
"""
[47] Fix | Delete
[48] Fix | Delete
# Known bugs that can't be fixed here:
[49] Fix | Delete
# - synopsis() cannot be prevented from clobbering existing
[50] Fix | Delete
# loaded modules.
[51] Fix | Delete
# - If the __file__ attribute on a module is a relative path and
[52] Fix | Delete
# the current directory is changed with os.chdir(), an incorrect
[53] Fix | Delete
# path will be displayed.
[54] Fix | Delete
[55] Fix | Delete
import builtins
[56] Fix | Delete
import importlib._bootstrap
[57] Fix | Delete
import importlib._bootstrap_external
[58] Fix | Delete
import importlib.machinery
[59] Fix | Delete
import importlib.util
[60] Fix | Delete
import inspect
[61] Fix | Delete
import io
[62] Fix | Delete
import os
[63] Fix | Delete
import pkgutil
[64] Fix | Delete
import platform
[65] Fix | Delete
import re
[66] Fix | Delete
import sys
[67] Fix | Delete
import sysconfig
[68] Fix | Delete
import time
[69] Fix | Delete
import tokenize
[70] Fix | Delete
import urllib.parse
[71] Fix | Delete
import warnings
[72] Fix | Delete
from collections import deque
[73] Fix | Delete
from reprlib import Repr
[74] Fix | Delete
from traceback import format_exception_only
[75] Fix | Delete
[76] Fix | Delete
[77] Fix | Delete
# --------------------------------------------------------- common routines
[78] Fix | Delete
[79] Fix | Delete
def pathdirs():
[80] Fix | Delete
"""Convert sys.path into a list of absolute, existing, unique paths."""
[81] Fix | Delete
dirs = []
[82] Fix | Delete
normdirs = []
[83] Fix | Delete
for dir in sys.path:
[84] Fix | Delete
dir = os.path.abspath(dir or '.')
[85] Fix | Delete
normdir = os.path.normcase(dir)
[86] Fix | Delete
if normdir not in normdirs and os.path.isdir(dir):
[87] Fix | Delete
dirs.append(dir)
[88] Fix | Delete
normdirs.append(normdir)
[89] Fix | Delete
return dirs
[90] Fix | Delete
[91] Fix | Delete
def _findclass(func):
[92] Fix | Delete
cls = sys.modules.get(func.__module__)
[93] Fix | Delete
if cls is None:
[94] Fix | Delete
return None
[95] Fix | Delete
for name in func.__qualname__.split('.')[:-1]:
[96] Fix | Delete
cls = getattr(cls, name)
[97] Fix | Delete
if not inspect.isclass(cls):
[98] Fix | Delete
return None
[99] Fix | Delete
return cls
[100] Fix | Delete
[101] Fix | Delete
def _finddoc(obj):
[102] Fix | Delete
if inspect.ismethod(obj):
[103] Fix | Delete
name = obj.__func__.__name__
[104] Fix | Delete
self = obj.__self__
[105] Fix | Delete
if (inspect.isclass(self) and
[106] Fix | Delete
getattr(getattr(self, name, None), '__func__') is obj.__func__):
[107] Fix | Delete
# classmethod
[108] Fix | Delete
cls = self
[109] Fix | Delete
else:
[110] Fix | Delete
cls = self.__class__
[111] Fix | Delete
elif inspect.isfunction(obj):
[112] Fix | Delete
name = obj.__name__
[113] Fix | Delete
cls = _findclass(obj)
[114] Fix | Delete
if cls is None or getattr(cls, name) is not obj:
[115] Fix | Delete
return None
[116] Fix | Delete
elif inspect.isbuiltin(obj):
[117] Fix | Delete
name = obj.__name__
[118] Fix | Delete
self = obj.__self__
[119] Fix | Delete
if (inspect.isclass(self) and
[120] Fix | Delete
self.__qualname__ + '.' + name == obj.__qualname__):
[121] Fix | Delete
# classmethod
[122] Fix | Delete
cls = self
[123] Fix | Delete
else:
[124] Fix | Delete
cls = self.__class__
[125] Fix | Delete
# Should be tested before isdatadescriptor().
[126] Fix | Delete
elif isinstance(obj, property):
[127] Fix | Delete
func = obj.fget
[128] Fix | Delete
name = func.__name__
[129] Fix | Delete
cls = _findclass(func)
[130] Fix | Delete
if cls is None or getattr(cls, name) is not obj:
[131] Fix | Delete
return None
[132] Fix | Delete
elif inspect.ismethoddescriptor(obj) or inspect.isdatadescriptor(obj):
[133] Fix | Delete
name = obj.__name__
[134] Fix | Delete
cls = obj.__objclass__
[135] Fix | Delete
if getattr(cls, name) is not obj:
[136] Fix | Delete
return None
[137] Fix | Delete
if inspect.ismemberdescriptor(obj):
[138] Fix | Delete
slots = getattr(cls, '__slots__', None)
[139] Fix | Delete
if isinstance(slots, dict) and name in slots:
[140] Fix | Delete
return slots[name]
[141] Fix | Delete
else:
[142] Fix | Delete
return None
[143] Fix | Delete
for base in cls.__mro__:
[144] Fix | Delete
try:
[145] Fix | Delete
doc = _getowndoc(getattr(base, name))
[146] Fix | Delete
except AttributeError:
[147] Fix | Delete
continue
[148] Fix | Delete
if doc is not None:
[149] Fix | Delete
return doc
[150] Fix | Delete
return None
[151] Fix | Delete
[152] Fix | Delete
def _getowndoc(obj):
[153] Fix | Delete
"""Get the documentation string for an object if it is not
[154] Fix | Delete
inherited from its class."""
[155] Fix | Delete
try:
[156] Fix | Delete
doc = object.__getattribute__(obj, '__doc__')
[157] Fix | Delete
if doc is None:
[158] Fix | Delete
return None
[159] Fix | Delete
if obj is not type:
[160] Fix | Delete
typedoc = type(obj).__doc__
[161] Fix | Delete
if isinstance(typedoc, str) and typedoc == doc:
[162] Fix | Delete
return None
[163] Fix | Delete
return doc
[164] Fix | Delete
except AttributeError:
[165] Fix | Delete
return None
[166] Fix | Delete
[167] Fix | Delete
def _getdoc(object):
[168] Fix | Delete
"""Get the documentation string for an object.
[169] Fix | Delete
[170] Fix | Delete
All tabs are expanded to spaces. To clean up docstrings that are
[171] Fix | Delete
indented to line up with blocks of code, any whitespace than can be
[172] Fix | Delete
uniformly removed from the second line onwards is removed."""
[173] Fix | Delete
doc = _getowndoc(object)
[174] Fix | Delete
if doc is None:
[175] Fix | Delete
try:
[176] Fix | Delete
doc = _finddoc(object)
[177] Fix | Delete
except (AttributeError, TypeError):
[178] Fix | Delete
return None
[179] Fix | Delete
if not isinstance(doc, str):
[180] Fix | Delete
return None
[181] Fix | Delete
return inspect.cleandoc(doc)
[182] Fix | Delete
[183] Fix | Delete
def getdoc(object):
[184] Fix | Delete
"""Get the doc string or comments for an object."""
[185] Fix | Delete
result = _getdoc(object) or inspect.getcomments(object)
[186] Fix | Delete
return result and re.sub('^ *\n', '', result.rstrip()) or ''
[187] Fix | Delete
[188] Fix | Delete
def splitdoc(doc):
[189] Fix | Delete
"""Split a doc string into a synopsis line (if any) and the rest."""
[190] Fix | Delete
lines = doc.strip().split('\n')
[191] Fix | Delete
if len(lines) == 1:
[192] Fix | Delete
return lines[0], ''
[193] Fix | Delete
elif len(lines) >= 2 and not lines[1].rstrip():
[194] Fix | Delete
return lines[0], '\n'.join(lines[2:])
[195] Fix | Delete
return '', '\n'.join(lines)
[196] Fix | Delete
[197] Fix | Delete
def classname(object, modname):
[198] Fix | Delete
"""Get a class name and qualify it with a module name if necessary."""
[199] Fix | Delete
name = object.__name__
[200] Fix | Delete
if object.__module__ != modname:
[201] Fix | Delete
name = object.__module__ + '.' + name
[202] Fix | Delete
return name
[203] Fix | Delete
[204] Fix | Delete
def isdata(object):
[205] Fix | Delete
"""Check if an object is of a type that probably means it's data."""
[206] Fix | Delete
return not (inspect.ismodule(object) or inspect.isclass(object) or
[207] Fix | Delete
inspect.isroutine(object) or inspect.isframe(object) or
[208] Fix | Delete
inspect.istraceback(object) or inspect.iscode(object))
[209] Fix | Delete
[210] Fix | Delete
def replace(text, *pairs):
[211] Fix | Delete
"""Do a series of global replacements on a string."""
[212] Fix | Delete
while pairs:
[213] Fix | Delete
text = pairs[1].join(text.split(pairs[0]))
[214] Fix | Delete
pairs = pairs[2:]
[215] Fix | Delete
return text
[216] Fix | Delete
[217] Fix | Delete
def cram(text, maxlen):
[218] Fix | Delete
"""Omit part of a string if needed to make it fit in a maximum length."""
[219] Fix | Delete
if len(text) > maxlen:
[220] Fix | Delete
pre = max(0, (maxlen-3)//2)
[221] Fix | Delete
post = max(0, maxlen-3-pre)
[222] Fix | Delete
return text[:pre] + '...' + text[len(text)-post:]
[223] Fix | Delete
return text
[224] Fix | Delete
[225] Fix | Delete
_re_stripid = re.compile(r' at 0x[0-9a-f]{6,16}(>+)$', re.IGNORECASE)
[226] Fix | Delete
def stripid(text):
[227] Fix | Delete
"""Remove the hexadecimal id from a Python object representation."""
[228] Fix | Delete
# The behaviour of %p is implementation-dependent in terms of case.
[229] Fix | Delete
return _re_stripid.sub(r'\1', text)
[230] Fix | Delete
[231] Fix | Delete
def _is_bound_method(fn):
[232] Fix | Delete
"""
[233] Fix | Delete
Returns True if fn is a bound method, regardless of whether
[234] Fix | Delete
fn was implemented in Python or in C.
[235] Fix | Delete
"""
[236] Fix | Delete
if inspect.ismethod(fn):
[237] Fix | Delete
return True
[238] Fix | Delete
if inspect.isbuiltin(fn):
[239] Fix | Delete
self = getattr(fn, '__self__', None)
[240] Fix | Delete
return not (inspect.ismodule(self) or (self is None))
[241] Fix | Delete
return False
[242] Fix | Delete
[243] Fix | Delete
[244] Fix | Delete
def allmethods(cl):
[245] Fix | Delete
methods = {}
[246] Fix | Delete
for key, value in inspect.getmembers(cl, inspect.isroutine):
[247] Fix | Delete
methods[key] = 1
[248] Fix | Delete
for base in cl.__bases__:
[249] Fix | Delete
methods.update(allmethods(base)) # all your base are belong to us
[250] Fix | Delete
for key in methods.keys():
[251] Fix | Delete
methods[key] = getattr(cl, key)
[252] Fix | Delete
return methods
[253] Fix | Delete
[254] Fix | Delete
def _split_list(s, predicate):
[255] Fix | Delete
"""Split sequence s via predicate, and return pair ([true], [false]).
[256] Fix | Delete
[257] Fix | Delete
The return value is a 2-tuple of lists,
[258] Fix | Delete
([x for x in s if predicate(x)],
[259] Fix | Delete
[x for x in s if not predicate(x)])
[260] Fix | Delete
"""
[261] Fix | Delete
[262] Fix | Delete
yes = []
[263] Fix | Delete
no = []
[264] Fix | Delete
for x in s:
[265] Fix | Delete
if predicate(x):
[266] Fix | Delete
yes.append(x)
[267] Fix | Delete
else:
[268] Fix | Delete
no.append(x)
[269] Fix | Delete
return yes, no
[270] Fix | Delete
[271] Fix | Delete
def visiblename(name, all=None, obj=None):
[272] Fix | Delete
"""Decide whether to show documentation on a variable."""
[273] Fix | Delete
# Certain special names are redundant or internal.
[274] Fix | Delete
# XXX Remove __initializing__?
[275] Fix | Delete
if name in {'__author__', '__builtins__', '__cached__', '__credits__',
[276] Fix | Delete
'__date__', '__doc__', '__file__', '__spec__',
[277] Fix | Delete
'__loader__', '__module__', '__name__', '__package__',
[278] Fix | Delete
'__path__', '__qualname__', '__slots__', '__version__'}:
[279] Fix | Delete
return 0
[280] Fix | Delete
# Private names are hidden, but special names are displayed.
[281] Fix | Delete
if name.startswith('__') and name.endswith('__'): return 1
[282] Fix | Delete
# Namedtuples have public fields and methods with a single leading underscore
[283] Fix | Delete
if name.startswith('_') and hasattr(obj, '_fields'):
[284] Fix | Delete
return True
[285] Fix | Delete
if all is not None:
[286] Fix | Delete
# only document that which the programmer exported in __all__
[287] Fix | Delete
return name in all
[288] Fix | Delete
else:
[289] Fix | Delete
return not name.startswith('_')
[290] Fix | Delete
[291] Fix | Delete
def classify_class_attrs(object):
[292] Fix | Delete
"""Wrap inspect.classify_class_attrs, with fixup for data descriptors."""
[293] Fix | Delete
results = []
[294] Fix | Delete
for (name, kind, cls, value) in inspect.classify_class_attrs(object):
[295] Fix | Delete
if inspect.isdatadescriptor(value):
[296] Fix | Delete
kind = 'data descriptor'
[297] Fix | Delete
if isinstance(value, property) and value.fset is None:
[298] Fix | Delete
kind = 'readonly property'
[299] Fix | Delete
results.append((name, kind, cls, value))
[300] Fix | Delete
return results
[301] Fix | Delete
[302] Fix | Delete
def sort_attributes(attrs, object):
[303] Fix | Delete
'Sort the attrs list in-place by _fields and then alphabetically by name'
[304] Fix | Delete
# This allows data descriptors to be ordered according
[305] Fix | Delete
# to a _fields attribute if present.
[306] Fix | Delete
fields = getattr(object, '_fields', [])
[307] Fix | Delete
try:
[308] Fix | Delete
field_order = {name : i-len(fields) for (i, name) in enumerate(fields)}
[309] Fix | Delete
except TypeError:
[310] Fix | Delete
field_order = {}
[311] Fix | Delete
keyfunc = lambda attr: (field_order.get(attr[0], 0), attr[0])
[312] Fix | Delete
attrs.sort(key=keyfunc)
[313] Fix | Delete
[314] Fix | Delete
# ----------------------------------------------------- module manipulation
[315] Fix | Delete
[316] Fix | Delete
def ispackage(path):
[317] Fix | Delete
"""Guess whether a path refers to a package directory."""
[318] Fix | Delete
if os.path.isdir(path):
[319] Fix | Delete
for ext in ('.py', '.pyc'):
[320] Fix | Delete
if os.path.isfile(os.path.join(path, '__init__' + ext)):
[321] Fix | Delete
return True
[322] Fix | Delete
return False
[323] Fix | Delete
[324] Fix | Delete
def source_synopsis(file):
[325] Fix | Delete
line = file.readline()
[326] Fix | Delete
while line[:1] == '#' or not line.strip():
[327] Fix | Delete
line = file.readline()
[328] Fix | Delete
if not line: break
[329] Fix | Delete
line = line.strip()
[330] Fix | Delete
if line[:4] == 'r"""': line = line[1:]
[331] Fix | Delete
if line[:3] == '"""':
[332] Fix | Delete
line = line[3:]
[333] Fix | Delete
if line[-1:] == '\\': line = line[:-1]
[334] Fix | Delete
while not line.strip():
[335] Fix | Delete
line = file.readline()
[336] Fix | Delete
if not line: break
[337] Fix | Delete
result = line.split('"""')[0].strip()
[338] Fix | Delete
else: result = None
[339] Fix | Delete
return result
[340] Fix | Delete
[341] Fix | Delete
def synopsis(filename, cache={}):
[342] Fix | Delete
"""Get the one-line summary out of a module file."""
[343] Fix | Delete
mtime = os.stat(filename).st_mtime
[344] Fix | Delete
lastupdate, result = cache.get(filename, (None, None))
[345] Fix | Delete
if lastupdate is None or lastupdate < mtime:
[346] Fix | Delete
# Look for binary suffixes first, falling back to source.
[347] Fix | Delete
if filename.endswith(tuple(importlib.machinery.BYTECODE_SUFFIXES)):
[348] Fix | Delete
loader_cls = importlib.machinery.SourcelessFileLoader
[349] Fix | Delete
elif filename.endswith(tuple(importlib.machinery.EXTENSION_SUFFIXES)):
[350] Fix | Delete
loader_cls = importlib.machinery.ExtensionFileLoader
[351] Fix | Delete
else:
[352] Fix | Delete
loader_cls = None
[353] Fix | Delete
# Now handle the choice.
[354] Fix | Delete
if loader_cls is None:
[355] Fix | Delete
# Must be a source file.
[356] Fix | Delete
try:
[357] Fix | Delete
file = tokenize.open(filename)
[358] Fix | Delete
except OSError:
[359] Fix | Delete
# module can't be opened, so skip it
[360] Fix | Delete
return None
[361] Fix | Delete
# text modules can be directly examined
[362] Fix | Delete
with file:
[363] Fix | Delete
result = source_synopsis(file)
[364] Fix | Delete
else:
[365] Fix | Delete
# Must be a binary module, which has to be imported.
[366] Fix | Delete
loader = loader_cls('__temp__', filename)
[367] Fix | Delete
# XXX We probably don't need to pass in the loader here.
[368] Fix | Delete
spec = importlib.util.spec_from_file_location('__temp__', filename,
[369] Fix | Delete
loader=loader)
[370] Fix | Delete
try:
[371] Fix | Delete
module = importlib._bootstrap._load(spec)
[372] Fix | Delete
except:
[373] Fix | Delete
return None
[374] Fix | Delete
del sys.modules['__temp__']
[375] Fix | Delete
result = module.__doc__.splitlines()[0] if module.__doc__ else None
[376] Fix | Delete
# Cache the result.
[377] Fix | Delete
cache[filename] = (mtime, result)
[378] Fix | Delete
return result
[379] Fix | Delete
[380] Fix | Delete
class ErrorDuringImport(Exception):
[381] Fix | Delete
"""Errors that occurred while trying to import something to document it."""
[382] Fix | Delete
def __init__(self, filename, exc_info):
[383] Fix | Delete
self.filename = filename
[384] Fix | Delete
self.exc, self.value, self.tb = exc_info
[385] Fix | Delete
[386] Fix | Delete
def __str__(self):
[387] Fix | Delete
exc = self.exc.__name__
[388] Fix | Delete
return 'problem in %s - %s: %s' % (self.filename, exc, self.value)
[389] Fix | Delete
[390] Fix | Delete
def importfile(path):
[391] Fix | Delete
"""Import a Python source file or compiled file given its path."""
[392] Fix | Delete
magic = importlib.util.MAGIC_NUMBER
[393] Fix | Delete
with open(path, 'rb') as file:
[394] Fix | Delete
is_bytecode = magic == file.read(len(magic))
[395] Fix | Delete
filename = os.path.basename(path)
[396] Fix | Delete
name, ext = os.path.splitext(filename)
[397] Fix | Delete
if is_bytecode:
[398] Fix | Delete
loader = importlib._bootstrap_external.SourcelessFileLoader(name, path)
[399] Fix | Delete
else:
[400] Fix | Delete
loader = importlib._bootstrap_external.SourceFileLoader(name, path)
[401] Fix | Delete
# XXX We probably don't need to pass in the loader here.
[402] Fix | Delete
spec = importlib.util.spec_from_file_location(name, path, loader=loader)
[403] Fix | Delete
try:
[404] Fix | Delete
return importlib._bootstrap._load(spec)
[405] Fix | Delete
except:
[406] Fix | Delete
raise ErrorDuringImport(path, sys.exc_info())
[407] Fix | Delete
[408] Fix | Delete
def safeimport(path, forceload=0, cache={}):
[409] Fix | Delete
"""Import a module; handle errors; return None if the module isn't found.
[410] Fix | Delete
[411] Fix | Delete
If the module *is* found but an exception occurs, it's wrapped in an
[412] Fix | Delete
ErrorDuringImport exception and reraised. Unlike __import__, if a
[413] Fix | Delete
package path is specified, the module at the end of the path is returned,
[414] Fix | Delete
not the package at the beginning. If the optional 'forceload' argument
[415] Fix | Delete
is 1, we reload the module from disk (unless it's a dynamic extension)."""
[416] Fix | Delete
try:
[417] Fix | Delete
# If forceload is 1 and the module has been previously loaded from
[418] Fix | Delete
# disk, we always have to reload the module. Checking the file's
[419] Fix | Delete
# mtime isn't good enough (e.g. the module could contain a class
[420] Fix | Delete
# that inherits from another module that has changed).
[421] Fix | Delete
if forceload and path in sys.modules:
[422] Fix | Delete
if path not in sys.builtin_module_names:
[423] Fix | Delete
# Remove the module from sys.modules and re-import to try
[424] Fix | Delete
# and avoid problems with partially loaded modules.
[425] Fix | Delete
# Also remove any submodules because they won't appear
[426] Fix | Delete
# in the newly loaded module's namespace if they're already
[427] Fix | Delete
# in sys.modules.
[428] Fix | Delete
subs = [m for m in sys.modules if m.startswith(path + '.')]
[429] Fix | Delete
for key in [path] + subs:
[430] Fix | Delete
# Prevent garbage collection.
[431] Fix | Delete
cache[key] = sys.modules[key]
[432] Fix | Delete
del sys.modules[key]
[433] Fix | Delete
module = __import__(path)
[434] Fix | Delete
except:
[435] Fix | Delete
# Did the error occur before or after the module was found?
[436] Fix | Delete
(exc, value, tb) = info = sys.exc_info()
[437] Fix | Delete
if path in sys.modules:
[438] Fix | Delete
# An error occurred while executing the imported module.
[439] Fix | Delete
raise ErrorDuringImport(sys.modules[path].__file__, info)
[440] Fix | Delete
elif exc is SyntaxError:
[441] Fix | Delete
# A SyntaxError occurred before we could execute the module.
[442] Fix | Delete
raise ErrorDuringImport(value.filename, info)
[443] Fix | Delete
elif issubclass(exc, ImportError) and value.name == path:
[444] Fix | Delete
# No such module in the path.
[445] Fix | Delete
return None
[446] Fix | Delete
else:
[447] Fix | Delete
# Some other error occurred during the importing process.
[448] Fix | Delete
raise ErrorDuringImport(path, sys.exc_info())
[449] Fix | Delete
for part in path.split('.')[1:]:
[450] Fix | Delete
try: module = getattr(module, part)
[451] Fix | Delete
except AttributeError: return None
[452] Fix | Delete
return module
[453] Fix | Delete
[454] Fix | Delete
# ---------------------------------------------------- formatter base class
[455] Fix | Delete
[456] Fix | Delete
class Doc:
[457] Fix | Delete
[458] Fix | Delete
PYTHONDOCS = os.environ.get("PYTHONDOCS",
[459] Fix | Delete
"https://docs.python.org/%d.%d/library"
[460] Fix | Delete
% sys.version_info[:2])
[461] Fix | Delete
[462] Fix | Delete
def document(self, object, name=None, *args):
[463] Fix | Delete
"""Generate documentation for an object."""
[464] Fix | Delete
args = (object, name) + args
[465] Fix | Delete
# 'try' clause is to attempt to handle the possibility that inspect
[466] Fix | Delete
# identifies something in a way that pydoc itself has issues handling;
[467] Fix | Delete
# think 'super' and how it is a descriptor (which raises the exception
[468] Fix | Delete
# by lacking a __name__ attribute) and an instance.
[469] Fix | Delete
try:
[470] Fix | Delete
if inspect.ismodule(object): return self.docmodule(*args)
[471] Fix | Delete
if inspect.isclass(object): return self.docclass(*args)
[472] Fix | Delete
if inspect.isroutine(object): return self.docroutine(*args)
[473] Fix | Delete
except AttributeError:
[474] Fix | Delete
pass
[475] Fix | Delete
if inspect.isdatadescriptor(object): return self.docdata(*args)
[476] Fix | Delete
return self.docother(*args)
[477] Fix | Delete
[478] Fix | Delete
def fail(self, object, name=None, *args):
[479] Fix | Delete
"""Raise an exception for unimplemented types."""
[480] Fix | Delete
message = "don't know how to document object%s of type %s" % (
[481] Fix | Delete
name and ' ' + repr(name), type(object).__name__)
[482] Fix | Delete
raise TypeError(message)
[483] Fix | Delete
[484] Fix | Delete
docmodule = docclass = docroutine = docother = docproperty = docdata = fail
[485] Fix | Delete
[486] Fix | Delete
def getdocloc(self, object, basedir=sysconfig.get_path('stdlib')):
[487] Fix | Delete
"""Return the location of module docs or None"""
[488] Fix | Delete
[489] Fix | Delete
try:
[490] Fix | Delete
file = inspect.getabsfile(object)
[491] Fix | Delete
except TypeError:
[492] Fix | Delete
file = '(built-in)'
[493] Fix | Delete
[494] Fix | Delete
docloc = os.environ.get("PYTHONDOCS", self.PYTHONDOCS)
[495] Fix | Delete
[496] Fix | Delete
basedir = os.path.normcase(basedir)
[497] Fix | Delete
if (isinstance(object, type(os)) and
[498] Fix | Delete
(object.__name__ in ('errno', 'exceptions', 'gc', 'imp',
[499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function