• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python pydoc.resolve函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中pydoc.resolve函数的典型用法代码示例。如果您正苦于以下问题:Python resolve函数的具体用法?Python resolve怎么用?Python resolve使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了resolve函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: helpNonVerbose

def helpNonVerbose(thing, title='Python Library Documentation: %s', forceload=0):
    """
    Utility method to return python help in the form of a string
    (based on the code in pydoc.py)
    Note: only a string (including unicode) should be passed in for "thing"
    """
    
    import pydoc as pydocs
    import inspect
    import string

    result=""

    # Important for converting an incoming c++ unicode character string!
    thingStr=str(thing)

    """Display text documentation, given an object or a path to an object."""
    try:
        # Possible two-stage object resolution!
        # Sometimes we get docs for strings, other times for objects
        #
        try:
            object, name = pydocs.resolve(thingStr, forceload)
        except:
            # Get an object from a string
            thingObj=eval(thingStr)
            object, name = pydocs.resolve(thingObj, forceload)
        desc = pydocs.describe(object)
        module = inspect.getmodule(object)
        if name and '.' in name:
            desc += ' in ' + name[:name.rfind('.')]
        elif module and module is not object:
            desc += ' in module ' + module.__name__
        if not (inspect.ismodule(object) or
                inspect.isclass(object) or
                inspect.isroutine(object) or
                inspect.isgetsetdescriptor(object) or
                inspect.ismemberdescriptor(object) or
                isinstance(object, property)):
            # If the passed object is a piece of data or an instance,
            # document its available methods instead of its value.
            object = type(object)
            desc += ' object'
        text = pydocs.TextDoc()
        result=pydocs.plain(title % desc + '\n\n' + text.document(object, name))
        
        # Remove multiple empty lines
        result = [ line for line in result.splitlines() if line.strip() ]
        result = string.join(result,"\n")

    except:
        pass

    return result
开发者ID:adamcobabe,项目名称:pymel,代码行数:54,代码来源:utils.py


示例2: get_pydoc_completions

def get_pydoc_completions(modulename=None):
    """Get possible completions for modulename for pydoc.

    Returns a list of possible values to be passed to pydoc.

    """
    modulename = compat.ensure_not_unicode(modulename)
    modules = get_modules(modulename)
    if modulename is None:
        return modules
    if modules is None:
        modules = []
    try:
        module, name = resolve(modulename)
    except:
        return None

    if isinstance(module, CONTAINER_TYPES):
        modules.extend(name for name in dir(module)
                       if not name.startswith("_") and
                       isinstance(getattr(module, name),
                                  PYDOC_TYPES))
    if modules:
        return modules
    else:
        return None
开发者ID:Jlen4ik,项目名称:emacsenv,代码行数:26,代码来源:pydocutils.py


示例3: PrintHtml

def PrintHtml(name, things):
  """Print HTML documentation to stdout."""
  ambiguous = len(things) > 1
  
  content = ""
  for thing in things:
    obj, name = pydoc.resolve(thing, forceload=0)
    title = pydoc.describe(obj)
    if ambiguous:
      if inspect.ismethoddescriptor(obj):
        content += '\n\n<h2>method %s in class %s</h2>\n' % (obj.__name__, obj.__dict__)
      else:
        content += '<h2>%s in module <a href="py:%s">%s</a></h2>\n' % (title, obj.__module__, obj.__module__)
    content += pydoc.html.document(obj, name)
  
  if ambiguous:
    title = 'Matches for "%s"' % name
    content = '<h1>%s</h1>\n\n%s' % (title, content)
  
  page = pydoc.html.page(title, content)
  
  # Note: rewriting the anchors in a form more useful to Evergreen should be in Evergreen, not here.
  # The rewriting here should be generally useful to anyone or anything that needs Python documentation.
  
  # Remove a couple of useless (and seemingly broken) links.
  page = page.replace('<a href=".">index</a><br>', '')
  page = re.sub('<br><a href="[^"]+\.html">Module Docs</a>', '', page)
  
  # There's a bug in pydoc that makes it output the text of the "Modules" section in cyan instead of white.
  page = re.sub('"#fffff"', '"#ffffff"', page)
  # The explicit font specifications are unnecessary manual uglification.
  page = re.sub(' face="[^"]+"', '', page);
  
  sys.stdout.write(page + '\n')
开发者ID:007durgesh219,项目名称:jessies,代码行数:34,代码来源:epydoc.py


示例4: doc2

