Edit File by line
/home/barbar84/www/wp-conte.../plugins/sujqvwi/AnonR/smanonr..../lib64/python3....
File: pydoc.py
[1000] Fix | Delete
if name:
[1001] Fix | Delete
push('<dl><dt><strong>%s</strong></dt>\n' % name)
[1002] Fix | Delete
doc = self.markup(getdoc(object), self.preformat)
[1003] Fix | Delete
if doc:
[1004] Fix | Delete
push('<dd><tt>%s</tt></dd>\n' % doc)
[1005] Fix | Delete
push('</dl>\n')
[1006] Fix | Delete
[1007] Fix | Delete
return ''.join(results)
[1008] Fix | Delete
[1009] Fix | Delete
docproperty = docdata
[1010] Fix | Delete
[1011] Fix | Delete
def docother(self, object, name=None, mod=None, *ignored):
[1012] Fix | Delete
"""Produce HTML documentation for a data object."""
[1013] Fix | Delete
lhs = name and '<strong>%s</strong> = ' % name or ''
[1014] Fix | Delete
return lhs + self.repr(object)
[1015] Fix | Delete
[1016] Fix | Delete
def index(self, dir, shadowed=None):
[1017] Fix | Delete
"""Generate an HTML index for a directory of modules."""
[1018] Fix | Delete
modpkgs = []
[1019] Fix | Delete
if shadowed is None: shadowed = {}
[1020] Fix | Delete
for importer, name, ispkg in pkgutil.iter_modules([dir]):
[1021] Fix | Delete
if any((0xD800 <= ord(ch) <= 0xDFFF) for ch in name):
[1022] Fix | Delete
# ignore a module if its name contains a surrogate character
[1023] Fix | Delete
continue
[1024] Fix | Delete
modpkgs.append((name, '', ispkg, name in shadowed))
[1025] Fix | Delete
shadowed[name] = 1
[1026] Fix | Delete
[1027] Fix | Delete
modpkgs.sort()
[1028] Fix | Delete
contents = self.multicolumn(modpkgs, self.modpkglink)
[1029] Fix | Delete
return self.bigsection(dir, '#ffffff', '#ee77aa', contents)
[1030] Fix | Delete
[1031] Fix | Delete
# -------------------------------------------- text documentation generator
[1032] Fix | Delete
[1033] Fix | Delete
class TextRepr(Repr):
[1034] Fix | Delete
"""Class for safely making a text representation of a Python object."""
[1035] Fix | Delete
def __init__(self):
[1036] Fix | Delete
Repr.__init__(self)
[1037] Fix | Delete
self.maxlist = self.maxtuple = 20
[1038] Fix | Delete
self.maxdict = 10
[1039] Fix | Delete
self.maxstring = self.maxother = 100
[1040] Fix | Delete
[1041] Fix | Delete
def repr1(self, x, level):
[1042] Fix | Delete
if hasattr(type(x), '__name__'):
[1043] Fix | Delete
methodname = 'repr_' + '_'.join(type(x).__name__.split())
[1044] Fix | Delete
if hasattr(self, methodname):
[1045] Fix | Delete
return getattr(self, methodname)(x, level)
[1046] Fix | Delete
return cram(stripid(repr(x)), self.maxother)
[1047] Fix | Delete
[1048] Fix | Delete
def repr_string(self, x, level):
[1049] Fix | Delete
test = cram(x, self.maxstring)
[1050] Fix | Delete
testrepr = repr(test)
[1051] Fix | Delete
if '\\' in test and '\\' not in replace(testrepr, r'\\', ''):
[1052] Fix | Delete
# Backslashes are only literal in the string and are never
[1053] Fix | Delete
# needed to make any special characters, so show a raw string.
[1054] Fix | Delete
return 'r' + testrepr[0] + test + testrepr[0]
[1055] Fix | Delete
return testrepr
[1056] Fix | Delete
[1057] Fix | Delete
repr_str = repr_string
[1058] Fix | Delete
[1059] Fix | Delete
def repr_instance(self, x, level):
[1060] Fix | Delete
try:
[1061] Fix | Delete
return cram(stripid(repr(x)), self.maxstring)
[1062] Fix | Delete
except:
[1063] Fix | Delete
return '<%s instance>' % x.__class__.__name__
[1064] Fix | Delete
[1065] Fix | Delete
class TextDoc(Doc):
[1066] Fix | Delete
"""Formatter class for text documentation."""
[1067] Fix | Delete
[1068] Fix | Delete
# ------------------------------------------- text formatting utilities
[1069] Fix | Delete
[1070] Fix | Delete
_repr_instance = TextRepr()
[1071] Fix | Delete
repr = _repr_instance.repr
[1072] Fix | Delete
[1073] Fix | Delete
def bold(self, text):
[1074] Fix | Delete
"""Format a string in bold by overstriking."""
[1075] Fix | Delete
return ''.join(ch + '\b' + ch for ch in text)
[1076] Fix | Delete
[1077] Fix | Delete
def indent(self, text, prefix=' '):
[1078] Fix | Delete
"""Indent text by prepending a given prefix to each line."""
[1079] Fix | Delete
if not text: return ''
[1080] Fix | Delete
lines = [prefix + line for line in text.split('\n')]
[1081] Fix | Delete
if lines: lines[-1] = lines[-1].rstrip()
[1082] Fix | Delete
return '\n'.join(lines)
[1083] Fix | Delete
[1084] Fix | Delete
def section(self, title, contents):
[1085] Fix | Delete
"""Format a section with a given heading."""
[1086] Fix | Delete
clean_contents = self.indent(contents).rstrip()
[1087] Fix | Delete
return self.bold(title) + '\n' + clean_contents + '\n\n'
[1088] Fix | Delete
[1089] Fix | Delete
# ---------------------------------------------- type-specific routines
[1090] Fix | Delete
[1091] Fix | Delete
def formattree(self, tree, modname, parent=None, prefix=''):
[1092] Fix | Delete
"""Render in text a class tree as returned by inspect.getclasstree()."""
[1093] Fix | Delete
result = ''
[1094] Fix | Delete
for entry in tree:
[1095] Fix | Delete
if type(entry) is type(()):
[1096] Fix | Delete
c, bases = entry
[1097] Fix | Delete
result = result + prefix + classname(c, modname)
[1098] Fix | Delete
if bases and bases != (parent,):
[1099] Fix | Delete
parents = (classname(c, modname) for c in bases)
[1100] Fix | Delete
result = result + '(%s)' % ', '.join(parents)
[1101] Fix | Delete
result = result + '\n'
[1102] Fix | Delete
elif type(entry) is type([]):
[1103] Fix | Delete
result = result + self.formattree(
[1104] Fix | Delete
entry, modname, c, prefix + ' ')
[1105] Fix | Delete
return result
[1106] Fix | Delete
[1107] Fix | Delete
def docmodule(self, object, name=None, mod=None):
[1108] Fix | Delete
"""Produce text documentation for a given module object."""
[1109] Fix | Delete
name = object.__name__ # ignore the passed-in name
[1110] Fix | Delete
synop, desc = splitdoc(getdoc(object))
[1111] Fix | Delete
result = self.section('NAME', name + (synop and ' - ' + synop))
[1112] Fix | Delete
all = getattr(object, '__all__', None)
[1113] Fix | Delete
docloc = self.getdocloc(object)
[1114] Fix | Delete
if docloc is not None:
[1115] Fix | Delete
result = result + self.section('MODULE REFERENCE', docloc + """
[1116] Fix | Delete
[1117] Fix | Delete
The following documentation is automatically generated from the Python
[1118] Fix | Delete
source files. It may be incomplete, incorrect or include features that
[1119] Fix | Delete
are considered implementation detail and may vary between Python
[1120] Fix | Delete
implementations. When in doubt, consult the module reference at the
[1121] Fix | Delete
location listed above.
[1122] Fix | Delete
""")
[1123] Fix | Delete
[1124] Fix | Delete
if desc:
[1125] Fix | Delete
result = result + self.section('DESCRIPTION', desc)
[1126] Fix | Delete
[1127] Fix | Delete
classes = []
[1128] Fix | Delete
for key, value in inspect.getmembers(object, inspect.isclass):
[1129] Fix | Delete
# if __all__ exists, believe it. Otherwise use old heuristic.
[1130] Fix | Delete
if (all is not None
[1131] Fix | Delete
or (inspect.getmodule(value) or object) is object):
[1132] Fix | Delete
if visiblename(key, all, object):
[1133] Fix | Delete
classes.append((key, value))
[1134] Fix | Delete
funcs = []
[1135] Fix | Delete
for key, value in inspect.getmembers(object, inspect.isroutine):
[1136] Fix | Delete
# if __all__ exists, believe it. Otherwise use old heuristic.
[1137] Fix | Delete
if (all is not None or
[1138] Fix | Delete
inspect.isbuiltin(value) or inspect.getmodule(value) is object):
[1139] Fix | Delete
if visiblename(key, all, object):
[1140] Fix | Delete
funcs.append((key, value))
[1141] Fix | Delete
data = []
[1142] Fix | Delete
for key, value in inspect.getmembers(object, isdata):
[1143] Fix | Delete
if visiblename(key, all, object):
[1144] Fix | Delete
data.append((key, value))
[1145] Fix | Delete
[1146] Fix | Delete
modpkgs = []
[1147] Fix | Delete
modpkgs_names = set()
[1148] Fix | Delete
if hasattr(object, '__path__'):
[1149] Fix | Delete
for importer, modname, ispkg in pkgutil.iter_modules(object.__path__):
[1150] Fix | Delete
modpkgs_names.add(modname)
[1151] Fix | Delete
if ispkg:
[1152] Fix | Delete
modpkgs.append(modname + ' (package)')
[1153] Fix | Delete
else:
[1154] Fix | Delete
modpkgs.append(modname)
[1155] Fix | Delete
[1156] Fix | Delete
modpkgs.sort()
[1157] Fix | Delete
result = result + self.section(
[1158] Fix | Delete
'PACKAGE CONTENTS', '\n'.join(modpkgs))
[1159] Fix | Delete
[1160] Fix | Delete
# Detect submodules as sometimes created by C extensions
[1161] Fix | Delete
submodules = []
[1162] Fix | Delete
for key, value in inspect.getmembers(object, inspect.ismodule):
[1163] Fix | Delete
if value.__name__.startswith(name + '.') and key not in modpkgs_names:
[1164] Fix | Delete
submodules.append(key)
[1165] Fix | Delete
if submodules:
[1166] Fix | Delete
submodules.sort()
[1167] Fix | Delete
result = result + self.section(
[1168] Fix | Delete
'SUBMODULES', '\n'.join(submodules))
[1169] Fix | Delete
[1170] Fix | Delete
if classes:
[1171] Fix | Delete
classlist = [value for key, value in classes]
[1172] Fix | Delete
contents = [self.formattree(
[1173] Fix | Delete
inspect.getclasstree(classlist, 1), name)]
[1174] Fix | Delete
for key, value in classes:
[1175] Fix | Delete
contents.append(self.document(value, key, name))
[1176] Fix | Delete
result = result + self.section('CLASSES', '\n'.join(contents))
[1177] Fix | Delete
[1178] Fix | Delete
if funcs:
[1179] Fix | Delete
contents = []
[1180] Fix | Delete
for key, value in funcs:
[1181] Fix | Delete
contents.append(self.document(value, key, name))
[1182] Fix | Delete
result = result + self.section('FUNCTIONS', '\n'.join(contents))
[1183] Fix | Delete
[1184] Fix | Delete
if data:
[1185] Fix | Delete
contents = []
[1186] Fix | Delete
for key, value in data:
[1187] Fix | Delete
contents.append(self.docother(value, key, name, maxlen=70))
[1188] Fix | Delete
result = result + self.section('DATA', '\n'.join(contents))
[1189] Fix | Delete
[1190] Fix | Delete
if hasattr(object, '__version__'):
[1191] Fix | Delete
version = str(object.__version__)
[1192] Fix | Delete
if version[:11] == '$' + 'Revision: ' and version[-1:] == '$':
[1193] Fix | Delete
version = version[11:-1].strip()
[1194] Fix | Delete
result = result + self.section('VERSION', version)
[1195] Fix | Delete
if hasattr(object, '__date__'):
[1196] Fix | Delete
result = result + self.section('DATE', str(object.__date__))
[1197] Fix | Delete
if hasattr(object, '__author__'):
[1198] Fix | Delete
result = result + self.section('AUTHOR', str(object.__author__))
[1199] Fix | Delete
if hasattr(object, '__credits__'):
[1200] Fix | Delete
result = result + self.section('CREDITS', str(object.__credits__))
[1201] Fix | Delete
try:
[1202] Fix | Delete
file = inspect.getabsfile(object)
[1203] Fix | Delete
except TypeError:
[1204] Fix | Delete
file = '(built-in)'
[1205] Fix | Delete
result = result + self.section('FILE', file)
[1206] Fix | Delete
return result
[1207] Fix | Delete
[1208] Fix | Delete
def docclass(self, object, name=None, mod=None, *ignored):
[1209] Fix | Delete
"""Produce text documentation for a given class object."""
[1210] Fix | Delete
realname = object.__name__
[1211] Fix | Delete
name = name or realname
[1212] Fix | Delete
bases = object.__bases__
[1213] Fix | Delete
[1214] Fix | Delete
def makename(c, m=object.__module__):
[1215] Fix | Delete
return classname(c, m)
[1216] Fix | Delete
[1217] Fix | Delete
if name == realname:
[1218] Fix | Delete
title = 'class ' + self.bold(realname)
[1219] Fix | Delete
else:
[1220] Fix | Delete
title = self.bold(name) + ' = class ' + realname
[1221] Fix | Delete
if bases:
[1222] Fix | Delete
parents = map(makename, bases)
[1223] Fix | Delete
title = title + '(%s)' % ', '.join(parents)
[1224] Fix | Delete
[1225] Fix | Delete
contents = []
[1226] Fix | Delete
push = contents.append
[1227] Fix | Delete
[1228] Fix | Delete
try:
[1229] Fix | Delete
signature = inspect.signature(object)
[1230] Fix | Delete
except (ValueError, TypeError):
[1231] Fix | Delete
signature = None
[1232] Fix | Delete
if signature:
[1233] Fix | Delete
argspec = str(signature)
[1234] Fix | Delete
if argspec and argspec != '()':
[1235] Fix | Delete
push(name + argspec + '\n')
[1236] Fix | Delete
[1237] Fix | Delete
doc = getdoc(object)
[1238] Fix | Delete
if doc:
[1239] Fix | Delete
push(doc + '\n')
[1240] Fix | Delete
[1241] Fix | Delete
# List the mro, if non-trivial.
[1242] Fix | Delete
mro = deque(inspect.getmro(object))
[1243] Fix | Delete
if len(mro) > 2:
[1244] Fix | Delete
push("Method resolution order:")
[1245] Fix | Delete
for base in mro:
[1246] Fix | Delete
push(' ' + makename(base))
[1247] Fix | Delete
push('')
[1248] Fix | Delete
[1249] Fix | Delete
# List the built-in subclasses, if any:
[1250] Fix | Delete
subclasses = sorted(
[1251] Fix | Delete
(str(cls.__name__) for cls in type.__subclasses__(object)
[1252] Fix | Delete
if not cls.__name__.startswith("_") and cls.__module__ == "builtins"),
[1253] Fix | Delete
key=str.lower
[1254] Fix | Delete
)
[1255] Fix | Delete
no_of_subclasses = len(subclasses)
[1256] Fix | Delete
MAX_SUBCLASSES_TO_DISPLAY = 4
[1257] Fix | Delete
if subclasses:
[1258] Fix | Delete
push("Built-in subclasses:")
[1259] Fix | Delete
for subclassname in subclasses[:MAX_SUBCLASSES_TO_DISPLAY]:
[1260] Fix | Delete
push(' ' + subclassname)
[1261] Fix | Delete
if no_of_subclasses > MAX_SUBCLASSES_TO_DISPLAY:
[1262] Fix | Delete
push(' ... and ' +
[1263] Fix | Delete
str(no_of_subclasses - MAX_SUBCLASSES_TO_DISPLAY) +
[1264] Fix | Delete
' other subclasses')
[1265] Fix | Delete
push('')
[1266] Fix | Delete
[1267] Fix | Delete
# Cute little class to pump out a horizontal rule between sections.
[1268] Fix | Delete
class HorizontalRule:
[1269] Fix | Delete
def __init__(self):
[1270] Fix | Delete
self.needone = 0
[1271] Fix | Delete
def maybe(self):
[1272] Fix | Delete
if self.needone:
[1273] Fix | Delete
push('-' * 70)
[1274] Fix | Delete
self.needone = 1
[1275] Fix | Delete
hr = HorizontalRule()
[1276] Fix | Delete
[1277] Fix | Delete
def spill(msg, attrs, predicate):
[1278] Fix | Delete
ok, attrs = _split_list(attrs, predicate)
[1279] Fix | Delete
if ok:
[1280] Fix | Delete
hr.maybe()
[1281] Fix | Delete
push(msg)
[1282] Fix | Delete
for name, kind, homecls, value in ok:
[1283] Fix | Delete
try:
[1284] Fix | Delete
value = getattr(object, name)
[1285] Fix | Delete
except Exception:
[1286] Fix | Delete
# Some descriptors may meet a failure in their __get__.
[1287] Fix | Delete
# (bug #1785)
[1288] Fix | Delete
push(self.docdata(value, name, mod))
[1289] Fix | Delete
else:
[1290] Fix | Delete
push(self.document(value,
[1291] Fix | Delete
name, mod, object))
[1292] Fix | Delete
return attrs
[1293] Fix | Delete
[1294] Fix | Delete
def spilldescriptors(msg, attrs, predicate):
[1295] Fix | Delete
ok, attrs = _split_list(attrs, predicate)
[1296] Fix | Delete
if ok:
[1297] Fix | Delete
hr.maybe()
[1298] Fix | Delete
push(msg)
[1299] Fix | Delete
for name, kind, homecls, value in ok:
[1300] Fix | Delete
push(self.docdata(value, name, mod))
[1301] Fix | Delete
return attrs
[1302] Fix | Delete
[1303] Fix | Delete
def spilldata(msg, attrs, predicate):
[1304] Fix | Delete
ok, attrs = _split_list(attrs, predicate)
[1305] Fix | Delete
if ok:
[1306] Fix | Delete
hr.maybe()
[1307] Fix | Delete
push(msg)
[1308] Fix | Delete
for name, kind, homecls, value in ok:
[1309] Fix | Delete
if callable(value) or inspect.isdatadescriptor(value):
[1310] Fix | Delete
doc = getdoc(value)
[1311] Fix | Delete
else:
[1312] Fix | Delete
doc = None
[1313] Fix | Delete
try:
[1314] Fix | Delete
obj = getattr(object, name)
[1315] Fix | Delete
except AttributeError:
[1316] Fix | Delete
obj = homecls.__dict__[name]
[1317] Fix | Delete
push(self.docother(obj, name, mod, maxlen=70, doc=doc) +
[1318] Fix | Delete
'\n')
[1319] Fix | Delete
return attrs
[1320] Fix | Delete
[1321] Fix | Delete
attrs = [(name, kind, cls, value)
[1322] Fix | Delete
for name, kind, cls, value in classify_class_attrs(object)
[1323] Fix | Delete
if visiblename(name, obj=object)]
[1324] Fix | Delete
[1325] Fix | Delete
while attrs:
[1326] Fix | Delete
if mro:
[1327] Fix | Delete
thisclass = mro.popleft()
[1328] Fix | Delete
else:
[1329] Fix | Delete
thisclass = attrs[0][2]
[1330] Fix | Delete
attrs, inherited = _split_list(attrs, lambda t: t[2] is thisclass)
[1331] Fix | Delete
[1332] Fix | Delete
if object is not builtins.object and thisclass is builtins.object:
[1333] Fix | Delete
attrs = inherited
[1334] Fix | Delete
continue
[1335] Fix | Delete
elif thisclass is object:
[1336] Fix | Delete
tag = "defined here"
[1337] Fix | Delete
else:
[1338] Fix | Delete
tag = "inherited from %s" % classname(thisclass,
[1339] Fix | Delete
object.__module__)
[1340] Fix | Delete
[1341] Fix | Delete
sort_attributes(attrs, object)
[1342] Fix | Delete
[1343] Fix | Delete
# Pump out the attrs, segregated by kind.
[1344] Fix | Delete
attrs = spill("Methods %s:\n" % tag, attrs,
[1345] Fix | Delete
lambda t: t[1] == 'method')
[1346] Fix | Delete
attrs = spill("Class methods %s:\n" % tag, attrs,
[1347] Fix | Delete
lambda t: t[1] == 'class method')
[1348] Fix | Delete
attrs = spill("Static methods %s:\n" % tag, attrs,
[1349] Fix | Delete
lambda t: t[1] == 'static method')
[1350] Fix | Delete
attrs = spilldescriptors("Readonly properties %s:\n" % tag, attrs,
[1351] Fix | Delete
lambda t: t[1] == 'readonly property')
[1352] Fix | Delete
attrs = spilldescriptors("Data descriptors %s:\n" % tag, attrs,
[1353] Fix | Delete
lambda t: t[1] == 'data descriptor')
[1354] Fix | Delete
attrs = spilldata("Data and other attributes %s:\n" % tag, attrs,
[1355] Fix | Delete
lambda t: t[1] == 'data')
[1356] Fix | Delete
[1357] Fix | Delete
assert attrs == []
[1358] Fix | Delete
attrs = inherited
[1359] Fix | Delete
[1360] Fix | Delete
contents = '\n'.join(contents)
[1361] Fix | Delete
if not contents:
[1362] Fix | Delete
return title + '\n'
[1363] Fix | Delete
return title + '\n' + self.indent(contents.rstrip(), ' | ') + '\n'
[1364] Fix | Delete
[1365] Fix | Delete
def formatvalue(self, object):
[1366] Fix | Delete
"""Format an argument default value as text."""
[1367] Fix | Delete
return '=' + self.repr(object)
[1368] Fix | Delete
[1369] Fix | Delete
def docroutine(self, object, name=None, mod=None, cl=None):
[1370] Fix | Delete
"""Produce text documentation for a function or method object."""
[1371] Fix | Delete
realname = object.__name__
[1372] Fix | Delete
name = name or realname
[1373] Fix | Delete
note = ''
[1374] Fix | Delete
skipdocs = 0
[1375] Fix | Delete
if _is_bound_method(object):
[1376] Fix | Delete
imclass = object.__self__.__class__
[1377] Fix | Delete
if cl:
[1378] Fix | Delete
if imclass is not cl:
[1379] Fix | Delete
note = ' from ' + classname(imclass, mod)
[1380] Fix | Delete
else:
[1381] Fix | Delete
if object.__self__ is not None:
[1382] Fix | Delete
note = ' method of %s instance' % classname(
[1383] Fix | Delete
object.__self__.__class__, mod)
[1384] Fix | Delete
else:
[1385] Fix | Delete
note = ' unbound %s method' % classname(imclass,mod)
[1386] Fix | Delete
[1387] Fix | Delete
if (inspect.iscoroutinefunction(object) or
[1388] Fix | Delete
inspect.isasyncgenfunction(object)):
[1389] Fix | Delete
asyncqualifier = 'async '
[1390] Fix | Delete
else:
[1391] Fix | Delete
asyncqualifier = ''
[1392] Fix | Delete
[1393] Fix | Delete
if name == realname:
[1394] Fix | Delete
title = self.bold(realname)
[1395] Fix | Delete
else:
[1396] Fix | Delete
if cl and inspect.getattr_static(cl, realname, []) is object:
[1397] Fix | Delete
skipdocs = 1
[1398] Fix | Delete
title = self.bold(name) + ' = ' + realname
[1399] Fix | Delete
argspec = None
[1400] Fix | Delete
[1401] Fix | Delete
if inspect.isroutine(object):
[1402] Fix | Delete
try:
[1403] Fix | Delete
signature = inspect.signature(object)
[1404] Fix | Delete
except (ValueError, TypeError):
[1405] Fix | Delete
signature = None
[1406] Fix | Delete
if signature:
[1407] Fix | Delete
argspec = str(signature)
[1408] Fix | Delete
if realname == '<lambda>':
[1409] Fix | Delete
title = self.bold(name) + ' lambda '
[1410] Fix | Delete
# XXX lambda's won't usually have func_annotations['return']
[1411] Fix | Delete
# since the syntax doesn't support but it is possible.
[1412] Fix | Delete
# So removing parentheses isn't truly safe.
[1413] Fix | Delete
argspec = argspec[1:-1] # remove parentheses
[1414] Fix | Delete
if not argspec:
[1415] Fix | Delete
argspec = '(...)'
[1416] Fix | Delete
decl = asyncqualifier + title + argspec + note
[1417] Fix | Delete
[1418] Fix | Delete
if skipdocs:
[1419] Fix | Delete
return decl + '\n'
[1420] Fix | Delete
else:
[1421] Fix | Delete
doc = getdoc(object) or ''
[1422] Fix | Delete
return decl + '\n' + (doc and self.indent(doc).rstrip() + '\n')
[1423] Fix | Delete
[1424] Fix | Delete
def docdata(self, object, name=None, mod=None, cl=None):
[1425] Fix | Delete
"""Produce text documentation for a data descriptor."""
[1426] Fix | Delete
results = []
[1427] Fix | Delete
push = results.append
[1428] Fix | Delete
[1429] Fix | Delete
if name:
[1430] Fix | Delete
push(self.bold(name))
[1431] Fix | Delete
push('\n')
[1432] Fix | Delete
doc = getdoc(object) or ''
[1433] Fix | Delete
if doc:
[1434] Fix | Delete
push(self.indent(doc))
[1435] Fix | Delete
push('\n')
[1436] Fix | Delete
return ''.join(results)
[1437] Fix | Delete
[1438] Fix | Delete
docproperty = docdata
[1439] Fix | Delete
[1440] Fix | Delete
def docother(self, object, name=None, mod=None, parent=None, maxlen=None, doc=None):
[1441] Fix | Delete
"""Produce text documentation for a data object."""
[1442] Fix | Delete
repr = self.repr(object)
[1443] Fix | Delete
if maxlen:
[1444] Fix | Delete
line = (name and name + ' = ' or '') + repr
[1445] Fix | Delete
chop = maxlen - len(line)
[1446] Fix | Delete
if chop < 0: repr = repr[:chop] + '...'
[1447] Fix | Delete
line = (name and self.bold(name) + ' = ' or '') + repr
[1448] Fix | Delete
if doc is not None:
[1449] Fix | Delete
line += '\n' + self.indent(str(doc))
[1450] Fix | Delete
return line
[1451] Fix | Delete
[1452] Fix | Delete
class _PlainTextDoc(TextDoc):
[1453] Fix | Delete
"""Subclass of TextDoc which overrides string styling"""
[1454] Fix | Delete
def bold(self, text):
[1455] Fix | Delete
return text
[1456] Fix | Delete
[1457] Fix | Delete
# --------------------------------------------------------- user interfaces
[1458] Fix | Delete
[1459] Fix | Delete
def pager(text):
[1460] Fix | Delete
"""The first time this is called, determine what kind of pager to use."""
[1461] Fix | Delete
global pager
[1462] Fix | Delete
pager = getpager()
[1463] Fix | Delete
pager(text)
[1464] Fix | Delete
[1465] Fix | Delete
def getpager():
[1466] Fix | Delete
"""Decide what method to use for paging through text."""
[1467] Fix | Delete
if not hasattr(sys.stdin, "isatty"):
[1468] Fix | Delete
return plainpager
[1469] Fix | Delete
if not hasattr(sys.stdout, "isatty"):
[1470] Fix | Delete
return plainpager
[1471] Fix | Delete
if not sys.stdin.isatty() or not sys.stdout.isatty():
[1472] Fix | Delete
return plainpager
[1473] Fix | Delete
use_pager = os.environ.get('MANPAGER') or os.environ.get('PAGER')
[1474] Fix | Delete
if use_pager:
[1475] Fix | Delete
if sys.platform == 'win32': # pipes completely broken in Windows
[1476] Fix | Delete
return lambda text: tempfilepager(plain(text), use_pager)
[1477] Fix | Delete
elif os.environ.get('TERM') in ('dumb', 'emacs'):
[1478] Fix | Delete
return lambda text: pipepager(plain(text), use_pager)
[1479] Fix | Delete
else:
[1480] Fix | Delete
return lambda text: pipepager(text, use_pager)
[1481] Fix | Delete
if os.environ.get('TERM') in ('dumb', 'emacs'):
[1482] Fix | Delete
return plainpager
[1483] Fix | Delete
if sys.platform == 'win32':
[1484] Fix | Delete
return lambda text: tempfilepager(plain(text), 'more <')
[1485] Fix | Delete
if hasattr(os, 'system') and os.system('(less) 2>/dev/null') == 0:
[1486] Fix | Delete
return lambda text: pipepager(text, 'less')
[1487] Fix | Delete
[1488] Fix | Delete
import tempfile
[1489] Fix | Delete
(fd, filename) = tempfile.mkstemp()
[1490] Fix | Delete
os.close(fd)
[1491] Fix | Delete
try:
[1492] Fix | Delete
if hasattr(os, 'system') and os.system('more "%s"' % filename) == 0:
[1493] Fix | Delete
return lambda text: pipepager(text, 'more')
[1494] Fix | Delete
else:
[1495] Fix | Delete
return ttypager
[1496] Fix | Delete
finally:
[1497] Fix | Delete
os.unlink(filename)
[1498] Fix | Delete
[1499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function