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


Python sys._getframe方法代码示例

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


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

示例1: test_update_versions

# 需要导入模块: import sys [as 别名]
# 或者: from sys import _getframe [as 别名]
def test_update_versions(self):
        """ Test version update """

        method_name = sys._getframe().f_code.co_name
        self._setUp(method_name)

        name = method_name
        self._create_or_update_param(name)

        param = SSMParameter(name)

        self.assertEqual(param.version, 1)
        self.assertEqual(param.value, self.PARAM_VALUE)

        # this will update the value and create version 2
        self._create_or_update_param(name, self.PARAM_VALUE_V2)

        param.refresh()

        # refreshing should give you version 2
        self.assertEqual(param.version, 2)
        self.assertEqual(param.value, self.PARAM_VALUE_V2)

        self._delete_param(name) 
开发者ID:alexcasalboni,项目名称:ssm-cache-python,代码行数:26,代码来源:versioning_test.py

示例2: test_select_versions

# 需要导入模块: import sys [as 别名]
# 或者: from sys import _getframe [as 别名]
def test_select_versions(self):
        """ Test version selection """

        method_name = sys._getframe().f_code.co_name
        self._setUp(method_name)

        name = method_name
        self._create_or_update_param(name)

        param = SSMParameter("%s:1" % name)

        self.assertEqual(param.value, self.PARAM_VALUE)
        self.assertEqual(param.version, 1)

        # this will update the value and create version 2
        self._create_or_update_param(name, self.PARAM_VALUE_V2)

        param.refresh()

        self.assertEqual(param.value, self.PARAM_VALUE)
        self.assertEqual(param.version, 1)

        self._delete_param(name) 
开发者ID:alexcasalboni,项目名称:ssm-cache-python,代码行数:25,代码来源:versioning_test.py

示例3: test_versions_group

# 需要导入模块: import sys [as 别名]
# 或者: from sys import _getframe [as 别名]
def test_versions_group(self):
        """ Test version update in a group """
        method_name = sys._getframe().f_code.co_name
        self._setUp(method_name)

        name = method_name
        self._create_or_update_param(name)

        group = SSMParameterGroup()
        param = group.parameter(name)

        self.assertEqual(param.version, 1)
        self.assertEqual(param.value, self.PARAM_VALUE)

        # this will update the value and create version 2
        self._create_or_update_param(name, self.PARAM_VALUE_V2)

        group.refresh()

        # refreshing should give you version 2
        self.assertEqual(param.version, 2)
        self.assertEqual(param.value, self.PARAM_VALUE_V2)

        self._delete_param(name) 
开发者ID:alexcasalboni,项目名称:ssm-cache-python,代码行数:26,代码来源:versioning_test.py

示例4: test_versions_group_select

# 需要导入模块: import sys [as 别名]
# 或者: from sys import _getframe [as 别名]
def test_versions_group_select(self):
        """ Test version selection in a group """
        method_name = sys._getframe().f_code.co_name
        self._setUp(method_name)

        name = method_name
        self._create_or_update_param(name)

        # this will update the value and create version 2
        self._create_or_update_param(name, self.PARAM_VALUE_V2)

        group = SSMParameterGroup()
        param = group.parameter("%s:1" % name)

        self.assertEqual(param.version, 1)
        self.assertEqual(param.value, self.PARAM_VALUE)

        self._delete_param(name) 
开发者ID:alexcasalboni,项目名称:ssm-cache-python,代码行数:20,代码来源:versioning_test.py

示例5: silentLogPrefix

# 需要导入模块: import sys [as 别名]
# 或者: from sys import _getframe [as 别名]
def silentLogPrefix(stepsUp):
    '''
    logPrefix v2-- gets caller information silently (without caller intervention)
    The single parameter reflects how far up the stack to go to find the caller and
    depends how deep the direct caller to this method is wrt to the target caller

    NOTE: Some calls cannot be silently prefixed (getting into the twisted code is a
    great example)

    :param stepsUp: the number of steps to move up the stack for the caller
    :type steps: int.
    '''

    try:
        trace = sys._getframe(stepsUp).f_code.co_filename
        line = sys._getframe(stepsUp).f_lineno
        module, package = parseLogPrefix(trace)
    except:
        return 'unknown', 'unknown', '??'

    return package, module, line 
开发者ID:ParadropLabs,项目名称:Paradrop,代码行数:23,代码来源:output.py

示例6: get_extended_info