def doc2(thing, title="Python Library Documentation: %s", forceload=0):
    """Display text documentation, given an object or a path to an object."""
    import types

    try:
        object, name = pydoc.resolve(thing, forceload)
        desc = pydoc.describe(object)
        module = mygetmodule(object)
        if name and "." in name:
            desc += " in " + name[: name.rfind(".")]
        elif module and module is not object:
            desc += " in module " + module.__name__

        if not (
            inspect.ismodule(object)
            or inspect.isclass(object)
            or inspect.isroutine(object)
            or isinstance(object, property)
        ):
            # If the passed object is a piece of data or an instance,
            # document its available methods instead of its value.

            # if this is a instance of used defined old-style class
            if type(object) == types.InstanceType:
                object = object.__class__
            else:
                object = type(object)
            desc += " object"
        pydoc.pager(title % desc + "\n\n" + pydoc.text.document(object, name))
    except (ImportError, pydoc.ErrorDuringImport), value:
        print value
开发者ID:wvengen,项目名称:lgipilot,代码行数:31,代码来源:gangadoc.py


示例5: get_pydoc_completions

def get_pydoc_completions(modulename=None):
    """Get possible completions for modulename for pydoc.

    Returns a list of possible values to be passed to pydoc.

    """
    modules = get_modules(modulename)
    if modulename is None:
        return modules
    if modules is None:
        modules = []
    try:
        module, name = resolve(modulename)
    except:
        return None

    if isinstance(module, (type, types.ClassType,
                           types.ModuleType)):
        modules.extend(name for name in dir(module)
                       if not name.startswith("_") and
                       isinstance(getattr(module, name),
                                  (type,
                                   types.FunctionType,
                                   types.BuiltinFunctionType,
                                   types.BuiltinMethodType,
                                   types.ClassType,
                                   types.MethodType,
                                   types.ModuleType)))
    if modules:
        return modules
    else:
        return None
开发者ID:0sn,项目名称:elpy,代码行数:32,代码来源:pydocutils.py


示例6: gethtmldoc

def gethtmldoc(thing, forceload=0):
    obj, name = pydoc.resolve(thing, forceload)
    page = pydoc.html.page(
        pydoc.describe(obj),
        pydoc.html.document(obj, name)
    )
    return page
开发者ID:Joey-Lee,项目名称:pyobjc,代码行数:7,代码来源:pydochelper.py


示例7: _writeclientdoc

def _writeclientdoc(doc, thing, forceload=0):
    """Write HTML documentation to a file in the current directory.
    """
    docmodule = pydoc.HTMLDoc.docmodule
    def strongarm(self, object, name=None, mod=None, *ignored):
        result = docmodule(self, object, name, mod, *ignored)

        # Grab all the aliases to pyclasses and create links.
        nonmembers = []
        push = nonmembers.append
        for k,v in inspect.getmembers(object, inspect.isclass):
            if inspect.getmodule(v) is not object 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:
        object, name = pydoc.resolve(thing, forceload)
        page = pydoc.html.page(pydoc.describe(object), pydoc.html.document(object, name))
        name = os.path.join(doc, name + '.html')
        file = open(name, 'w')
        file.write(page)
        file.close()
    except (ImportError, pydoc.ErrorDuringImport), value:
        log.debug(str(value))
开发者ID:mikedougherty,项目名称:ZSI,代码行数:27,代码来源:commands.py


示例8: local_docs

def local_docs(word):
    import pydoc
    try:
        obj, name = pydoc.resolve(word)
    except ImportError:
        return None
    desc = pydoc.describe(obj)
    return [(desc, urljoin(pydoc_url()[0], "%s.html" % word))]
开发者ID:prymatex,项目名称:python.tmbundle,代码行数:8,代码来源:docmate.py


示例9: getPydocHtml

def getPydocHtml(oModule):
    r"""Get pydoc for a module.
    """
    sHtml = pydoc.html.document(*pydoc.resolve(thing=oModule))
    sHtml = re.sub(r'<tr bgcolor="#aa55cc">.*?</td></tr></table></td></tr></table>', '</table>', sHtml, flags=re.DOTALL) # remove modules
    sHtml = re.sub(r'<tr bgcolor="#55aa55">.*?</td></tr></table>', '</table>', sHtml, flags=re.DOTALL) # remove data
    sHtml = re.sub(r'<a href=.*?</a>', '', sHtml) # remove links
    return sHtml
开发者ID:vbem,项目名称:breeze3,代码行数:8,代码来源:breeze_server.py


示例10: _writetypesdoc

def _writetypesdoc(doc, thing, forceload=0):
    """Write HTML documentation to a file in the current directory.
    """
    try:
        object, name = pydoc.resolve(thing, forceload)
        name = os.path.join(doc, name + '.html')
    except (ImportError, pydoc.ErrorDuringImport), value:
        log.debug(str(value))
        return
开发者ID:mikedougherty,项目名称:ZSI,代码行数:9,代码来源:commands.py


示例11: main

def main():
  document = ""

  for clz in mrh.getAllDocumentedClasses():
    object, name = pydoc.resolve(str(clz), 0)
    document += pydoc.html.document(object, name)

  page = create_page('MonkeyRunner API', document)
  file = open(BASEDIR + 'monkeyrunner_api.html', 'w')
  file.write(page)
  file.close()
