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


Python types.FrameType方法代码示例

本文整理汇总了Python中types.FrameType方法的典型用法代码示例。如果您正苦于以下问题:Python types.FrameType方法的具体用法?Python types.FrameType怎么用?Python types.FrameType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在types的用法示例。


在下文中一共展示了types.FrameType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _skip_frame_predicates

# 需要导入模块: import types [as 别名]
# 或者: from types import FrameType [as 别名]
def _skip_frame_predicates(self):
    """A tuple of predicate functions to decide whether or not to skip a given
    frame for warning attribution. The predicates are connected with logic OR,
    meaning that if one of the predicates says to skip, the frame will be
    skipped. A predicate function will have signature as follows.

    Args:
      * name (str) - Fully qualified warning name e.g. 'repo/WARNING_NAME'
      * index (int) - The index of the provided frame in call stack. Outer
      frame has larger index.
      * frame (types.FrameType) - A frame in call stack that the predicate
      function is currently evaluating against

    Returns a human-readable reason (str) why the given frame should be skipped.
    Returns None if the warning can be attributed to the given frame.
    """
    return (
      # Skip the first frame as it is where the warning is being issued
      lambda name, index, frame: 'warning issued frame' if index == 0 else None,
      self._non_recipe_code_predicate,
      escape_warning_predicate
    ) 
开发者ID:luci,项目名称:recipes-py,代码行数:24,代码来源:record.py

示例2: interpret

# 需要导入模块: import types [as 别名]
# 或者: from types import FrameType [as 别名]
def interpret(source, frame, should_fail=False):
    module = Interpretable(parse(source, 'exec').node)
    #print "got module", module
    if isinstance(frame, types.FrameType):
        frame = py.code.Frame(frame)
    try:
        module.run(frame)
    except Failure:
        e = sys.exc_info()[1]
        return getfailure(e)
    except passthroughex:
        raise
    except:
        import traceback
        traceback.print_exc()
    if should_fail:
        return ("(assertion failed, but when it was re-run for "
                "printing intermediate values, it did not fail.  Suggestions: "
                "compute assert expression before the assert or use --nomagic)")
    else:
        return None 
开发者ID:pytest-dev,项目名称:py,代码行数:23,代码来源:_assertionold.py

示例3: isframe

# 需要导入模块: import types [as 别名]
# 或者: from types import FrameType [as 别名]
def isframe(object):
    """Return true if the object is a frame object.

    Frame objects provide these attributes:
        f_back          next outer frame object (this frame's caller)
        f_builtins      built-in namespace seen by this frame
        f_code          code object being executed in this frame
        f_exc_traceback traceback if raised in this frame, or None
        f_exc_type      exception type if raised in this frame, or None
        f_exc_value     exception value if raised in this frame, or None
        f_globals       global namespace seen by this frame
        f_lasti         index of last attempted instruction in bytecode
        f_lineno        current line number in Python source code
        f_locals        local namespace seen by this frame
        f_restricted    0 or 1 if frame is in restricted execution mode
        f_trace         tracing function for this frame, or None"""
    return isinstance(object, types.FrameType) 
开发者ID:glmcdona,项目名称:meddle,代码行数:19,代码来源:inspect.py

示例4: short_repr

# 需要导入模块: import types [as 别名]
# 或者: from types import FrameType [as 别名]
def short_repr(obj):
    if isinstance(obj, (type, types.ModuleType, types.BuiltinMethodType,
                        types.BuiltinFunctionType)):
        return obj.__name__
    if isinstance(obj, types.MethodType):
        try:
            if obj.__self__ is not None:
                return obj.__func__.__name__ + ' (bound)'
            else:
                return obj.__func__.__name__
        except AttributeError:
            # Python < 2.6 compatibility
            if obj.im_self is not None:
                return obj.im_func.__name__ + ' (bound)'
            else:
                return obj.im_func.__name__

    if isinstance(obj, types.FrameType):
        return '%s:%s' % (obj.f_code.co_filename, obj.f_lineno)
    if isinstance(obj, (tuple, list, dict, set)):
        return '%d items' % len(obj)
    return repr(obj)[:40] 
开发者ID:Exa-Networks,项目名称:exaddos,代码行数:24,代码来源:objgraph.py

示例5: should_hide_frame

# 需要导入模块: import types [as 别名]
# 或者: from types import FrameType [as 别名]
def should_hide_frame(frame):
    # type: (FrameType) -> bool
    try:
        mod = frame.f_globals["__name__"]
        if mod.startswith("sentry_sdk."):
            return True
    except (AttributeError, KeyError):
        pass

    for flag_name in "__traceback_hide__", "__tracebackhide__":
        try:
            if frame.f_locals[flag_name]:
                return True
        except Exception:
            pass

    return False 
