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


Python inspect.iscode方法代码示例

本文整理汇总了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 
开发者ID:SergeySatskiy,项目名称:codimension,代码行数:22,代码来源:cdm_dbg_utils.py

示例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)) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:25,代码来源:test_inspect.py

示例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) 
开发者ID:figment,项目名称:unpyc3,代码行数:23,代码来源:unpyc3.py

示例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)) 
开发者ID:war-and-code,项目名称:jawfish,代码行数:7,代码来源:pydoc.py

示例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__) 
开发者ID:remg427,项目名称:misp42splunk,代码行数:29,代码来源:compat.py

示例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) 
开发者ID:remg427,项目名称:misp42splunk,代码行数:34,代码来源:prepareable.py

示例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 
开发者ID:CityOfZion,项目名称:neo-boa,代码行数:6,代码来源:method.py

示例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 
开发者ID:CityOfZion,项目名称:neo-boa,代码行数:6,代码来源:ast_preprocess.py

示例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 
开发者ID:glmcdona,项目名称:meddle,代码行数:13,代码来源:trace.py

示例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)) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:8,代码来源:fake.py

示例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) 
开发者ID:fabioz,项目名称:PyDev.Debugger,代码行数:30,代码来源:pydevd_code_to_source.py

示例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 {},
    ) 
开发者ID:sqlalchemy,项目名称:dogpile.cache,代码行数:38,代码来源:compat.py

示例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) 
开发者ID:ufora,项目名称:ufora,代码行数:13,代码来源:StdinCache.py


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