# 需要导入模块: import sys [as 别名]
# 或者: from sys import _getframe [as 别名]
def get_extended_info(error_message, prefix):
    # noinspection PyProtectedMember
    caller_stack_frame = sys._getframe(2)
    caller = caller_stack_frame.f_code.co_name
    line = caller_stack_frame.f_lineno
    module = inspect.getmodule(caller_stack_frame)
    error_code = get_error_constant_name(module.__dict__, error_message, prefix)
    if error_code is None:
        error_code = get_error_constant_name(caller_stack_frame.f_globals, error_message, prefix)

    result = {
        "Caller": caller,
        "Module": module.__name__,
        "Line": line
    }
    if error_code is not None:
        result["Code"] = error_code

    return result 
开发者ID:awslabs,项目名称:aws-ops-automator,代码行数:21,代码来源:__init__.py

示例7: currentframe

# 需要导入模块: import sys [as 别名]
# 或者: from sys import _getframe [as 别名]
def currentframe():
        """Return the frame object for the caller's stack frame."""
        try:
            raise Exception
        except:
            return sys.exc_info()[2].tb_frame.f_back

# _srcfile is only used in conjunction with sys._getframe().
# To provide compatibility with older versions of Python, set _srcfile
# to None if _getframe() is not available; this value will prevent
# findCaller() from being called.
#if not hasattr(sys, "_getframe"):
#    _srcfile = None

#
#_startTime is used as the base when calculating the relative time of events
# 
开发者ID:war-and-code,项目名称:jawfish,代码行数:19,代码来源:__init__.py

示例8: set_trace

# 需要导入模块: import sys [as 别名]
# 或者: from sys import _getframe [as 别名]
def set_trace():
    """Call pdb.set_trace in the caller's frame.

    First restore sys.stdout and sys.stderr.  Note that the streams are
    NOT reset to whatever they were before the call once pdb is done!
    """
    import pdb
    for stream in 'stdout', 'stderr':
        output = getattr(sys, stream)
        orig_output = getattr(sys, '__%s__' % stream)
        if output != orig_output:
            # Flush the output before entering pdb
            if hasattr(output, 'getvalue'):
                orig_output.write(output.getvalue())
                orig_output.flush()
            setattr(sys, stream, orig_output)
    exc, tb = sys.exc_info()[1:]
    if tb:
        if isinstance(exc, AssertionError) and exc.args:
            # The traceback is not printed yet
            print_exc()
        pdb.post_mortem(tb)
    else:
        pdb.Pdb().set_trace(sys._getframe().f_back) 
开发者ID:OpenTrading,项目名称:OpenTrader,代码行数:26,代码来源:tools.py

示例9: name_corresponds_to

# 需要导入模块: import sys [as 别名]
# 或者: from sys import _getframe [as 别名]
def name_corresponds_to(self, name, expected):
        """Helper functions to test get_objects_in_frame.

        Check that the name corresponds to the expected objects (and their
        scope) in the frame of calling function.
        None can be used to match any object as it can be hard to describe
        an object when it is hidden by something in a closer scope.
        Also, extra care is to be taken when calling the function because
        giving value by names might affect the result (adding in local
        scope).
        """
        frame = sys._getframe(1)  # frame of calling function
        lst = get_objects_in_frame(frame).get(name, [])
        self.assertEqual(len(lst), len(expected))
        for scopedobj, exp in zip(lst, expected):
            obj, scope = scopedobj
            expobj, expscope = exp
            self.assertEqual(scope, expscope, name)
            if expobj is not None:
                self.assertEqual(obj, expobj, name) 
开发者ID:SylvainDe,项目名称:DidYouMean-Python,代码行数:22,代码来源:didyoumean_internal_tests.py

示例10: requires

# 需要导入模块: import sys [as 别名]
# 或者: from sys import _getframe [as 别名]
def requires(resource, msg=None):
    """Raise ResourceDenied if the specified resource is not available.

    If the caller's module is __main__ then automatically return True.  The
    possibility of False being returned occurs when regrtest.py is
    executing.
    """
    if resource == 'gui' and not _is_gui_available():
        raise unittest.SkipTest("Cannot use the 'gui' resource")
    # see if the caller's module is __main__ - if so, treat as if
    # the resource was set
    if sys._getframe(1).f_globals.get("__name__") == "__main__":
        return
    if not is_resource_enabled(resource):
        if msg is None:
            msg = "Use of the %r resource not enabled" % resource
        raise ResourceDenied(msg) 
开发者ID:Soft8Soft,项目名称:verge3d-blender-addon,代码行数:19,代码来源:support.py

示例11: update