开发者ID:getsentry,项目名称:sentry-python,代码行数:19,代码来源:utils.py

示例6: get_source_context

# 需要导入模块: import types [as 别名]
# 或者: from types import FrameType [as 别名]
def get_source_context(
    frame,  # type: FrameType
    tb_lineno,  # type: int
):
    # type: (...) -> Tuple[List[Annotated[str]], Optional[Annotated[str]], List[Annotated[str]]]
    try:
        abs_path = frame.f_code.co_filename  # type: Optional[str]
    except Exception:
        abs_path = None
    try:
        module = frame.f_globals["__name__"]
    except Exception:
        return [], None, []
    try:
        loader = frame.f_globals["__loader__"]
    except Exception:
        loader = None
    lineno = tb_lineno - 1
    if lineno is not None and abs_path:
        return get_lines_from_file(abs_path, lineno, loader, module)
    return [], None, [] 
开发者ID:getsentry,项目名称:sentry-python,代码行数:23,代码来源:utils.py

示例7: emit

# 需要导入模块: import types [as 别名]
# 或者: from types import FrameType [as 别名]
def emit(self, record: logging.LogRecord) -> None:  # pragma: no cover
        # Get corresponding Loguru level if it exists
        try:
            level = logger.level(record.levelname).name
        except ValueError:
            level = str(record.levelno)

        # Find caller from where originated the logged message
        frame, depth = logging.currentframe(), 2
        while frame.f_code.co_filename == logging.__file__:  # noqa: WPS609
            frame = cast(FrameType, frame.f_back)
            depth += 1

        logger.opt(depth=depth, exception=record.exc_info).log(
            level, record.getMessage(),
        ) 
开发者ID:nsidnev,项目名称:fastapi-realworld-example-app,代码行数:18,代码来源:logging.py

示例8: test_frame_getargs

# 需要导入模块: import types [as 别名]
# 或者: from types import FrameType [as 别名]
def test_frame_getargs() -> None:
    def f1(x) -> FrameType:
        return sys._getframe(0)

    fr1 = Frame(f1("a"))
    assert fr1.getargs(var=True) == [("x", "a")]

    def f2(x, *y) -> FrameType:
        return sys._getframe(0)

    fr2 = Frame(f2("a", "b", "c"))
    assert fr2.getargs(var=True) == [("x", "a"), ("y", ("b", "c"))]

    def f3(x, **z) -> FrameType:
        return sys._getframe(0)

    fr3 = Frame(f3("a", b="c"))
    assert fr3.getargs(var=True) == [("x", "a"), ("z", {"b": "c"})]

    def f4(x, *y, **z) -> FrameType:
        return sys._getframe(0)

    fr4 = Frame(f4("a", "b", c="d"))
    assert fr4.getargs(var=True) == [("x", "a"), ("y", ("b",)), ("z", {"c": "d"})] 
开发者ID:pytest-dev,项目名称:pytest,代码行数:26,代码来源:test_code.py

示例9: isframe

# 需要导入模块: import types [as 别名]
# 或者: from types import FrameType [as 别名]
def isframe(object):
    """Return true if the object is a frame object.

    Frame objects provide these attributes:
        f_back          next outer frame object (this frame's caller)
        f_builtins      built-in namespace seen by this frame
        f_code          code object being executed in this frame
        f_globals       global namespace seen by this frame
        f_lasti         index of last attempted instruction in bytecode
        f_lineno        current line number in Python source code
        f_locals        local namespace seen by this frame
        f_trace         tracing function for this frame, or None"""
    return isinstance(object, types.FrameType) 
开发者ID:war-and-code,项目名称:jawfish,代码行数:15,代码来源:inspect.py

示例10: getlineno

# 需要导入模块: import types [as 别名]
# 或者: from types import FrameType [as 别名]
def getlineno(frame):
    """Get the line number from a frame object, allowing for optimization."""
    # FrameType.f_lineno is now a descriptor that grovels co_lnotab
    return frame.f_lineno 
开发者ID:war-and-code,项目名称:jawfish,代码行数:6,代码来源:inspect.py

示例11: is_internal_attribute

