本文整理匯總了Python中types.ObjectType方法的典型用法代碼示例。如果您正苦於以下問題:Python types.ObjectType方法的具體用法?Python types.ObjectType怎麽用?Python types.ObjectType使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類types
的用法示例。
在下文中一共展示了types.ObjectType方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: lr_read_tables
# 需要導入模塊: import types [as 別名]
# 或者: from types import ObjectType [as 別名]
def lr_read_tables(module=tab_module,optimize=0):
global _lr_action, _lr_goto, _lr_productions, _lr_method
try:
exec("import %s as parsetab" % module)
global parsetab # declare the name of the imported module
if (optimize) or (Signature.digest() == parsetab._lr_signature):
_lr_action = parsetab._lr_action
_lr_goto = parsetab._lr_goto
_lr_productions = parsetab._lr_productions
_lr_method = parsetab._lr_method
return 1
else:
return 0
except (ImportError,AttributeError):
return 0
# Available instance types. This is used when parsers are defined by a class.
# it's a little funky because I want to preserve backwards compatibility
# with Python 2.0 where types.ObjectType is undefined.
示例2: source_read
# 需要導入模塊: import types [as 別名]
# 或者: from types import ObjectType [as 別名]
def source_read(app, docname, source):
'''Transform the contents of plugins-toolkit.rst to contain reference docs.
'''
# We're only interested in the 'plugins-toolkit' doc (plugins-toolkit.rst).
if docname != 'extensions/plugins-toolkit':
return
source_ = ''
for name, thing in inspect.getmembers(toolkit):
# The plugins toolkit can override the docstrings of some of its
# members (e.g. things that are imported from third-party libraries)
# by putting custom docstrings in this docstring_overrides dict.
custom_docstring = toolkit.docstring_overrides.get(name)
if inspect.isfunction(thing):
source_ += format_function(name, thing, docstring=custom_docstring)
elif inspect.ismethod(thing):
# We document plugins toolkit methods as if they're functions. This
# is correct because the class ckan.plugins.toolkit._Toolkit
# actually masquerades as a module ckan.plugins.toolkit, and you
# call its methods as if they were functions.
source_ += format_function(name, thing, docstring=custom_docstring)
elif inspect.isclass(thing):
source_ += format_class(name, thing, docstring=custom_docstring)
elif isinstance(thing, types.ObjectType):
source_ += format_object(name, thing, docstring=custom_docstring)
else:
assert False, ("Someone added {name}:{thing} to the plugins "
"toolkit and this Sphinx extension doesn't know "
"how to document that yet. If you're that someone, "
"you need to add a new format_*() function for it "
"here or the docs won't build.".format(
name=name, thing=thing))
source[0] += source_
# This is useful for debugging the generated RST.
#open('/tmp/source', 'w').write(source[0])
示例3: help
# 需要導入模塊: import types [as 別名]
# 或者: from types import ObjectType [as 別名]
def help(obj = None):
"""help(object) prints out help for object, e.g. help(modem)"""
if obj is not None :
sep='\n'
if isinstance(obj, (types.FunctionType)):
if obj.__doc__ is None :
iofun.out("No documentation for \"" +
obj.__name__ + "\"")
return
iofun.out(obj.__doc__)
elif isinstance(obj, (types.ClassType, types.ObjectType)):
if obj.__doc__ is None :
iofun.out("No documentation for \"" +
obj.__class__.__name__ + "\"")
return
iofun.out(obj.__doc__)
docList = [getattr(obj, method).__doc__ for method in dir(obj) if callable(getattr(obj, method)) and getattr(obj, method).__doc__]
if len(docList) == 0:
return
maxMethodLen = max([len(doc.split(sep)[0]) for doc in docList])
iofun.out("\n".join(["%s %s" %
(doc.split(sep)[0].ljust(maxMethodLen + 1),
" ".join(doc.split(sep)[1:]).strip())
for doc in docList]))
else:
out("-------Welcome to the Insteon Terminal-------")
out("to get a list of available functions, type '?'")
out("to get help, type help(funcName) or help(objectName)")
out("for example: help(Modem2413U)")
out("to quit, type 'quit()'")
示例4: _curry_callable
# 需要導入模塊: import types [as 別名]
# 或者: from types import ObjectType [as 別名]
def _curry_callable(obj, *args, **kwargs):
"""Takes a callable and arguments and returns a task queue tuple.
The returned tuple consists of (callable, args, kwargs), and can be pickled
and unpickled safely.
Args:
obj: The callable to curry. See the module docstring for restrictions.
args: Positional arguments to call the callable with.
kwargs: Keyword arguments to call the callable with.
Returns:
A tuple consisting of (callable, args, kwargs) that can be evaluated by
run() with equivalent effect of executing the function directly.
Raises:
ValueError: If the passed in object is not of a valid callable type.
"""
if isinstance(obj, types.MethodType):
return (invoke_member, (obj.im_self, obj.im_func.__name__) + args, kwargs)
elif isinstance(obj, types.BuiltinMethodType):
if not obj.__self__:
return (obj, args, kwargs)
else:
return (invoke_member, (obj.__self__, obj.__name__) + args, kwargs)
elif isinstance(obj, types.ObjectType) and hasattr(obj, "__call__"):
return (obj, args, kwargs)
elif isinstance(obj, (types.FunctionType, types.BuiltinFunctionType,
types.ClassType, types.UnboundMethodType)):
return (obj, args, kwargs)
else:
raise ValueError("obj must be callable")