A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://mail.python.org/pipermail/python-dev/attachments/20040613/8e42d480/pydoc.py-0001.bin below:

%s' % doc push('
%s%s
\n' % (base, doc)) + if not visiblename(name): + push(self.endprivate) push('\n') + if allprivate: + push(self.endprivate) return attrs ! attrs = inspect.classify_class_attrs(object) mdict = {} for key, kind, homecls, value in attrs: mdict[key] = anchor = '#' + name + '-' + key *************** *** 799,809 **** contents = ''.join(contents) if name == realname: ! title = 'class %s' % ( ! name, realname) else: ! title = '%s = class %s' % ( ! name, name, realname) if bases: parents = [] for base in bases: --- 1016,1028 ---- contents = ''.join(contents) if name == realname: ! title = 'class '\ ! '%s' %\ ! (name, mod, name, realname) else: ! title = '%s = '\ ! 'class %s' % \ ! (mod, name, name, name, realname) if bases: parents = [] for base in bases: *************** *** 840,846 **** object = object.im_func if name == realname: ! title = '%s' % (anchor, realname) else: if (cl and realname in cl.__dict__ and cl.__dict__[realname] is object): --- 1059,1066 ---- object = object.im_func if name == realname: ! title = '%s'\ ! '' % (anchor, mod, anchor, realname) else: if (cl and realname in cl.__dict__ and cl.__dict__[realname] is object): *************** *** 849,856 **** skipdocs = 1 else: reallink = realname ! title = '%s = %s' % ( ! anchor, name, reallink) if inspect.isfunction(object): args, varargs, varkw, defaults = inspect.getargspec(object) argspec = inspect.formatargspec( --- 1069,1076 ---- skipdocs = 1 else: reallink = realname ! title = '%s'\ ! ' = %s' % (anchor, mod, anchor, name, reallink) if inspect.isfunction(object): args, varargs, varkw, defaults = inspect.getargspec(object) argspec = inspect.formatargspec( *************** *** 905,910 **** --- 1125,1273 ---- contents = self.multicolumn(modpkgs, self.modpkglink) return self.bigsection(dir, '#ffffff', '#ee77aa', contents) + # ---------------------------------------------- pretty-print source + + def tagify(self, readline, docfile): + """ + Wrap the tokenize.generate_tokens generator, to produce along with the + 5-tuple, the opening tag(s) for the token and the closing tag(s) for it. + docfile is the name of the HTML documentation file, to make class and + function definitions link to it. + """ + # current indentation level. incremented by 1 for each INDENT token + curindent = 0 + # a stack with the class names in which we are, and the indentation + # level in which each class was defined. + classstack = [] + # the type of definition which should be coming right now. Can be + # either "class" or "def", or None of course. + comingdefinition = None + + for tup in tokenize.generate_tokens(readline): + opentag = closetag = "" + + if comingdefinition: + if tup[0] != tokenize.NAME: + raise tokenize.TokenError, \ + ("A definition was expected.", tup[2]) + if comingdefinition == "class": + classstack.append((tup[1], curindent)) + aname = '-'.join([name for name, indent in classstack]) + if comingdefinition == "def": + aname = aname + '-' + tup[1] + opentag = ''\ + % (aname, docfile, aname) + closetag = '' + comingdefinition = None + elif tup[0] == tokenize.NAME: + if tup[1] in ('def', 'class'): + comingdefinition = tup[1] + if iskeyword(tup[1]): + opentag = '' + closetag = '' + elif tup[0] == tokenize.INDENT: + curindent += 1 + elif tup[0] == tokenize.DEDENT: + curindent -= 1 + if classstack and classstack[-1][1] == curindent: + classstack.pop() + elif tup[0] == tokenize.COMMENT: + opentag = '' + elif tup[0] == tokenize.STRING: + opentag = '' + closetag = '' + elif tup[0] == tokenize.NUMBER: + opentag = '' + closetag = '' + + yield tup, opentag, closetag + + class LineNumberer: + """ + A simple class which writes to a file object the line-numbered input + given with the method write. + """ + def __init__(self, outfile): + self.curline = 0 + self.outfile = outfile + outfile.write(' \n' + ' ') + self.pendingnewline = True + + def write(self, text, opentag="", closetag=""): + outfile = self.outfile + lines = text.split('\n') + for i, line in enumerate(lines): + if self.pendingnewline: + self.curline += 1 + outfile.write( + ' %d ' + % self.curline) + self.pendingnewline = False + if opentag: outfile.write(opentag) + outfile.write(line.replace('<','<').replace('>','>')) + if closetag: outfile.write(closetag) + if i < len(lines)-1: + outfile.write(' \n') + self.pendingnewline = True + + def writeend(self): + outfile = self.outfile + if not self.pendingnewline: + outfile.write('\n') + outfile.write(' \n') + + def sourcemodule(self, path, name, destdir=None): + """ + Produce HTML source code, which is linked with the module documentation. + """ + parts = split(name, '.') + links = [] + for i in range(len(parts)): + links.append( + '%s' % + (join(parts[:i+1], '.'), parts[i])) + linkedname = join(links, '.') + head = '%s source' % linkedname + fixedpath = path + if destdir: + curdir = os.path.abspath(os.getcwd()) + if path.startswith(curdir): + fixedpath = os.path.join(destdir, path[len(curdir)+1:]) + url = fixedpath + if sys.platform == 'win32': + import nturl2path + url = nturl2path.pathname2url(path) + filelink = 'download %s' % (url, fixedpath) + result = StringIO() + result.write(self.heading( + head, '#ffffff', '#7799ee', + 'index
' + filelink + '
' + + 'back to documentation' % name)) + + numberer = self.LineNumberer(result) + curpos = (1, 0) + try: + for tup, opentag, closetag in self.tagify(file(path).readline, + name+".html"): + if curpos[0] < tup[2][0]: + numberer.write('\n' * (tup[2][0]-curpos[0]) + + ' ' * tup[2][1]) + elif curpos[1] < tup[2][1]: + numberer.write(' ' * (tup[2][1] - curpos[1])) + numberer.write(tup[1], opentag, closetag) + curpos = tup[3] + if tup[1].endswith('\n'): + curpos = curpos[0]+1, 0 + except tokenize.TokenError, e: + return "Could not produce pretty-printed source code of the file "\ + "%s, because of an error in line %d column %d: %s"\ + % (path, e[1][0], e[1][1], e[0]) + numberer.writeend() + + return result.getvalue() + # -------------------------------------------- text documentation generator class TextRepr(Repr): *************** *** 985,1019 **** """Produce text documentation for a given module object.""" name = object.__name__ # ignore the passed-in name synop, desc = splitdoc(getdoc(object)) ! result = self.section('NAME', name + (synop and ' - ' + synop)) try: file = inspect.getabsfile(object) except TypeError: file = '(built-in)' ! result = result + self.section('FILE', file) docloc = self.getdocloc(object) if docloc is not None: ! result = result + self.section('MODULE DOCS', docloc) if desc: ! result = result + self.section('DESCRIPTION', desc) ! classes = [] ! for key, value in inspect.getmembers(object, inspect.isclass): ! if (inspect.getmodule(value) or object) is object: ! if visiblename(key): ! classes.append((key, value)) ! funcs = [] ! for key, value in inspect.getmembers(object, inspect.isroutine): ! if inspect.isbuiltin(value) or inspect.getmodule(value) is object: ! if visiblename(key): ! funcs.append((key, value)) ! data = [] ! for key, value in inspect.getmembers(object, isdata): ! if visiblename(key): ! data.append((key, value)) if hasattr(object, '__path__'): modpkgs = [] --- 1348,1379 ---- """Produce text documentation for a given module object.""" name = object.__name__ # ignore the passed-in name synop, desc = splitdoc(getdoc(object)) ! result = StringIO() ! result.write(self.section('NAME', name + (synop and ' - ' + synop))) try: file = inspect.getabsfile(object) except TypeError: file = '(built-in)' ! result.write(self.section('FILE', file)) docloc = self.getdocloc(object) if docloc is not None: ! result.write(self.section('MODULE DOCS', docloc)) if desc: ! result.write(self.section('DESCRIPTION', desc)) ! publicmembers = [(key, getattr(object, key)) ! for key in getpublicmembers(object)] ! publicmembers.sort() ! ! classes = [(key, value) for key, value in publicmembers ! if inspect.isclass(value)] ! funcs = [(key, value) for key, value in publicmembers ! if inspect.isroutine(value)] ! data = [(key, value) for key, value in publicmembers ! if isdata(value)] if hasattr(object, '__path__'): modpkgs = [] *************** *** 1026,1033 **** elif ispackage(path): modpkgs.append(file + ' (package)') modpkgs.sort() ! result = result + self.section( ! 'PACKAGE CONTENTS', join(modpkgs, '\n')) if classes: classlist = map(lambda (key, value): value, classes) --- 1386,1393 ---- elif ispackage(path): modpkgs.append(file + ' (package)') modpkgs.sort() ! result.write(self.section( ! 'PACKAGE CONTENTS', join(modpkgs, '\n'))) if classes: classlist = map(lambda (key, value): value, classes) *************** *** 1035,1066 **** inspect.getclasstree(classlist, 1), name)] for key, value in classes: contents.append(self.document(value, key, name)) ! result = result + self.section('CLASSES', join(contents, '\n')) if funcs: contents = [] for key, value in funcs: contents.append(self.document(value, key, name)) ! result = result + self.section('FUNCTIONS', join(contents, '\n')) if data: contents = [] for key, value in data: contents.append(self.docother(value, key, name, 70)) ! result = result + self.section('DATA', join(contents, '\n')) if hasattr(object, '__version__'): version = str(object.__version__) if version[:11] == '$' + 'Revision: ' and version[-1:] == '$': version = strip(version[11:-1]) ! result = result + self.section('VERSION', version) if hasattr(object, '__date__'): ! result = result + self.section('DATE', str(object.__date__)) if hasattr(object, '__author__'): ! result = result + self.section('AUTHOR', str(object.__author__)) if hasattr(object, '__credits__'): ! result = result + self.section('CREDITS', str(object.__credits__)) ! return result def docclass(self, object, name=None, mod=None): """Produce text documentation for a given class object.""" --- 1395,1426 ---- inspect.getclasstree(classlist, 1), name)] for key, value in classes: contents.append(self.document(value, key, name)) ! result.write(self.section('CLASSES', join(contents, '\n'))) if funcs: contents = [] for key, value in funcs: contents.append(self.document(value, key, name)) ! result.write(self.section('FUNCTIONS', join(contents, '\n'))) if data: contents = [] for key, value in data: contents.append(self.docother(value, key, name, 70)) ! result.write(self.section('DATA', join(contents, '\n'))) if hasattr(object, '__version__'): version = str(object.__version__) if version[:11] == '$' + 'Revision: ' and version[-1:] == '$': version = strip(version[11:-1]) ! result.write(self.section('VERSION', version)) if hasattr(object, '__date__'): ! result.write(self.section('DATE', str(object.__date__))) if hasattr(object, '__author__'): ! result.write(self.section('AUTHOR', str(object.__author__))) if hasattr(object, '__credits__'): ! result.write(self.section('CREDITS', str(object.__credits__))) ! return result.getvalue() def docclass(self, object, name=None, mod=None): """Produce text documentation for a given class object.""" *************** *** 1376,1387 **** return 'instance of ' + thing.__class__.__name__ return type(thing).__name__ ! def locate(path, forceload=0): """Locate an object by name or dotted path, importing as necessary.""" parts = [part for part in split(path, '.') if part] module, n = None, 0 while n < len(parts): ! nextmodule = safeimport(join(parts[:n+1], '.'), forceload) if nextmodule: module, n = nextmodule, n + 1 else: break if module: --- 1736,1747 ---- return 'instance of ' + thing.__class__.__name__ return type(thing).__name__ ! def locate(path, forceload=False, finddirs=None): """Locate an object by name or dotted path, importing as necessary.""" parts = [part for part in split(path, '.') if part] module, n = None, 0 while n < len(parts): ! nextmodule = safeimport(join(parts[:n+1], '.'), forceload, finddirs) if nextmodule: module, n = nextmodule, n + 1 else: break if module: *************** *** 1399,1408 **** text = TextDoc() html = HTMLDoc() ! def resolve(thing, forceload=0): """Given an object or a path to an object, get the object and its name.""" if isinstance(thing, str): ! object = locate(thing, forceload) if not object: raise ImportError, 'no Python documentation found for %r' % thing return object, thing --- 1759,1768 ---- text = TextDoc() html = HTMLDoc() ! def resolve(thing, forceload=0, finddirs=None): """Given an object or a path to an object, get the object and its name.""" if isinstance(thing, str): ! object = locate(thing, forceload, finddirs) if not object: raise ImportError, 'no Python documentation found for %r' % thing return object, thing *************** *** 1423,1447 **** except (ImportError, ErrorDuringImport), value: print value ! def writedoc(thing, forceload=0): ! """Write HTML documentation to a file in the current directory.""" try: ! object, name = resolve(thing, forceload) ! page = html.page(describe(object), html.document(object, name)) ! file = open(name + '.html', 'w') ! file.write(page) ! file.close() ! print 'wrote', name + '.html' except (ImportError, ErrorDuringImport), value: print value ! def writedocs(dir, pkgpath='', done=None): """Write out HTML documentation for all modules in a directory tree.""" if done is None: done = {} for file in os.listdir(dir): path = os.path.join(dir, file) if ispackage(path): ! writedocs(path, pkgpath + file + '.', done) elif os.path.isfile(path): modname = inspect.getmodulename(path) if modname: --- 1783,1858 ---- except (ImportError, ErrorDuringImport), value: print value ! def shouldwritefile(sourcefn, destfn, updateonly): ! """ ! Get the module file name and the documentation file name, and return True ! if a documentation should be written. ! A documentation should be written if destfn doesn't exist, or it is older ! than sourcefn and was generated by pydoc. ! If sourcefn is None or updateonly is False, then the date of the existing ! file is ignored. ! """ ! if not os.path.exists(destfn): ! return True ! else: ! if sourcefn and updateonly and \ ! os.path.getmtime(destfn) > os.path.getmtime(sourcefn): ! return False ! else: ! if HTMLDoc.generatortag in file(destfn).read(1000): ! return True ! else: ! print >> sys.stderr, \ ! "Warning: file %s is older than %s, but wasn't updated "\ ! "because it hasn't been created by pydoc."\ ! % (destfn, sourcefn) ! return False ! ! def writedoc(thing, forceload=0, finddirs=None, outputdir="", destdir=None, ! updateonly=False): ! """Write HTML documentation to a file.""" try: ! object, name = resolve(thing, forceload, finddirs) ! try: ! sourcefn = inspect.getabsfile(object) ! except TypeError: ! sourcefn = None ! ! destfn = os.path.join(outputdir, name + '.html') ! if shouldwritefile(sourcefn, destfn, updateonly): ! page = html.page(describe(object), html.show_hide_private_html_head, ! html.document(object, name, destdir=destdir)) ! file = open(destfn, 'w') ! file.write(page) ! file.close() ! print 'wrote', name + '.html' ! ! destfn = os.path.join(outputdir, name + '-source.html') ! if sourcefn.endswith('.pyc'): ! # We can't use a pyc file as a source code, so try the '.py' file. ! sourcefn = sourcefn[:-1] ! if sourcefn and os.path.exists(sourcefn) and \ ! shouldwritefile(sourcefn, destfn, updateonly): ! page = html.page("%s source" % name, html.source_head, ! html.sourcemodule(sourcefn, name, destdir)) ! file = open(destfn, 'w') ! file.write(page) ! file.close() ! print 'wrote %s-source.html' % name ! except (ImportError, ErrorDuringImport), value: print value ! def writedocs(dir, pkgpath='', done=None, outputdir="", destdir=None, ! origdir=None): """Write out HTML documentation for all modules in a directory tree.""" if done is None: done = {} + origdir = origdir or dir for file in os.listdir(dir): path = os.path.join(dir, file) if ispackage(path): ! writedocs(path, pkgpath + file + '.', done, outputdir, destdir, ! origdir) elif os.path.isfile(path): modname = inspect.getmodulename(path) if modname: *************** *** 1451,1457 **** modname = pkgpath + modname if modname not in done: done[modname] = 1 ! writedoc(modname) class Helper: keywords = { --- 1862,1869 ---- modname = pkgpath + modname if modname not in done: done[modname] = 1 ! writedoc(modname, finddirs=[origdir], outputdir=outputdir, ! destdir=destdir, updateonly=True) class Helper: keywords = { *************** *** 1854,1865 **** self.parseplist() class DocHandler(BaseHTTPServer.BaseHTTPRequestHandler): ! def send_document(self, title, contents): try: self.send_response(200) self.send_header('Content-Type', 'text/html') self.end_headers() ! self.wfile.write(html.page(title, contents)) except IOError: pass def do_GET(self): --- 2266,2277 ---- self.parseplist() class DocHandler(BaseHTTPServer.BaseHTTPRequestHandler): ! def send_document(self, title, head, contents): try: self.send_response(200) self.send_header('Content-Type', 'text/html') self.end_headers() ! self.wfile.write(html.page(title, head, contents)) except IOError: pass def do_GET(self): *************** *** 1867,1881 **** if path[-5:] == '.html': path = path[:-5] if path[:1] == '/': path = path[1:] if path and path != '.': try: ! obj = locate(path, forceload=1) except ErrorDuringImport, value: ! self.send_document(path, html.escape(str(value))) return if obj: ! self.send_document(describe(obj), html.document(obj, path)) else: ! self.send_document(path, 'no Python documentation found for %s' % repr(path)) else: heading = html.heading( --- 2279,2309 ---- if path[-5:] == '.html': path = path[:-5] if path[:1] == '/': path = path[1:] if path and path != '.': + givesource = path.endswith('-source') + if givesource: + path = path[:-7] try: ! obj = locate(path, forceload=False) except ErrorDuringImport, value: ! self.send_document(path, "", html.escape(str(value))) return if obj: ! if not givesource: ! self.send_document(describe(obj), ! html.show_hide_private_html_head, ! html.document(obj, path)) ! else: ! try: ! absfile = inspect.getabsfile(obj) ! except TypeError: ! self.send_document(path, "", "Can't show the source" ! " code of a built-in module.") ! else: ! self.send_document("%s source" % path, ! html.source_head, ! html.sourcemodule(absfile, path)) else: ! self.send_document(path, "", 'no Python documentation found for %s' % repr(path)) else: heading = html.heading( *************** *** 1895,1901 **** contents = heading + join(indices) + '''

pydoc by Ka-Ping Yee <ping@lfw.org>''' ! self.send_document('Index of Modules', contents) def log_message(self, *args): pass --- 2323,2329 ---- contents = heading + join(indices) + '''

pydoc by Ka-Ping Yee <ping@lfw.org>''' ! self.send_document('Index of Modules', "", contents) def log_message(self, *args): pass *************** *** 2125,2132 **** sys.path.insert(0, '.') try: ! opts, args = getopt.getopt(sys.argv[1:], 'gk:p:w') writing = 0 for opt, val in opts: if opt == '-g': --- 2553,2562 ---- sys.path.insert(0, '.') try: ! opts, args = getopt.getopt(sys.argv[1:], 'gk:p:wo:d:') writing = 0 + outputdir = "" + destdir = "" for opt, val in opts: if opt == '-g': *************** *** 2148,2153 **** --- 2578,2587 ---- return if opt == '-w': writing = 1 + if opt == '-o': + outputdir = val + if opt == '-d': + destdir = val if not args: raise BadUsage for arg in args: *************** *** 2159,2167 **** arg = importfile(arg) if writing: if ispath(arg) and os.path.isdir(arg): ! writedocs(arg) else: ! writedoc(arg) else: help.help(arg) except ErrorDuringImport, value: --- 2593,2601 ---- arg = importfile(arg) if writing: if ispath(arg) and os.path.isdir(arg): ! writedocs(arg, outputdir=outputdir, destdir=destdir) else: ! writedoc(arg, outputdir=outputdir, destdir=destdir) else: help.help(arg) except ErrorDuringImport, value: *************** *** 2188,2197 **** %s -g Pop up a graphical interface for finding and serving documentation. ! %s -w ... Write out the HTML documentation for a module to a file in the current directory. If contains a '%s', it is treated as a filename; if it names a directory, documentation is written for all the contents. """ % (cmd, os.sep, cmd, cmd, cmd, cmd, os.sep) if __name__ == '__main__': cli() --- 2622,2636 ---- %s -g Pop up a graphical interface for finding and serving documentation. ! %s -w [-o outputdir] [-d destdir] ... Write out the HTML documentation for a module to a file in the current directory. If contains a '%s', it is treated as a filename; if it names a directory, documentation is written for all the contents. + If outputdir is given, files are written into that dir instead of into + current directory. + If destdir is given, the current working directory in module documentation + is replaced with destdir. This is useful if the files are to be transferred + to another location. """ % (cmd, os.sep, cmd, cmd, cmd, cmd, os.sep) if __name__ == '__main__': cli()


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4