# 需要导入模块: import types [as 别名]
# 或者: from types import FrameType [as 别名]
def is_internal_attribute(obj, attr):
    """Test if the attribute given is an internal python attribute.  For
    example this function returns `True` for the `func_code` attribute of
    python objects.  This is useful if the environment method
    :meth:`~SandboxedEnvironment.is_safe_attribute` is overridden.

    >>> from jinja2.sandbox import is_internal_attribute
    >>> is_internal_attribute(str, "mro")
    True
    >>> is_internal_attribute(str, "upper")
    False
    """
    if isinstance(obj, types.FunctionType):
        if attr in UNSAFE_FUNCTION_ATTRIBUTES:
            return True
    elif isinstance(obj, types.MethodType):
        if attr in UNSAFE_FUNCTION_ATTRIBUTES or \
           attr in UNSAFE_METHOD_ATTRIBUTES:
            return True
    elif isinstance(obj, type):
        if attr == 'mro':
            return True
    elif isinstance(obj, (types.CodeType, types.TracebackType, types.FrameType)):
        return True
    elif isinstance(obj, types.GeneratorType):
        if attr in UNSAFE_GENERATOR_ATTRIBUTES:
            return True
    elif hasattr(types, 'CoroutineType') and isinstance(obj, types.CoroutineType):
        if attr in UNSAFE_COROUTINE_ATTRIBUTES:
            return True
    elif hasattr(types, 'AsyncGeneratorType') and isinstance(obj, types.AsyncGeneratorType):
        if attr in UNSAFE_ASYNC_GENERATOR_ATTRIBUTES:
            return True
    return attr.startswith('__') 
开发者ID:remg427,项目名称:misp42splunk,代码行数:36,代码来源:sandbox.py

示例12: is_internal_attribute

# 需要导入模块: import types [as 别名]
# 或者: from types import FrameType [as 别名]
def is_internal_attribute(obj, attr):
    """Test if the attribute given is an internal python attribute.  For
    example this function returns `True` for the `func_code` attribute of
    python objects.  This is useful if the environment method
    :meth:`~SandboxedEnvironment.is_safe_attribute` is overridden.

    >>> from jinja2.sandbox import is_internal_attribute
    >>> is_internal_attribute(str, "mro")
    True
    >>> is_internal_attribute(str, "upper")
    False
    """
    if isinstance(obj, types.FunctionType):
        if attr in UNSAFE_FUNCTION_ATTRIBUTES:
            return True
    elif isinstance(obj, types.MethodType):
        if attr in UNSAFE_FUNCTION_ATTRIBUTES or \
           attr in UNSAFE_METHOD_ATTRIBUTES:
            return True
    elif isinstance(obj, type):
        if attr == 'mro':
            return True
    elif isinstance(obj, (types.CodeType, types.TracebackType, types.FrameType)):
        return True
    elif isinstance(obj, types.GeneratorType):
        if attr in UNSAFE_GENERATOR_ATTRIBUTES:
            return True
    return attr.startswith('__') 
开发者ID:jpush,项目名称:jbox,代码行数:30,代码来源:sandbox.py

示例13: edge_label

# 需要导入模块: import types [as 别名]
# 或者: from types import FrameType [as 别名]
def edge_label(source, target):
    if isinstance(target, dict) and target is getattr(source, '__dict__', None):
        return ' [label="__dict__",weight=10]'
    if isinstance(source, types.FrameType):
        if target is source.f_locals:
            return ' [label="f_locals",weight=10]'
        if target is source.f_globals:
            return ' [label="f_globals",weight=10]'
    if isinstance(source, types.MethodType):
        try:
            if target is source.__self__:
                return ' [label="__self__",weight=10]'
            if target is source.__func__:
                return ' [label="__func__",weight=10]'
        except AttributeError:
            # Python < 2.6 compatibility
            if target is source.im_self:
                return ' [label="im_self",weight=10]'
            if target is source.im_func:
                return ' [label="im_func",weight=10]'
    if isinstance(source, types.FunctionType):
        for k in dir(source):
            if target is getattr(source, k):
                return ' [label="%s",weight=10]' % quote(k)
    if isinstance(source, dict):
        for k, v in iteritems(source):
            if v is target:
                if isinstance(k, basestring) and is_identifier(k):
                    return ' [label="%s",weight=2]' % quote(k)
                else:
                    return ' [label="%s"]' % quote(type(k).__name__ + "\n"
                                                   + safe_repr(k))
    return '' 
开发者ID:Exa-Networks,项目名称:exaddos,代码行数:35,代码来源:objgraph.py

示例14: _extract_branch

# 需要导入模块: import types [as 别名]
# 或者: from types import FrameType [as 别名]
def _extract_branch(self, frame: FrameType):
        branch = frame.f_locals['branch']
        assert isinstance(branch, SourceBranch)
        return branch 
开发者ID:google,项目名称:tmppy,代码行数:6,代码来源:_plugin.py

示例15: dynamic_source_filename

# 需要导入模块: import types [as 别名]
# 或者: from types import FrameType [as 别名]
def dynamic_source_filename(self, filename: str, frame: FrameType):
        branch = self._extract_branch(frame)
        return branch.file_name 
开发者ID:google,项目名称:tmppy,代码行数:5,代码来源:_plugin.py


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