当前位置: 首页>>代码示例>>Python>>正文


Python pydoc.resolve函数代码示例

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


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


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