我们从Python开源项目中,提取了以下22个代码示例,用于说明如何使用pydoc.join()。
def docserver(self, server_name, package_documentation, methods): """Produce HTML documentation for an XML-RPC server.""" fdict = {} for key, value in methods.items(): fdict[key] = '#-' + key fdict[value] = fdict[key] server_name = self.escape(server_name) head = '<big><big><strong>%s</strong></big></big>' % server_name result = self.heading(head, '#ffffff', '#7799ee') doc = self.markup(package_documentation, self.preformat, fdict) doc = doc and '<tt>%s</tt>' % doc result = result + '<p>%s</p>\n' % doc contents = [] method_items = sorted(methods.items()) for key, value in method_items: contents.append(self.docroutine(value, key, funcs=fdict)) result = result + self.bigsection( 'Methods', '#ffffff', '#eeaa77', pydoc.join(contents)) return result
def _wsdl2dispatch(options, wsdl): """TOOD: Remove ServiceContainer stuff, and replace with WSGI. """ kw = dict() # TODO: make all this handler arch if options.address is True: ss = ServiceDescriptionWSA() else: ss = ServiceDescription(**kw) ss.fromWSDL(wsdl) file_name = ss.getServiceModuleName()+'.py' fd = open( join(options.output_dir, file_name), 'w+') ss.write(fd) fd.close() return file_name
def markup(self, text, escape=None, funcs={}, classes={}, methods={}): """Mark up some plain text, given a context of symbols to look for. Each context dictionary maps object names to anchor names.""" escape = escape or self.escape results = [] here = 0 # XXX Note that this regular expression does not allow for the # hyperlinking of arbitrary strings being used as method # names. Only methods with names consisting of word characters # and '.'s are hyperlinked. pattern = re.compile(r'\b((http|ftp)://\S+[\w/]|' r'RFC[- ]?(\d+)|' r'PEP[- ]?(\d+)|' r'(self\.)?((?:\w|\.)+))\b') while 1: match = pattern.search(text, here) if not match: break start, end = match.span() results.append(escape(text[here:start])) all, scheme, rfc, pep, selfdot, name = match.groups() if scheme: url = escape(all).replace('"', '"') results.append('<a href="%s">%s</a>' % (url, url)) elif rfc: url = 'http://www.rfc-editor.org/rfc/rfc%d.txt' % int(rfc) results.append('<a href="%s">%s</a>' % (url, escape(all))) elif pep: url = 'http://www.python.org/dev/peps/pep-%04d/' % int(pep) results.append('<a href="%s">%s</a>' % (url, escape(all))) elif text[end:end+1] == '(': results.append(self.namelink(name, methods, funcs, classes)) elif selfdot: results.append('self.<strong>%s</strong>' % name) else: results.append(self.namelink(name, classes)) here = end results.append(escape(text[here:])) return ''.join(results)
def _wsdl2py(options, wsdl): if options.simple_naming: # Use a different client suffix # WriteServiceModule.client_module_suffix = "_client" # Write messages definitions to a separate file. #wsdl2pyServiceDescription.separate_messages = True # Use more simple type and element class names containers.SetTypeNameFunc( lambda n: '%s_' %(NC_to_CN(n)) ) containers.SetElementNameFunc( lambda n: '%s' %(NC_to_CN(n)) ) # Don't add "_" to the attribute name (remove when --aname works well) containers.ContainerBase.func_aname = lambda instnc,n: TextProtect(str(n)) # write out the modules with their names rather than their number. utility.namespace_name = lambda cls, ns: utility.Namespace2ModuleName(ns) files = [] append = files.append if isinstance(wsdl, XMLSchema.XMLSchema): wsm = WriteServiceModule(_XMLSchemaAdapter(wsdl.location, wsdl), addressing=options.address) else: wsm = WriteServiceModule(wsdl, addressing=options.address) client_mod = wsm.getClientModuleName() client_file = join(options.output_dir, '%s.py' %client_mod) append(client_file) fd = open(client_file, 'w+') wsm.writeClient(fd) fd.close() types_mod = wsm.getTypesModuleName() types_file = join(options.output_dir, '%s.py' %types_mod) append(types_file) fd = open(types_file, 'w+' ) wsm.writeTypes(fd) fd.close() return files
def __init__(self, location, schema): """Parameters: location -- base location, file path schema -- XMLSchema instance """ self.name = '_'.join(split(location)[-1].split('.')) self.types = {schema.targetNamespace:schema}
def _writedoc(doc, thing, forceload=0): """Write HTML documentation to a file in the current directory. """ try: obj, name = pydoc.resolve(thing, forceload) page = pydoc.html.page(pydoc.describe(obj), pydoc.html.document(obj, name)) fname = os.path.join(doc, name + '.html') fd = open(fname, 'w') fd.write(page) fd.close() except (ImportError, pydoc.ErrorDuringImport): traceback.print_exc(sys.stderr) else: return name + '.html'
def _writeclientdoc(doc, thing, forceload=0): """Write HTML documentation to a file in the current directory. """ docmodule = pydoc.HTMLDoc.docmodule def strongarm(self, obj, name=None, mod=None, *ignored): result = docmodule(self, obj, name, mod, *ignored) # Grab all the aliases to pyclasses and create links. nonmembers = [] push = nonmembers.append for k,v in inspect.getmembers(obj, inspect.isclass): if inspect.getmodule(v) is not obj and getattr(v,'typecode',None) is not None: push('<a href="%s.html">%s</a>: pyclass alias<br/>' %(v.__name__,k)) result += self.bigsection('Aliases', '#ffffff', '#eeaa77', ''.join(nonmembers)) return result pydoc.HTMLDoc.docmodule = strongarm try: obj, name = pydoc.resolve(thing, forceload) page = pydoc.html.page(pydoc.describe(obj), pydoc.html.document(obj, name)) name = os.path.join(doc, name + '.html') fd = open(name, 'w') fd.write(page) fd.close() except (ImportError, pydoc.ErrorDuringImport), value: log.debug(str(value)) pydoc.HTMLDoc.docmodule = docmodule
def _writepydoc(doc, *args): """create pydoc html pages doc -- destination directory for documents *args -- modules run thru pydoc """ if not os.path.isdir(doc): os.makedirs(doc) if os.path.curdir not in sys.path: sys.path.append(os.path.curdir) for f in args: if f.startswith('./'): f = f[2:] name = os.path.sep.join(f.strip('.py').split(os.path.sep)) try: e = __import__(name) except Exception,ex: raise # _writebrokedoc(doc, ex, name) # continue if name.endswith('_client'): _writeclientdoc(doc, e) continue if name.endswith('_types'): _writetypesdoc(doc, e) continue try: _writedoc(doc, e) except IndexError,ex: _writebrokedoc(doc, ex, name) continue