Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/ExeBy/smexe_ro.../lib64/python2....
File: pydoc.py
#! /usr/bin/python2.7
[0] Fix | Delete
# -*- coding: latin-1 -*-
[1] Fix | Delete
"""Generate Python documentation in HTML or text for interactive use.
[2] Fix | Delete
[3] Fix | Delete
In the Python interpreter, do "from pydoc import help" to provide online
[4] Fix | Delete
help. Calling help(thing) on a Python object documents the object.
[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 -p <port>" to start an HTTP server on a given port on the
[18] Fix | Delete
local machine to generate documentation web pages. Port number 0 can be
[19] Fix | Delete
used to get an arbitrary unused port.
[20] Fix | Delete
[21] Fix | Delete
Run "pydoc -w <name>" to write out the HTML documentation for a module
[22] Fix | Delete
to a file named "<name>.html".
[23] Fix | Delete
[24] Fix | Delete
Module docs for core modules are assumed to be in
[25] Fix | Delete
[26] Fix | Delete
https://docs.python.org/library/
[27] Fix | Delete
[28] Fix | Delete
This can be overridden by setting the PYTHONDOCS environment variable
[29] Fix | Delete
to a different URL or to a local directory containing the Library
[30] Fix | Delete
Reference Manual pages.
[31] Fix | Delete
"""
[32] Fix | Delete
[33] Fix | Delete
__author__ = "Ka-Ping Yee <ping@lfw.org>"
[34] Fix | Delete
__date__ = "26 February 2001"
[35] Fix | Delete
[36] Fix | Delete
__version__ = "$Revision: 88564 $"
[37] Fix | Delete
__credits__ = """Guido van Rossum, for an excellent programming language.
[38] Fix | Delete
Tommy Burnette, the original creator of manpy.
[39] Fix | Delete
Paul Prescod, for all his work on onlinehelp.
[40] Fix | Delete
Richard Chamberlain, for the first implementation of textdoc.
[41] Fix | Delete
"""
[42] Fix | Delete
[43] Fix | Delete
# Known bugs that can't be fixed here:
[44] Fix | Delete
# - imp.load_module() cannot be prevented from clobbering existing
[45] Fix | Delete
# loaded modules, so calling synopsis() on a binary module file
[46] Fix | Delete
# changes the contents of any existing module with the same name.
[47] Fix | Delete
# - If the __file__ attribute on a module is a relative path and
[48] Fix | Delete
# the current directory is changed with os.chdir(), an incorrect
[49] Fix | Delete
# path will be displayed.
[50] Fix | Delete
[51] Fix | Delete
import sys, imp, os, re, types, inspect, __builtin__, pkgutil, warnings
[52] Fix | Delete
from repr import Repr
[53] Fix | Delete
from string import expandtabs, find, join, lower, split, strip, rfind, rstrip
[54] Fix | Delete
from traceback import extract_tb
[55] Fix | Delete
try:
[56] Fix | Delete
from collections import deque
[57] Fix | Delete
except ImportError:
[58] Fix | Delete
# Python 2.3 compatibility
[59] Fix | Delete
class deque(list):
[60] Fix | Delete
def popleft(self):
[61] Fix | Delete
return self.pop(0)
[62] Fix | Delete
[63] Fix | Delete
# --------------------------------------------------------- common routines
[64] Fix | Delete
[65] Fix | Delete
def pathdirs():
[66] Fix | Delete
"""Convert sys.path into a list of absolute, existing, unique paths."""
[67] Fix | Delete
dirs = []
[68] Fix | Delete
normdirs = []
[69] Fix | Delete
for dir in sys.path:
[70] Fix | Delete
dir = os.path.abspath(dir or '.')
[71] Fix | Delete
normdir = os.path.normcase(dir)
[72] Fix | Delete
if normdir not in normdirs and os.path.isdir(dir):
[73] Fix | Delete
dirs.append(dir)
[74] Fix | Delete
normdirs.append(normdir)
[75] Fix | Delete
return dirs
[76] Fix | Delete
[77] Fix | Delete
def getdoc(object):
[78] Fix | Delete
"""Get the doc string or comments for an object."""
[79] Fix | Delete
result = inspect.getdoc(object) or inspect.getcomments(object)
[80] Fix | Delete
result = _encode(result)
[81] Fix | Delete
return result and re.sub('^ *\n', '', rstrip(result)) or ''
[82] Fix | Delete
[83] Fix | Delete
def splitdoc(doc):
[84] Fix | Delete
"""Split a doc string into a synopsis line (if any) and the rest."""
[85] Fix | Delete
lines = split(strip(doc), '\n')
[86] Fix | Delete
if len(lines) == 1:
[87] Fix | Delete
return lines[0], ''
[88] Fix | Delete
elif len(lines) >= 2 and not rstrip(lines[1]):
[89] Fix | Delete
return lines[0], join(lines[2:], '\n')
[90] Fix | Delete
return '', join(lines, '\n')
[91] Fix | Delete
[92] Fix | Delete
def classname(object, modname):
[93] Fix | Delete
"""Get a class name and qualify it with a module name if necessary."""
[94] Fix | Delete
name = object.__name__
[95] Fix | Delete
if object.__module__ != modname:
[96] Fix | Delete
name = object.__module__ + '.' + name
[97] Fix | Delete
return name
[98] Fix | Delete
[99] Fix | Delete
def isdata(object):
[100] Fix | Delete
"""Check if an object is of a type that probably means it's data."""
[101] Fix | Delete
return not (inspect.ismodule(object) or inspect.isclass(object) or
[102] Fix | Delete
inspect.isroutine(object) or inspect.isframe(object) or
[103] Fix | Delete
inspect.istraceback(object) or inspect.iscode(object))
[104] Fix | Delete
[105] Fix | Delete
def replace(text, *pairs):
[106] Fix | Delete
"""Do a series of global replacements on a string."""
[107] Fix | Delete
while pairs:
[108] Fix | Delete
text = join(split(text, pairs[0]), pairs[1])
[109] Fix | Delete
pairs = pairs[2:]
[110] Fix | Delete
return text
[111] Fix | Delete
[112] Fix | Delete
def cram(text, maxlen):
[113] Fix | Delete
"""Omit part of a string if needed to make it fit in a maximum length."""
[114] Fix | Delete
if len(text) > maxlen:
[115] Fix | Delete
pre = max(0, (maxlen-3)//2)
[116] Fix | Delete
post = max(0, maxlen-3-pre)
[117] Fix | Delete
return text[:pre] + '...' + text[len(text)-post:]
[118] Fix | Delete
return text
[119] Fix | Delete
[120] Fix | Delete
_re_stripid = re.compile(r' at 0x[0-9a-f]{6,16}(>+)$', re.IGNORECASE)
[121] Fix | Delete
def stripid(text):
[122] Fix | Delete
"""Remove the hexadecimal id from a Python object representation."""
[123] Fix | Delete
# The behaviour of %p is implementation-dependent in terms of case.
[124] Fix | Delete
return _re_stripid.sub(r'\1', text)
[125] Fix | Delete
[126] Fix | Delete
def _is_some_method(obj):
[127] Fix | Delete
return inspect.ismethod(obj) or inspect.ismethoddescriptor(obj)
[128] Fix | Delete
[129] Fix | Delete
def allmethods(cl):
[130] Fix | Delete
methods = {}
[131] Fix | Delete
for key, value in inspect.getmembers(cl, _is_some_method):
[132] Fix | Delete
methods[key] = 1
[133] Fix | Delete
for base in cl.__bases__:
[134] Fix | Delete
methods.update(allmethods(base)) # all your base are belong to us
[135] Fix | Delete
for key in methods.keys():
[136] Fix | Delete
methods[key] = getattr(cl, key)
[137] Fix | Delete
return methods
[138] Fix | Delete
[139] Fix | Delete
def _split_list(s, predicate):
[140] Fix | Delete
"""Split sequence s via predicate, and return pair ([true], [false]).
[141] Fix | Delete
[142] Fix | Delete
The return value is a 2-tuple of lists,
[143] Fix | Delete
([x for x in s if predicate(x)],
[144] Fix | Delete
[x for x in s if not predicate(x)])
[145] Fix | Delete
"""
[146] Fix | Delete
[147] Fix | Delete
yes = []
[148] Fix | Delete
no = []
[149] Fix | Delete
for x in s:
[150] Fix | Delete
if predicate(x):
[151] Fix | Delete
yes.append(x)
[152] Fix | Delete
else:
[153] Fix | Delete
no.append(x)
[154] Fix | Delete
return yes, no
[155] Fix | Delete
[156] Fix | Delete
def visiblename(name, all=None, obj=None):
[157] Fix | Delete
"""Decide whether to show documentation on a variable."""
[158] Fix | Delete
# Certain special names are redundant.
[159] Fix | Delete
_hidden_names = ('__builtins__', '__doc__', '__file__', '__path__',
[160] Fix | Delete
'__module__', '__name__', '__slots__', '__package__')
[161] Fix | Delete
if name in _hidden_names: return 0
[162] Fix | Delete
# Private names are hidden, but special names are displayed.
[163] Fix | Delete
if name.startswith('__') and name.endswith('__'): return 1
[164] Fix | Delete
# Namedtuples have public fields and methods with a single leading underscore
[165] Fix | Delete
if name.startswith('_') and hasattr(obj, '_fields'):
[166] Fix | Delete
return 1
[167] Fix | Delete
if all is not None:
[168] Fix | Delete
# only document that which the programmer exported in __all__
[169] Fix | Delete
return name in all
[170] Fix | Delete
else:
[171] Fix | Delete
return not name.startswith('_')
[172] Fix | Delete
[173] Fix | Delete
def classify_class_attrs(object):
[174] Fix | Delete
"""Wrap inspect.classify_class_attrs, with fixup for data descriptors."""
[175] Fix | Delete
def fixup(data):
[176] Fix | Delete
name, kind, cls, value = data
[177] Fix | Delete
if inspect.isdatadescriptor(value):
[178] Fix | Delete
kind = 'data descriptor'
[179] Fix | Delete
return name, kind, cls, value
[180] Fix | Delete
return map(fixup, inspect.classify_class_attrs(object))
[181] Fix | Delete
[182] Fix | Delete
# ----------------------------------------------------- Unicode support helpers
[183] Fix | Delete
[184] Fix | Delete
try:
[185] Fix | Delete
_unicode = unicode
[186] Fix | Delete
except NameError:
[187] Fix | Delete
# If Python is built without Unicode support, the unicode type
[188] Fix | Delete
# will not exist. Fake one that nothing will match, and make
[189] Fix | Delete
# the _encode function that do nothing.
[190] Fix | Delete
class _unicode(object):
[191] Fix | Delete
pass
[192] Fix | Delete
_encoding = 'ascii'
[193] Fix | Delete
def _encode(text, encoding='ascii'):
[194] Fix | Delete
return text
[195] Fix | Delete
else:
[196] Fix | Delete
import locale
[197] Fix | Delete
_encoding = locale.getpreferredencoding()
[198] Fix | Delete
[199] Fix | Delete
def _encode(text, encoding=None):
[200] Fix | Delete
if isinstance(text, unicode):
[201] Fix | Delete
return text.encode(encoding or _encoding, 'xmlcharrefreplace')
[202] Fix | Delete
else:
[203] Fix | Delete
return text
[204] Fix | Delete
[205] Fix | Delete
def _binstr(obj):
[206] Fix | Delete
# Ensure that we have an encoded (binary) string representation of obj,
[207] Fix | Delete
# even if it is a unicode string.
[208] Fix | Delete
if isinstance(obj, _unicode):
[209] Fix | Delete
return obj.encode(_encoding, 'xmlcharrefreplace')
[210] Fix | Delete
return str(obj)
[211] Fix | Delete
[212] Fix | Delete
# ----------------------------------------------------- module manipulation
[213] Fix | Delete
[214] Fix | Delete
def ispackage(path):
[215] Fix | Delete
"""Guess whether a path refers to a package directory."""
[216] Fix | Delete
if os.path.isdir(path):
[217] Fix | Delete
for ext in ('.py', '.pyc', '.pyo'):
[218] Fix | Delete
if os.path.isfile(os.path.join(path, '__init__' + ext)):
[219] Fix | Delete
return True
[220] Fix | Delete
return False
[221] Fix | Delete
[222] Fix | Delete
def source_synopsis(file):
[223] Fix | Delete
line = file.readline()
[224] Fix | Delete
while line[:1] == '#' or not strip(line):
[225] Fix | Delete
line = file.readline()
[226] Fix | Delete
if not line: break
[227] Fix | Delete
line = strip(line)
[228] Fix | Delete
if line[:4] == 'r"""': line = line[1:]
[229] Fix | Delete
if line[:3] == '"""':
[230] Fix | Delete
line = line[3:]
[231] Fix | Delete
if line[-1:] == '\\': line = line[:-1]
[232] Fix | Delete
while not strip(line):
[233] Fix | Delete
line = file.readline()
[234] Fix | Delete
if not line: break
[235] Fix | Delete
result = strip(split(line, '"""')[0])
[236] Fix | Delete
else: result = None
[237] Fix | Delete
return result
[238] Fix | Delete
[239] Fix | Delete
def synopsis(filename, cache={}):
[240] Fix | Delete
"""Get the one-line summary out of a module file."""
[241] Fix | Delete
mtime = os.stat(filename).st_mtime
[242] Fix | Delete
lastupdate, result = cache.get(filename, (None, None))
[243] Fix | Delete
if lastupdate is None or lastupdate < mtime:
[244] Fix | Delete
info = inspect.getmoduleinfo(filename)
[245] Fix | Delete
try:
[246] Fix | Delete
file = open(filename)
[247] Fix | Delete
except IOError:
[248] Fix | Delete
# module can't be opened, so skip it
[249] Fix | Delete
return None
[250] Fix | Delete
if info and 'b' in info[2]: # binary modules have to be imported
[251] Fix | Delete
try: module = imp.load_module('__temp__', file, filename, info[1:])
[252] Fix | Delete
except: return None
[253] Fix | Delete
result = module.__doc__.splitlines()[0] if module.__doc__ else None
[254] Fix | Delete
del sys.modules['__temp__']
[255] Fix | Delete
else: # text modules can be directly examined
[256] Fix | Delete
result = source_synopsis(file)
[257] Fix | Delete
file.close()
[258] Fix | Delete
cache[filename] = (mtime, result)
[259] Fix | Delete
return result
[260] Fix | Delete
[261] Fix | Delete
class ErrorDuringImport(Exception):
[262] Fix | Delete
"""Errors that occurred while trying to import something to document it."""
[263] Fix | Delete
def __init__(self, filename, exc_info):
[264] Fix | Delete
exc, value, tb = exc_info
[265] Fix | Delete
self.filename = filename
[266] Fix | Delete
self.exc = exc
[267] Fix | Delete
self.value = value
[268] Fix | Delete
self.tb = tb
[269] Fix | Delete
[270] Fix | Delete
def __str__(self):
[271] Fix | Delete
exc = self.exc
[272] Fix | Delete
if type(exc) is types.ClassType:
[273] Fix | Delete
exc = exc.__name__
[274] Fix | Delete
return 'problem in %s - %s: %s' % (self.filename, exc, self.value)
[275] Fix | Delete
[276] Fix | Delete
def importfile(path):
[277] Fix | Delete
"""Import a Python source file or compiled file given its path."""
[278] Fix | Delete
magic = imp.get_magic()
[279] Fix | Delete
file = open(path, 'r')
[280] Fix | Delete
if file.read(len(magic)) == magic:
[281] Fix | Delete
kind = imp.PY_COMPILED
[282] Fix | Delete
else:
[283] Fix | Delete
kind = imp.PY_SOURCE
[284] Fix | Delete
file.close()
[285] Fix | Delete
filename = os.path.basename(path)
[286] Fix | Delete
name, ext = os.path.splitext(filename)
[287] Fix | Delete
file = open(path, 'r')
[288] Fix | Delete
try:
[289] Fix | Delete
module = imp.load_module(name, file, path, (ext, 'r', kind))
[290] Fix | Delete
except:
[291] Fix | Delete
raise ErrorDuringImport(path, sys.exc_info())
[292] Fix | Delete
file.close()
[293] Fix | Delete
return module
[294] Fix | Delete
[295] Fix | Delete
def safeimport(path, forceload=0, cache={}):
[296] Fix | Delete
"""Import a module; handle errors; return None if the module isn't found.
[297] Fix | Delete
[298] Fix | Delete
If the module *is* found but an exception occurs, it's wrapped in an
[299] Fix | Delete
ErrorDuringImport exception and reraised. Unlike __import__, if a
[300] Fix | Delete
package path is specified, the module at the end of the path is returned,
[301] Fix | Delete
not the package at the beginning. If the optional 'forceload' argument
[302] Fix | Delete
is 1, we reload the module from disk (unless it's a dynamic extension)."""
[303] Fix | Delete
try:
[304] Fix | Delete
# If forceload is 1 and the module has been previously loaded from
[305] Fix | Delete
# disk, we always have to reload the module. Checking the file's
[306] Fix | Delete
# mtime isn't good enough (e.g. the module could contain a class
[307] Fix | Delete
# that inherits from another module that has changed).
[308] Fix | Delete
if forceload and path in sys.modules:
[309] Fix | Delete
if path not in sys.builtin_module_names:
[310] Fix | Delete
# Avoid simply calling reload() because it leaves names in
[311] Fix | Delete
# the currently loaded module lying around if they're not
[312] Fix | Delete
# defined in the new source file. Instead, remove the
[313] Fix | Delete
# module from sys.modules and re-import. Also remove any
[314] Fix | Delete
# submodules because they won't appear in the newly loaded
[315] Fix | Delete
# module's namespace if they're already in sys.modules.
[316] Fix | Delete
subs = [m for m in sys.modules if m.startswith(path + '.')]
[317] Fix | Delete
for key in [path] + subs:
[318] Fix | Delete
# Prevent garbage collection.
[319] Fix | Delete
cache[key] = sys.modules[key]
[320] Fix | Delete
del sys.modules[key]
[321] Fix | Delete
module = __import__(path)
[322] Fix | Delete
except:
[323] Fix | Delete
# Did the error occur before or after the module was found?
[324] Fix | Delete
(exc, value, tb) = info = sys.exc_info()
[325] Fix | Delete
if path in sys.modules:
[326] Fix | Delete
# An error occurred while executing the imported module.
[327] Fix | Delete
raise ErrorDuringImport(sys.modules[path].__file__, info)
[328] Fix | Delete
elif exc is SyntaxError:
[329] Fix | Delete
# A SyntaxError occurred before we could execute the module.
[330] Fix | Delete
raise ErrorDuringImport(value.filename, info)
[331] Fix | Delete
elif exc is ImportError and extract_tb(tb)[-1][2]=='safeimport':
[332] Fix | Delete
# The import error occurred directly in this function,
[333] Fix | Delete
# which means there is no such module in the path.
[334] Fix | Delete
return None
[335] Fix | Delete
else:
[336] Fix | Delete
# Some other error occurred during the importing process.
[337] Fix | Delete
raise ErrorDuringImport(path, sys.exc_info())
[338] Fix | Delete
for part in split(path, '.')[1:]:
[339] Fix | Delete
try: module = getattr(module, part)
[340] Fix | Delete
except AttributeError: return None
[341] Fix | Delete
return module
[342] Fix | Delete
[343] Fix | Delete
# ---------------------------------------------------- formatter base class
[344] Fix | Delete
[345] Fix | Delete
class Doc:
[346] Fix | Delete
def document(self, object, name=None, *args):
[347] Fix | Delete
"""Generate documentation for an object."""
[348] Fix | Delete
args = (object, name) + args
[349] Fix | Delete
# 'try' clause is to attempt to handle the possibility that inspect
[350] Fix | Delete
# identifies something in a way that pydoc itself has issues handling;
[351] Fix | Delete
# think 'super' and how it is a descriptor (which raises the exception
[352] Fix | Delete
# by lacking a __name__ attribute) and an instance.
[353] Fix | Delete
if inspect.isgetsetdescriptor(object): return self.docdata(*args)
[354] Fix | Delete
if inspect.ismemberdescriptor(object): return self.docdata(*args)
[355] Fix | Delete
try:
[356] Fix | Delete
if inspect.ismodule(object): return self.docmodule(*args)
[357] Fix | Delete
if inspect.isclass(object): return self.docclass(*args)
[358] Fix | Delete
if inspect.isroutine(object): return self.docroutine(*args)
[359] Fix | Delete
except AttributeError:
[360] Fix | Delete
pass
[361] Fix | Delete
if isinstance(object, property): return self.docproperty(*args)
[362] Fix | Delete
return self.docother(*args)
[363] Fix | Delete
[364] Fix | Delete
def fail(self, object, name=None, *args):
[365] Fix | Delete
"""Raise an exception for unimplemented types."""
[366] Fix | Delete
message = "don't know how to document object%s of type %s" % (
[367] Fix | Delete
name and ' ' + repr(name), type(object).__name__)
[368] Fix | Delete
raise TypeError, message
[369] Fix | Delete
[370] Fix | Delete
docmodule = docclass = docroutine = docother = docproperty = docdata = fail
[371] Fix | Delete
[372] Fix | Delete
def getdocloc(self, object,
[373] Fix | Delete
basedir=os.path.join(sys.exec_prefix, "lib",
[374] Fix | Delete
"python"+sys.version[0:3])):
[375] Fix | Delete
"""Return the location of module docs or None"""
[376] Fix | Delete
[377] Fix | Delete
try:
[378] Fix | Delete
file = inspect.getabsfile(object)
[379] Fix | Delete
except TypeError:
[380] Fix | Delete
file = '(built-in)'
[381] Fix | Delete
[382] Fix | Delete
docloc = os.environ.get("PYTHONDOCS",
[383] Fix | Delete
"https://docs.python.org/library")
[384] Fix | Delete
basedir = os.path.normcase(basedir)
[385] Fix | Delete
if (isinstance(object, type(os)) and
[386] Fix | Delete
(object.__name__ in ('errno', 'exceptions', 'gc', 'imp',
[387] Fix | Delete
'marshal', 'posix', 'signal', 'sys',
[388] Fix | Delete
'thread', 'zipimport') or
[389] Fix | Delete
(file.startswith(basedir) and
[390] Fix | Delete
not file.startswith(os.path.join(basedir, 'site-packages')))) and
[391] Fix | Delete
object.__name__ not in ('xml.etree', 'test.pydoc_mod')):
[392] Fix | Delete
if docloc.startswith(("http://", "https://")):
[393] Fix | Delete
docloc = "%s/%s" % (docloc.rstrip("/"), object.__name__.lower())
[394] Fix | Delete
else:
[395] Fix | Delete
docloc = os.path.join(docloc, object.__name__.lower() + ".html")
[396] Fix | Delete
else:
[397] Fix | Delete
docloc = None
[398] Fix | Delete
return docloc
[399] Fix | Delete
[400] Fix | Delete
# -------------------------------------------- HTML documentation generator
[401] Fix | Delete
[402] Fix | Delete
class HTMLRepr(Repr):
[403] Fix | Delete
"""Class for safely making an HTML representation of a Python object."""
[404] Fix | Delete
def __init__(self):
[405] Fix | Delete
Repr.__init__(self)
[406] Fix | Delete
self.maxlist = self.maxtuple = 20
[407] Fix | Delete
self.maxdict = 10
[408] Fix | Delete
self.maxstring = self.maxother = 100
[409] Fix | Delete
[410] Fix | Delete
def escape(self, text):
[411] Fix | Delete
return replace(text, '&', '&amp;', '<', '&lt;', '>', '&gt;')
[412] Fix | Delete
[413] Fix | Delete
def repr(self, object):
[414] Fix | Delete
return Repr.repr(self, object)
[415] Fix | Delete
[416] Fix | Delete
def repr1(self, x, level):
[417] Fix | Delete
if hasattr(type(x), '__name__'):
[418] Fix | Delete
methodname = 'repr_' + join(split(type(x).__name__), '_')
[419] Fix | Delete
if hasattr(self, methodname):
[420] Fix | Delete
return getattr(self, methodname)(x, level)
[421] Fix | Delete
return self.escape(cram(stripid(repr(x)), self.maxother))
[422] Fix | Delete
[423] Fix | Delete
def repr_string(self, x, level):
[424] Fix | Delete
test = cram(x, self.maxstring)
[425] Fix | Delete
testrepr = repr(test)
[426] Fix | Delete
if '\\' in test and '\\' not in replace(testrepr, r'\\', ''):
[427] Fix | Delete
# Backslashes are only literal in the string and are never
[428] Fix | Delete
# needed to make any special characters, so show a raw string.
[429] Fix | Delete
return 'r' + testrepr[0] + self.escape(test) + testrepr[0]
[430] Fix | Delete
return re.sub(r'((\\[\\abfnrtv\'"]|\\[0-9]..|\\x..|\\u....)+)',
[431] Fix | Delete
r'<font color="#c040c0">\1</font>',
[432] Fix | Delete
self.escape(testrepr))
[433] Fix | Delete
[434] Fix | Delete
repr_str = repr_string
[435] Fix | Delete
[436] Fix | Delete
def repr_instance(self, x, level):
[437] Fix | Delete
try:
[438] Fix | Delete
return self.escape(cram(stripid(repr(x)), self.maxstring))
[439] Fix | Delete
except:
[440] Fix | Delete
return self.escape('<%s instance>' % x.__class__.__name__)
[441] Fix | Delete
[442] Fix | Delete
repr_unicode = repr_string
[443] Fix | Delete
[444] Fix | Delete
class HTMLDoc(Doc):
[445] Fix | Delete
"""Formatter class for HTML documentation."""
[446] Fix | Delete
[447] Fix | Delete
# ------------------------------------------- HTML formatting utilities
[448] Fix | Delete
[449] Fix | Delete
_repr_instance = HTMLRepr()
[450] Fix | Delete
repr = _repr_instance.repr
[451] Fix | Delete
escape = _repr_instance.escape
[452] Fix | Delete
[453] Fix | Delete
def page(self, title, contents):
[454] Fix | Delete
"""Format an HTML page."""
[455] Fix | Delete
return _encode('''
[456] Fix | Delete
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
[457] Fix | Delete
<html><head><title>Python: %s</title>
[458] Fix | Delete
<meta charset="utf-8">
[459] Fix | Delete
</head><body bgcolor="#f0f0f8">
[460] Fix | Delete
%s
[461] Fix | Delete
</body></html>''' % (title, contents), 'ascii')
[462] Fix | Delete
[463] Fix | Delete
def heading(self, title, fgcol, bgcol, extras=''):
[464] Fix | Delete
"""Format a page heading."""
[465] Fix | Delete
return '''
[466] Fix | Delete
<table width="100%%" cellspacing=0 cellpadding=2 border=0 summary="heading">
[467] Fix | Delete
<tr bgcolor="%s">
[468] Fix | Delete
<td valign=bottom>&nbsp;<br>
[469] Fix | Delete
<font color="%s" face="helvetica, arial">&nbsp;<br>%s</font></td
[470] Fix | Delete
><td align=right valign=bottom
[471] Fix | Delete
><font color="%s" face="helvetica, arial">%s</font></td></tr></table>
[472] Fix | Delete
''' % (bgcol, fgcol, title, fgcol, extras or '&nbsp;')
[473] Fix | Delete
[474] Fix | Delete
def section(self, title, fgcol, bgcol, contents, width=6,
[475] Fix | Delete
prelude='', marginalia=None, gap='&nbsp;'):
[476] Fix | Delete
"""Format a section with a heading."""
[477] Fix | Delete
if marginalia is None:
[478] Fix | Delete
marginalia = '<tt>' + '&nbsp;' * width + '</tt>'
[479] Fix | Delete
result = '''<p>
[480] Fix | Delete
<table width="100%%" cellspacing=0 cellpadding=2 border=0 summary="section">
[481] Fix | Delete
<tr bgcolor="%s">
[482] Fix | Delete
<td colspan=3 valign=bottom>&nbsp;<br>
[483] Fix | Delete
<font color="%s" face="helvetica, arial">%s</font></td></tr>
[484] Fix | Delete
''' % (bgcol, fgcol, title)
[485] Fix | Delete
if prelude:
[486] Fix | Delete
result = result + '''
[487] Fix | Delete
<tr bgcolor="%s"><td rowspan=2>%s</td>
[488] Fix | Delete
<td colspan=2>%s</td></tr>
[489] Fix | Delete
<tr><td>%s</td>''' % (bgcol, marginalia, prelude, gap)
[490] Fix | Delete
else:
[491] Fix | Delete
result = result + '''
[492] Fix | Delete
<tr><td bgcolor="%s">%s</td><td>%s</td>''' % (bgcol, marginalia, gap)
[493] Fix | Delete
[494] Fix | Delete
return result + '\n<td width="100%%">%s</td></tr></table>' % contents
[495] Fix | Delete
[496] Fix | Delete
def bigsection(self, title, *args):
[497] Fix | Delete
"""Format a section with a big heading."""
[498] Fix | Delete
title = '<big><strong>%s</strong></big>' % title
[499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function