开发者ID:jixieshi999,项目名称:lowen,代码行数:11,代码来源:mr_pydoc.py


示例12: custom_writedoc

def custom_writedoc(thing, forceload=0):
    """Write HTML documentation to specific directory"""
    try:
        object, name = pydoc.resolve(thing, forceload)
        page = pydoc.html.page(pydoc.describe(object), pydoc.html.document(object, name))
        file = open(PYDOC_OUTPUT_DIR + name + '.html', 'w')
        file.write(page)
        file.close()
        print 'wrote', PYDOC_OUTPUT_DIR + name + '.html'
    except (ImportError, pydoc.ErrorDuringImport), value:
        print value
开发者ID:fregaham,项目名称:mod-lang-jython,代码行数:11,代码来源:pydocx.py


示例13: test

def test():
    module = importfile("ext_doc.py")
    tmp_obj, name = resolve(module)
    print "GOT_C: ", find_class("foo", tmp_obj)
    print "GOT_F: ", find_func("find_func", tmp_obj)
    print "GOT_CF: ", find_func("foo:bar", tmp_obj)
    print "GOT_RF: ", find_func("find_.*", tmp_obj, as_regexp=True)
    print "GOT_CRF: \n", find_func("foo:.*", tmp_obj, as_regexp=True)
    funcs = find_func("foo:.*", tmp_obj, as_regexp=True)
    for f_name, f_ref in funcs:
        dump_func_doc(f_name, f_ref)
    dump_object(name, tmp_obj)
开发者ID:unioslo,项目名称:cerebrum,代码行数:12,代码来源:ext_doc.py


示例14: _writedoc

def _writedoc(doc, thing, forceload=0):
    """Write HTML documentation to a file in the current directory.
    """
    try:
        object, name = pydoc.resolve(thing, forceload)
        page = pydoc.html.page(pydoc.describe(object), pydoc.html.document(object, name))
        fname = os.path.join(doc, name + '.html')
        file = open(fname, 'w')
        file.write(page)
        file.close()
    except (ImportError, pydoc.ErrorDuringImport), value:
        traceback.print_exc(sys.stderr)
开发者ID:mikedougherty,项目名称:ZSI,代码行数:12,代码来源:commands.py


示例15: update_action

 def update_action(self, text):
     o, n = pydoc.resolve(self.data, getattr(self.data, text))
     self.ids.info_label.text = pydoc.text.document(o, n)
     self.action = getattr(self.data, self.ids.action_choose.text)
     self.ids.func_args.clear_widgets()
     argspec = inspect.getargspec(self.action)
     args, defs = argspec.args[1:], argspec.defaults
     while len(defs) < len(args):
         defs = [''] + defs
     for i, a in enumerate(args):
         entry = Factory.FormEntry(text=a,
                                   default=defs[i])
         self.ids.func_args.add_widget(entry)
开发者ID:sirpercival,项目名称:garden.datatable,代码行数:13,代码来源:pandas_table.py


示例16: strongarm

    def strongarm(self, object, name=None, mod=None, funcs={}, classes={}, *ignored):
        """Produce HTML documentation for a class object."""
        realname = object.__name__
        name = name or realname
        bases = object.__bases__
        object, name = pydoc.resolve(object, forceload)
        contents = []
        push = contents.append
        if name == realname:
            title = '<a name="%s">class <strong>%s</strong></a>' % (
                name, realname)
        else:
            title = '<strong>%s</strong> = <a name="%s">class %s</a>' % (
                name, name, realname)

        mdict = {}
        if bases:
            parents = []
            for base in bases:
                parents.append(self.classlink(base, object.__module__))
            title = title + '(%s)' % pydoc.join(parents, ', ')

        doc = self.markup(pydoc.getdoc(object), self.preformat, funcs, classes, mdict)
        doc = doc and '<tt>%s<br>&nbsp;</tt>' % doc
        for iname,iclass in cdict[name]:
            fname = fdict[(name,iname)]

            if elements_dict.has_key(iname):
                push('class <a href="%s">%s</a>: element declaration typecode<br/>'\
                    %(fname,iname))
                pyclass = elements_dict[iname]
                if pyclass is not None:
                    push('<ul>instance attributes:')
                    push('<li><a href="%s">pyclass</a>: instances serializable to XML<br/></li>'\
                        %elements_dict[iname])
                    push('</ul>')
            elif types_dict.has_key(iname):
                push('class <a href="%s">%s</a>: type definition typecode<br/>' %(fname,iname))
                pyclass = types_dict[iname]
                if pyclass is not None:
                    push('<ul>instance attributes:')
                    push('<li><a href="%s">pyclass</a>: instances serializable to XML<br/></li>'\
                          %types_dict[iname])
                    push('</ul>')
            else:
                push('class <a href="%s">%s</a>: TODO not sure what this is<br/>' %(fname,iname))

        contents = ''.join(contents)
        return self.section(title, '#000000', '#ffc8d8', contents, 3, doc)