# 需要导入模块: import sys [as 别名]
# 或者: from sys import _getframe [as 别名]
def update(self, func, **kw):
        "Update the signature of func with the data in self"
        func.__name__ = self.name
        func.__doc__ = getattr(self, 'doc', None)
        func.__dict__ = getattr(self, 'dict', {})
        func.__defaults__ = self.defaults
        func.__kwdefaults__ = self.kwonlydefaults or None
        func.__annotations__ = getattr(self, 'annotations', None)
        try:
            frame = sys._getframe(3)
        except AttributeError:  # for IronPython and similar implementations
            callermodule = '?'
        else:
            callermodule = frame.f_globals.get('__name__', '?')
        func.__module__ = getattr(self, 'module', callermodule)
        func.__dict__.update(kw) 
开发者ID:remg427,项目名称:misp42splunk,代码行数:18,代码来源:decorator.py

示例12: render_string

# 需要导入模块: import sys [as 别名]
# 或者: from sys import _getframe [as 别名]
def render_string(self, template_name, **kwargs):
        """使用给定的参数生成指定模板.

        我们返回生成的字节字符串(以utf8). 为了生成并写一个模板
        作为响应, 使用上面的render().
        """
        # If no template_path is specified, use the path of the calling file
        template_path = self.get_template_path()
        if not template_path:
            frame = sys._getframe(0)
            web_file = frame.f_code.co_filename
            while frame.f_code.co_filename == web_file:
                frame = frame.f_back
            template_path = os.path.dirname(frame.f_code.co_filename)
        with RequestHandler._template_loader_lock:
            if template_path not in RequestHandler._template_loaders:
                loader = self.create_template_loader(template_path)
                RequestHandler._template_loaders[template_path] = loader
            else:
                loader = RequestHandler._template_loaders[template_path]
        t = loader.load(template_name)
        namespace = self.get_template_namespace()
        namespace.update(kwargs)
        return t.generate(**namespace) 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:26,代码来源:web.py

示例13: check

# 需要导入模块: import sys [as 别名]
# 或者: from sys import _getframe [as 别名]
def check(s, frame=None):
    if frame is None:
        frame = sys._getframe(1)
        frame = py.code.Frame(frame)
    expr = parse(s, 'eval')
    assert isinstance(expr, ast.Expression)
    node = Interpretable(expr.node)
    try:
        node.eval(frame)
    except passthroughex:
        raise
    except Failure:
        e = sys.exc_info()[1]
        report_failure(e)
    else:
        if not frame.is_true(node.result):
            sys.stderr.write("assertion failed: %s\n" % node.nice_explanation())


###########################################################
# API / Entry points
# ######################################################### 
开发者ID:pytest-dev,项目名称:py,代码行数:24,代码来源:_assertionold.py

示例14: _apiwarn

# 需要导入模块: import sys [as 别名]
# 或者: from sys import _getframe [as 别名]
def _apiwarn(startversion, msg, stacklevel=2, function=None):
    # below is mostly COPIED from python2.4/warnings.py's def warn()
    # Get context information
    if isinstance(stacklevel, str):
        frame = sys._getframe(1)
        level = 1
        found = frame.f_code.co_filename.find(stacklevel) != -1
        while frame:
            co = frame.f_code
            if co.co_filename.find(stacklevel) == -1:
                if found:
                    stacklevel = level
                    break
            else:
                found = True
            level += 1
            frame = frame.f_back
        else:
            stacklevel = 1
    msg = "%s (since version %s)" %(msg, startversion)
    warn(msg, stacklevel=stacklevel+1, function=function) 
开发者ID:pytest-dev,项目名称:py,代码行数:23,代码来源:warning.py

示例15: test_frame_getargs

# 需要导入模块: import sys [as 别名]
# 或者: from sys import _getframe [as 别名]
def test_frame_getargs():
    def f1(x):
        return sys._getframe(0)
    fr1 = py.code.Frame(f1('a'))
    assert fr1.getargs(var=True) == [('x', 'a')]

    def f2(x, *y):
        return sys._getframe(0)
    fr2 = py.code.Frame(f2('a', 'b', 'c'))
    assert fr2.getargs(var=True) == [('x', 'a'), ('y', ('b', 'c'))]

    def f3(x, **z):
        return sys._getframe(0)
    fr3 = py.code.Frame(f3('a', b='c'))
    assert fr3.getargs(var=True) == [('x', 'a'), ('z', {'b': 'c'})]

    def f4(x, *y, **z):
        return sys._getframe(0)
    fr4 = py.code.Frame(f4('a', 'b', c='d'))
    assert fr4.getargs(var=True) == [('x', 'a'), ('y', ('b',)),
                                     ('z', {'c': 'd'})] 
开发者ID:pytest-dev,项目名称:py,代码行数:23,代码来源:test_code.py


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