本文整理匯總了Python中inspect.iscode方法的典型用法代碼示例。如果您正苦於以下問題:Python inspect.iscode方法的具體用法?Python inspect.iscode怎麽用?Python inspect.iscode使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類inspect
的用法示例。
在下文中一共展示了inspect.iscode方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: _getfullargs
# 需要導入模塊: import inspect [as 別名]
# 或者: from inspect import iscode [as 別名]
def _getfullargs(co):
"""Provides information about the arguments accepted by a code object"""
if not iscode(co):
raise TypeError('{0!r} is not a code object'.format(co))
nargs = co.co_argcount
names = co.co_varnames
nkwargs = co.co_kwonlyargcount
args = list(names[:nargs])
kwonlyargs = list(names[nargs:nargs + nkwargs])
nargs += nkwargs
varargs = None
if co.co_flags & CO_VARARGS:
varargs = co.co_varnames[nargs]
nargs = nargs + 1
varkw = None
if co.co_flags & CO_VARKEYWORDS:
varkw = co.co_varnames[nargs]
return args, varargs, kwonlyargs, varkw
示例2: test_excluding_predicates
# 需要導入模塊: import inspect [as 別名]
# 或者: from inspect import iscode [as 別名]
def test_excluding_predicates(self):
self.istest(inspect.isbuiltin, 'sys.exit')
self.istest(inspect.isbuiltin, '[].append')
self.istest(inspect.iscode, 'mod.spam.func_code')
self.istest(inspect.isframe, 'tb.tb_frame')
self.istest(inspect.isfunction, 'mod.spam')
self.istest(inspect.ismethod, 'mod.StupidGit.abuse')
self.istest(inspect.ismethod, 'git.argue')
self.istest(inspect.ismodule, 'mod')
self.istest(inspect.istraceback, 'tb')
self.istest(inspect.isdatadescriptor, '__builtin__.file.closed')
self.istest(inspect.isdatadescriptor, '__builtin__.file.softspace')
self.istest(inspect.isgenerator, '(x for x in xrange(2))')
self.istest(inspect.isgeneratorfunction, 'generator_function_example')
if hasattr(types, 'GetSetDescriptorType'):
self.istest(inspect.isgetsetdescriptor,
'type(tb.tb_frame).f_locals')
else:
self.assertFalse(inspect.isgetsetdescriptor(type(tb.tb_frame).f_locals))
if hasattr(types, 'MemberDescriptorType'):
self.istest(inspect.ismemberdescriptor, 'datetime.timedelta.days')
else:
self.assertFalse(inspect.ismemberdescriptor(datetime.timedelta.days))
示例3: decompile
# 需要導入模塊: import inspect [as 別名]
# 或者: from inspect import iscode [as 別名]
def decompile(obj):
"""
Decompile obj if it is a module object, a function or a
code object. If obj is a string, it is assumed to be the path
to a python module.
"""
if isinstance(obj, str):
return dec_module(obj)
if inspect.iscode(obj):
code = Code(obj)
return code.get_suite()
if inspect.isfunction(obj):
code = Code(obj.__code__)
defaults = obj.__defaults__
kwdefaults = obj.__kwdefaults__
return DefStatement(code, defaults, kwdefaults, obj.__closure__)
elif inspect.ismodule(obj):
return dec_module(obj.__file__)
else:
msg = "Object must be string, module, function or code object"
raise TypeError(msg)
示例4: isdata
# 需要導入模塊: import inspect [as 別名]
# 或者: from inspect import iscode [as 別名]
def isdata(object):
"""Check if an object is of a type that probably means it's data."""
return not (inspect.ismodule(object) or inspect.isclass(object) or
inspect.isroutine(object) or inspect.isframe(object) or
inspect.istraceback(object) or inspect.iscode(object))
示例5: inspect_getargspec
# 需要導入模塊: import inspect [as 別名]
# 或者: from inspect import iscode [as 別名]
def inspect_getargspec(func):
"""getargspec based on fully vendored getfullargspec from Python 3.3."""
if inspect.ismethod(func):
func = func.__func__
if not inspect.isfunction(func):
raise TypeError("{!r} is not a Python function".format(func))
co = func.__code__
if not inspect.iscode(co):
raise TypeError("{!r} is not a code object".format(co))
nargs = co.co_argcount
names = co.co_varnames
nkwargs = co.co_kwonlyargcount if py3k else 0
args = list(names[:nargs])
nargs += nkwargs
varargs = None
if co.co_flags & inspect.CO_VARARGS:
varargs = co.co_varnames[nargs]
nargs = nargs + 1
varkw = None
if co.co_flags & inspect.CO_VARKEYWORDS:
varkw = co.co_varnames[nargs]
return ArgSpec(args, varargs, varkw, func.__defaults__)
示例6: __new__
# 需要導入模塊: import inspect [as 別名]
# 或者: from inspect import iscode [as 別名]
def __new__(cls, name, bases, attributes):
try:
constructor = attributes["__new__"]
except KeyError:
return type.__new__(cls, name, bases, attributes)
def preparing_constructor(cls, name, bases, attributes):
try:
cls.__prepare__
except AttributeError:
return constructor(cls, name, bases, attributes)
namespace = cls.__prepare__(name, bases)
defining_frame = sys._getframe(1)
for constant in reversed(defining_frame.f_code.co_consts):
if inspect.iscode(constant) and constant.co_name == name:
def get_index(attribute_name, _names=constant.co_names):
try:
return _names.index(attribute_name)
except ValueError:
return 0
break
else:
return constructor(cls, name, bases, attributes)
by_appearance = sorted(
attributes.items(), key=lambda item: get_index(item[0])
)
for key, value in by_appearance:
namespace[key] = value
return constructor(cls, name, bases, namespace)
attributes["__new__"] = wraps(constructor)(preparing_constructor)
return type.__new__(cls, name, bases, attributes)
示例7: get_code_block_index
# 需要導入模塊: import inspect [as 別名]
# 或者: from inspect import iscode [as 別名]
def get_code_block_index(self, blocks):
for index, block in enumerate(blocks):
if inspect.iscode(block.arg):
return index
示例8: get_code_block
# 需要導入模塊: import inspect [as 別名]
# 或者: from inspect import iscode [as 別名]
def get_code_block(blocks):
for block in blocks:
if inspect.iscode(block.arg):
return block
示例9: find_lines
# 需要導入模塊: import inspect [as 別名]
# 或者: from inspect import iscode [as 別名]
def find_lines(code, strs):
"""Return lineno dict for all code objects reachable from code."""
# get all of the lineno information from the code of this scope level
linenos = find_lines_from_code(code, strs)
# and check the constants for references to other code objects
for c in code.co_consts:
if inspect.iscode(c):
# find another code object, so recurse into it
linenos.update(find_lines(c, strs))
return linenos
示例10: is_class_instance
# 需要導入模塊: import inspect [as 別名]
# 或者: from inspect import iscode [as 別名]
def is_class_instance(obj):
"""Like inspect.* methods."""
return not (inspect.isclass(obj) or inspect.ismodule(obj)
or inspect.isbuiltin(obj) or inspect.ismethod(obj)
or inspect.ismethoddescriptor(obj) or inspect.iscode(obj)
or inspect.isgenerator(obj))
示例11: __init__
# 需要導入模塊: import inspect [as 別名]
# 或者: from inspect import iscode [as 別名]
def __init__(self, i_line, instruction=None, tok=_SENTINEL, priority=0, after=None, end_of_line=False):
'''
:param i_line:
:param instruction:
:param tok:
:param priority:
:param after:
:param end_of_line:
Marker to signal only after all the other tokens have been written.
'''
self.i_line = i_line
if tok is not _SENTINEL:
self.tok = tok
else:
if instruction is not None:
if inspect.iscode(instruction.argval):
self.tok = ''
else:
self.tok = str(instruction.argval)
else:
raise AssertionError('Either the tok or the instruction is needed.')
self.instruction = instruction
self.priority = priority
self.end_of_line = end_of_line
self._after_tokens = set()
self._after_handler_tokens = set()
if after:
self.mark_after(after)
示例12: inspect_getfullargspec
# 需要導入模塊: import inspect [as 別名]
# 或者: from inspect import iscode [as 別名]
def inspect_getfullargspec(func):
"""Fully vendored version of getfullargspec from Python 3.3."""
if inspect.ismethod(func):
func = func.__func__
if not inspect.isfunction(func):
raise TypeError("{!r} is not a Python function".format(func))
co = func.__code__
if not inspect.iscode(co):
raise TypeError("{!r} is not a code object".format(co))
nargs = co.co_argcount
names = co.co_varnames
nkwargs = co.co_kwonlyargcount if py3k else 0
args = list(names[:nargs])
kwonlyargs = list(names[nargs : nargs + nkwargs])
nargs += nkwargs
varargs = None
if co.co_flags & inspect.CO_VARARGS:
varargs = co.co_varnames[nargs]
nargs = nargs + 1
varkw = None
if co.co_flags & inspect.CO_VARKEYWORDS:
varkw = co.co_varnames[nargs]
return FullArgSpec(
args,
varargs,
varkw,
func.__defaults__,
kwonlyargs,
func.__kwdefaults__ if py3k else None,
func.__annotations__ if py3k else {},
)
示例13: registerCodeObject
# 需要導入模塊: import inspect [as 別名]
# 或者: from inspect import iscode [as 別名]
def registerCodeObject(self, codeObject, codeObjectLineNumberBase):
if codeObject.co_code not in self.codeStringToCodeObjectsAndLineNumber:
self.codeStringToCodeObjectsAndLineNumber[codeObject.co_code] = []
self.codeStringToCodeObjectsAndLineNumber[codeObject.co_code].append(
(codeObject, codeObjectLineNumberBase + codeObject.co_firstlineno-1)
)
for child in codeObject.co_consts:
if inspect.iscode(child):
self.registerCodeObject(child, codeObjectLineNumberBase)