本文整理汇总了Python中pydoc.splitdoc函数的典型用法代码示例。如果您正苦于以下问题:Python splitdoc函数的具体用法?Python splitdoc怎么用?Python splitdoc使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了splitdoc函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: splitdocfor
def splitdocfor(path):
"""split the docstring for a path
valid paths are::
./path/to/module.py
./path/to/module.py:SomeClass.method
returns (description, long_description) from the docstring for path
or (None, None) if there isn't a docstring.
Example::
>>> splitdocfor("./wsgi_intercept/__init__.py")[0]
'installs a WSGI application in place of a real URI for testing.'
>>> splitdocfor("./wsgi_intercept/__init__.py:WSGI_HTTPConnection.get_app")[0]
'Return the app object for the given (host, port).'
>>>
"""
if ":" in path:
filename, objpath = path.split(':')
else:
filename, objpath = path, None
inspector = DocInspector(filename)
visitor.walk(compiler.parseFile(filename), inspector)
if objpath is None:
if inspector.top_level_doc is None:
return None, None
return pydoc.splitdoc(inspector.top_level_doc)
else:
if inspector[objpath] is None:
return None, None
return pydoc.splitdoc(inspector[objpath])
示例2: main
def main():
usage = __import__(__name__).__doc__.strip()
usage += "\n\nCommands:\n\n"
commands = {}
for func in sorted(COMMANDS):
name = func.__name__.strip().replace("cmd_", "").replace("_", "-")
commands[name] = func
head, tail = pydoc.splitdoc(pydoc.getdoc(func))
cmd_help = textwrap.fill(tail, width=70).replace("\n", "\n ").strip()
usage += "%s\n %s\n\n" % (head, cmd_help)
usage = usage.strip()
parser = OptionParser(usage=usage)
parser.allow_interspersed_args = False
(options, args) = parser.parse_args()
if len(args) < 1:
parser.error("No command given")
cmd_name = args.pop(0)
cmd = commands.get(cmd_name)
if cmd is None:
parser.error("Unknown command %s" % cmd_name)
else:
cmd(args)
示例3: get_module_meta
def get_module_meta(modfile):
docstring = None
version = [(tokenize.NAME, '__version__'), (tokenize.OP, '=')]
f = open(modfile,'r')
for toknum, tokval, _, _, _ in tokenize.generate_tokens(lambda: f.readline()):
if not docstring:
if toknum == tokenize.STRING:
docstring = tokval
continue
if len(version):
if (toknum, tokval) == version[0]:
version.pop(0)
else:
version = tokval
break
if docstring is None:
raise ValueError("could not find docstring in %s" % modfile)
if not isinstance(version, basestring):
raise ValueError("could not find __version__ in %s" % modfile)
# unquote :
docstring = docstring[3:]
docstring = docstring[:-3]
version = version[1:]
version = version[:-1]
return (version,) + pydoc.splitdoc(docstring)
示例4: setup
def setup(args=None):
# make sure our directory is at the front of sys.path
module = metadata('backupmgr')
# get the version and description from the source
version = module.__version__
description = pydoc.splitdoc(pydoc.getdoc(module))[0]
author, author_email = email.utils.parseaddr(module.__authors__[0])
# get the long description from README-type files
long_description = []
for path in READMES:
with open(os.path.join(SRCROOT, path), 'r') as fh:
long_description.append(fh.read())
long_description = '\n'.join([ x for x in long_description if x ])
# use setuptools to do the rest
setuptools.setup(
name=pkg_resources.safe_name(module.__name__),
packages=setuptools.find_packages(),
version=version,
description=description,
author=author,
author_email=author_email,
zip_safe=True,
#url=None,
install_requires=["python-dateutil"],
long_description=long_description,
license='BSD',
classifiers=[
'Development Status :: 3 - Alpha',
'Intended Audience :: Developers'
])
示例5: hh
def hh(cmd = None):
"""Get help on a command."""
shell_funcs['hh'] = hh
import pydoc
from inspect import getargspec, formatargspec
if not cmd:
print "\nUse self.addrspace for Kernel/Virtual AS"
print "Use self.addrspace.base for Physical AS"
print "Use self.proc to get the current _EPROCESS object"
print " and self.proc.get_process_address_space() for the current process AS"
print " and self.proc.get_load_modules() for the current process DLLs\n"
for f in sorted(shell_funcs):
doc = pydoc.getdoc(shell_funcs[f])
synop, _full = pydoc.splitdoc(doc)
print "{0:40} : {1}".format(f + formatargspec(*getargspec(shell_funcs[f])), synop)
print "\nFor help on a specific command, type 'hh(<command>)'"
elif type(cmd) == str:
try:
doc = pydoc.getdoc(shell_funcs[cmd])
except KeyError:
print "No such command: {0}".format(cmd)
return
print doc
else:
doc = pydoc.getdoc(cmd)
print doc
示例6: module_section
def module_section(self, obj, package_context ):
"""Create a module-links section for the given object (module)"""
modules = inspect.getmembers(obj, inspect.ismodule)
package_context.clean(modules, obj)
package_context.recurse_scan(modules)
if hasattr(obj, '__path__'):
modpkgs = []
modnames = []
for file in os.listdir(obj.__path__[0]):
path = os.path.join(obj.__path__[0], file)
modname = inspect.getmodulename(file)
if modname and modname not in modnames:
modpkgs.append((modname, obj.__name__, 0, 0))
modnames.append(modname)
elif pydoc.ispackage(path):
modpkgs.append((file, obj.__name__, 1, 0))
modpkgs.sort()
# do more recursion here...
for (modname, name, ya, yo) in modpkgs:
package_context.add_interesting('.'.join((obj.__name__, modname)))
items = []
for (modname, name, ispackage, is_shadowed) in modpkgs:
try:
# get the actual module obj...
#if modname == "events":
# import pdb
# pdb.set_trace()
module = pydoc.safeimport('{0}.{1}'.format(name, modname))
description, documentation = pydoc.splitdoc(inspect.getdoc(module))
if description:
items.append(
'{0} -- {1}'.format(
self.modpkglink((modname, name, ispackage, is_shadowed)),
description,
)
)
else:
items.append(
self.modpkglink((modname, name, ispackage, is_shadowed))
)
except:
items.append(
self.modpkglink((modname, name, ispackage, is_shadowed))
)
contents = '<br>'.join(items)
result = self.bigsection(
'Package Contents', '#ffffff', '#aa55cc', contents)
elif modules:
contents = self.multicolumn(
modules,
lambda a: self.modulelink(a[1])
)
result = self.bigsection(
'Modules', '#fffff', '#aa55cc', contents)
else:
result = ""
return result
示例7: moduleSection
def moduleSection( self, object, packageContext ):
"""Create a module-links section for the given object (module)"""
modules = inspect.getmembers(object, inspect.ismodule)
packageContext.clean ( modules, object )
packageContext.recurseScan( modules )
if hasattr(object, '__path__'):
modpkgs = []
modnames = []
for file in os.listdir(object.__path__[0]):
path = os.path.join(object.__path__[0], file)
modname = inspect.getmodulename(file)
if modname and modname not in modnames:
modpkgs.append((modname, object.__name__, 0, 0))
modnames.append(modname)
elif pydoc.ispackage(path):
modpkgs.append((file, object.__name__, 1, 0))
modpkgs.sort()
# do more recursion here...
for (modname, name, ya,yo) in modpkgs:
packageContext.addInteresting( join( (object.__name__, modname), '.'))
items = []
for (modname, name, ispackage,isshadowed) in modpkgs:
try:
# get the actual module object...
## if modname == "events":
## import pdb
## pdb.set_trace()
module = pydoc.safeimport( "%s.%s"%(name,modname) )
description, documentation = pydoc.splitdoc( inspect.getdoc( module ))
if description:
items.append(
"""%s -- %s"""% (
self.modpkglink( (modname, name, ispackage, isshadowed) ),
description,
)
)
else:
items.append(
self.modpkglink( (modname, name, ispackage, isshadowed) )
)
except:
items.append(
self.modpkglink( (modname, name, ispackage, isshadowed) )
)
contents = string.join( items, '<br>')
result = self.bigsection(
'Package Contents', '#ffffff', '#aa55cc', contents)
elif modules:
contents = self.multicolumn(
modules, lambda (key, value), s=self: s.modulelink(value))
result = self.bigsection(
'Modules', '#fffff', '#aa55cc', contents)
else:
result = ""
return result
示例8: formatDocString
def formatDocString(self, doc):
doc = pydoc.splitdoc(doc)
bodylines = doc[1].splitlines()
body = ""
for idx, line in enumerate(bodylines):
if len(line) == 0:
body += "\n"
body += line.strip() + " "
ret = "%s\n\n%s" % (doc[0], body)
return ret.strip()
示例9: get_module_meta
def get_module_meta(modfile):
ast = compiler.parseFile(modfile)
modnode = ModuleVisitor()
visitor.walk(ast, modnode)
if modnode.mod_doc is None:
raise RuntimeError(
"could not parse doc string from %s" % modfile)
if modnode.mod_version is None:
raise RuntimeError(
"could not parse __version__ from %s" % modfile)
return (modnode.mod_version,) + pydoc.splitdoc(modnode.mod_doc)
示例10: build_help_cb
def build_help_cb(bot, *args, **kwargs):
'''
Build the help overview so it can be cached and poked at from shell.
'''
global HELP_OVERVIEW
HELP_OVERVIEW += 'Available commands:\n'
for category in sorted(COMMAND_CATEGORIES):
if category:
HELP_OVERVIEW += '- {}:\n'.format(category)
for command in sorted(COMMAND_CATEGORIES[category]):
HELP_OVERVIEW += '{}: {}\n'.format(
command[0], pydoc.splitdoc(command[2].__doc__)[0])
示例11: _default_optparse
def _default_optparse(cmd, args, option_list=[], indoc=False, outfile=False,
nargs=None, syspath=False):
if indoc:
option_list += [
make_option("-i", action="store", dest="infile", type="str",
help="input file, '-' means stdin, '--' means empty input file (default)",
default="--")
]
if outfile:
option_list += [
make_option("-o", action="store", dest="outfile", type="str",
help="output file, '-' means stdout (default)",
default="-")
]
if syspath:
option_list += [
make_option("-s", "--sys-path", action="store", dest="path",
type="str", default=None,
help="prepend paths to sys.path")
]
head, tail = pydoc.splitdoc(pydoc.getdoc(cmd))
p = OptionParser(usage="pydoc-tool.py %s\n\n%s" % (head, tail),
option_list=option_list)
opts, args = p.parse_args(args)
if nargs is not None:
if len(args) != nargs:
p.error("wrong number of arguments")
if outfile:
if opts.outfile == '-':
opts.outfile = sys.stdout
else:
opts.outfile = open(opts.outfile, 'w')
if indoc:
if opts.infile == '--':
opts.indoc = Documentation()
elif opts.infile == '-':
opts.indoc = Documentation.load(sys.stdin)
else:
opts.indoc = Documentation.load(open(opts.infile, 'r'))
if syspath:
if opts.path is not None:
sys.path = [os.path.abspath(x)
for x in opts.path.split(os.path.pathsep)] + sys.path
return opts, args, p
示例12: split_doc_from_module
def split_doc_from_module(modfile):
docstring = None
f = open(modfile,'r')
for toknum, tokval, _, _, _ in tokenize.generate_tokens(lambda: f.readline()):
if toknum == tokenize.STRING:
docstring = tokval
break
if toknum not in (tokenize.NL, tokenize.COMMENT):
# we went too far
break
if docstring is None:
raise ValueError("could not find docstring in %s" % modfile)
docstring = docstring[3:]
docstring = docstring[:-3]
return pydoc.splitdoc(docstring)
示例13: hh
def hh(cmd = None):
"""Get help on a command."""
shell_funcs['hh'] = hh
import pydoc
from inspect import getargspec, formatargspec
if not cmd:
for f in shell_funcs:
doc = pydoc.getdoc(shell_funcs[f])
synop, _full = pydoc.splitdoc(doc)
print("{0:40} : {1}".format(f + formatargspec(*getargspec(shell_funcs[f])), synop))
print()
print("For help on a specific command, type 'hh(<command>)'")
elif type(cmd) == str:
try:
doc = pydoc.getdoc(shell_funcs[cmd])
except KeyError:
print("No such command: {0}".format(cmd))
return
print(doc)
else:
doc = pydoc.getdoc(cmd)
print(doc)
示例14: makedocindex
def makedocindex():
"""
Return a string with GPI Index.
"""
import pydoc
sections = {}
from Ganga.Utility.strings import ItemizedTextParagraph
for sec, names in zip(_GPIhelp_sections.keys(), _GPIhelp_sections.values()):
itbuf = ItemizedTextParagraph(sec + ":")
for name, obj, docstring in names:
# if docstring not provided when exporting the object to GPI then use the docstring generated by pydoc
if not docstring:
docstring = pydoc.splitdoc(pydoc.getdoc(obj))[0]
itbuf.addLine(name, docstring)
sections[sec] = itbuf.getString()
return _GPIhelp % sections
示例15: hh
def hh(cmd=None):
"""Get help on a command."""
shell_funcs['hh'] = hh
import pydoc
from inspect import getargspec, formatargspec
if not cmd:
for f in shell_funcs:
doc = pydoc.getdoc(shell_funcs[f])
synop, full = pydoc.splitdoc(doc)
print "%-40s : %s" % (f + formatargspec(*getargspec(shell_funcs[f])), synop)
print
print "For help on a specific command, type 'hh(<command>)'"
elif type(cmd) == str:
try:
doc = pydoc.getdoc(shell_funcs[cmd])
except KeyError:
print "No such command: %s" % cmd
return
print doc
else:
doc = pydoc.getdoc(cmd)
print doc