python类resolve()的实例源码

commands.py 文件源码 项目:vspheretools 作者: devopshq 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
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'
commands.py 文件源码 项目:vspheretools 作者: devopshq 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
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
sphinx_fakeinv_test.py 文件源码 项目:sphinx-fakeinv 作者: dahlia 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def import_string(import_path):
    m, _ = pydoc.resolve(import_path)
    return m


问题


面经


文章

微信
公众号

扫码关注公众号