开发者ID:mikedougherty,项目名称:ZSI,代码行数:49,代码来源:commands.py


示例17: get_completions

def get_completions(modulename):
    modules = set("{0}.{1}".format(modulename, module)
                  for module in get_modules(modulename))

    try:
        module, name = resolve(modulename)
    except ImportError:
        return modules
    if isinstance(module, CONTAINER_TYPES):
        modules.update("{0}.{1}".format(modulename, name)
                       for name in dir(module)
                       if not name.startswith("_") and
                       isinstance(getattr(module, name),
                                  PYDOC_TYPES))
    return modules
开发者ID:AlexBaranosky,项目名称:myemacs,代码行数:15,代码来源:pydocutils.py


示例18: buildAllDocs

def buildAllDocs(symbol='pyroclast'):
	"""Recursively constructs HTML pages of documentation the given module
	   contents, beginning with pyroclast itself, which are subsequently written
	   to the package's 'docs/' folder.
	"""
	dd = getDocDir()
	obj, name = pydoc.resolve(symbol)
	page = pydoc.html.page(pydoc.describe(obj), pydoc.html.document(obj,name))
	with open(dd + name + '.html', 'w') as f:
		f.write(page)
	if hasattr(obj, '__all__'):
		for a in obj.__all__:
			identifier = name + '.' + a
			child = importlib.import_module(identifier)
			buildAllDocs(child)
开发者ID:Tythos,项目名称:pyroclast,代码行数:15,代码来源:__init__.py


示例19: help

def help(obj):
    """
    Display HTML help for ``obj``, a Python object, module, etc.  This
    help is often more extensive than that given by 'obj?'.  This
    function does not return a value --- it prints HTML as a side
    effect.
    
    .. note::

       This a wrapper around the built-in help. If formats the output
       as HTML without word wrap, which looks better in the notebook.

    INPUT:
    
    -  ``obj`` - a Python object, module, etc.
    
    TESTS::
    
        sage: import numpy.linalg
        sage: import os, sage.misc.misc ; current_dir = os.getcwd()
        sage: os.chdir(sage.misc.misc.tmp_dir('server_doctest'))
        sage: sage.server.support.help(numpy.linalg.norm)
        <html><table notracebacks bgcolor="#386074" cellpadding=10 cellspacing=10><tr><td bgcolor="#f5f5f5"><font color="#37546d">
        &nbsp;&nbsp;&nbsp;<a target='_new' href='cell://docs-....html'>Click to open help window</a>&nbsp;&nbsp;&nbsp;
        <br></font></tr></td></table></html>
        sage: os.chdir(current_dir)
    """
    from pydoc import resolve, html, describe
    import sagenb.notebook.interact as interact

    print '<html><table notracebacks bgcolor="#386074" cellpadding=10 cellspacing=10><tr><td bgcolor="#f5f5f5"><font color="#37546d">'
    object, name = resolve(obj)
    page = html.page(describe(object), html.document(object, name))
    page = page.replace("<a href", "<a ")
    n = 0
    while True:
        filename = "docs-%s.html" % n
        if not os.path.exists(filename):
            break
        n += 1
    open(filename, "w").write(page)
    print "&nbsp;&nbsp;&nbsp;<a target='_new' href='cell://%s'>Click to open help window</a>&nbsp;&nbsp;&nbsp;" % filename
    print "<br></font></tr></td></table></html>"
开发者ID:regmi,项目名称:femhub-lab,代码行数:43,代码来源:support.py


示例20: document

def document(resource, path):
  print path
  collections = []
  for name in dir(resource):
    if not "_" in name and callable(getattr(resource, name)) and hasattr(
          getattr(resource, name), '__is_resource__'):
      collections.append(name)

  obj, name = pydoc.resolve(type(resource))
  page = pydoc.html.page(
      pydoc.describe(obj), pydoc.html.document(obj, name))

  for name in collections:
    page = re.sub('strong>(%s)<' % name, r'strong><a href="%s">\1</a><' % (path + name + ".html"), page)
  for name in collections:
    document(getattr(resource, name)(), path + name + ".")

  f = open(os.path.join(BASE, path + 'html'), 'w')
  f.write(page)
  f.close()
开发者ID:GeomancerProject,项目名称:Software,代码行数:20,代码来源:describe.py



注:本文中的pydoc.resolve函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python pydoc.splitdoc函数代码示例发布时间:2022-05-25
下一篇:
Python pydoc.render_doc函数代码示例发布时间:2022-05-25
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap