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


Python inspect.getouterframes方法代码示例

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


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

示例1: _called_from_setup

# 需要导入模块: import inspect [as 别名]
# 或者: from inspect import getouterframes [as 别名]
def _called_from_setup(run_frame):
        """
        Attempt to detect whether run() was called from setup() or by another
        command.  If called by setup(), the parent caller will be the
        'run_command' method in 'distutils.dist', and *its* caller will be
        the 'run_commands' method.  If called any other way, the
        immediate caller *might* be 'run_command', but it won't have been
        called by 'run_commands'. Return True in that case or if a call stack
        is unavailable. Return False otherwise.
        """
        if run_frame is None:
            msg = "Call stack not available. bdist_* commands may fail."
            warnings.warn(msg)
            if platform.python_implementation() == 'IronPython':
                msg = "For best results, pass -X:Frames to enable call stack."
                warnings.warn(msg)
            return True
        res = inspect.getouterframes(run_frame)[2]
        caller, = res[:1]
        info = inspect.getframeinfo(caller)
        caller_module = caller.f_globals.get('__name__', '')
        return (
            caller_module == 'distutils.dist'
            and info.function == 'run_commands'
        ) 
开发者ID:jpush,项目名称:jbox,代码行数:27,代码来源:install.py

示例2: __set_message

# 需要导入模块: import inspect [as 别名]
# 或者: from inspect import getouterframes [as 别名]
def __set_message(self, args, kargs):
        details = ', '.join(map(str, args))
        errno = kargs['errno'] if 'errno' in kargs and kargs['errno'] else \
            self.default_errno
        self.errno = errno
        message = kargs['message'] if 'message' in kargs and kargs['message'] \
            else self.default_msg
        exception = ''
        if 'frame' in kargs and kargs['frame']:
            frame = kargs['frame']
        else:
            my_frames = inspect.getouterframes(inspect.currentframe())[2]
            frame = inspect.getframeinfo(my_frames[0])
        if 'exception' in kargs and kargs['exception']:
            message = kargs['exception']
        elif details:
            exception = details
        self.frame = frame
        self.message = self.message_format % (errno, message, exception,
                                              frame.filename, frame.lineno) 
开发者ID:F5Networks,项目名称:f5-openstack-agent,代码行数:22,代码来源:exceptions.py

示例3: _add_served_directory

# 需要导入模块: import inspect [as 别名]
# 或者: from inspect import getouterframes [as 别名]
def _add_served_directory(cls, config, relative_path, config_var):
        ''' Add extra public/template directories to config. '''
        import inspect
        import os

        assert config_var in ('extra_template_paths', 'extra_public_paths')
        # we want the filename that of the function caller but they will
        # have used one of the available helper functions
        frame, filename, line_number, function_name, lines, index =\
            inspect.getouterframes(inspect.currentframe())[2]

        this_dir = os.path.dirname(filename)
        absolute_path = os.path.join(this_dir, relative_path)
        if absolute_path not in config.get(config_var, ''):
            if config.get(config_var):
                config[config_var] += ',' + absolute_path
            else:
                config[config_var] = absolute_path 
开发者ID:italia,项目名称:daf-recipes,代码行数:20,代码来源:toolkit.py

示例4: _add_resource

# 需要导入模块: import inspect [as 别名]
# 或者: from inspect import getouterframes [as 别名]
def _add_resource(cls, path, name):
        '''Add a Fanstatic resource library to CKAN.

        Fanstatic libraries are directories containing static resource files
        (e.g. CSS, JavaScript or image files) that can be accessed from CKAN.

        See :doc:`/theming/index` for more details.

        '''
        import inspect
        import os

        # we want the filename that of the function caller but they will
        # have used one of the available helper functions
        frame, filename, line_number, function_name, lines, index =\
            inspect.getouterframes(inspect.currentframe())[1]

        this_dir = os.path.dirname(filename)
        absolute_path = os.path.join(this_dir, path)
        import ckan.lib.fanstatic_resources
        ckan.lib.fanstatic_resources.create_library(name, absolute_path) 
开发者ID:italia,项目名称:daf-recipes,代码行数:23,代码来源:toolkit.py

示例5: ton_async_execute

# 需要导入模块: import inspect [as 别名]
# 或者: from inspect import getouterframes [as 别名]
def ton_async_execute(self, query, timeout=30.0):
        if not isinstance(query, dict):
            raise TonLibWrongResult(f'query must be a dictionary, got {type(query)}')

        unhidden_query = json.dumps(query).encode('utf-8')
        self._tonlib_json_client_send(self._client, unhidden_query)
        result = self._tonlib_json_client_receive(self._client, timeout)
        if result:
            result = json.loads(result.decode('utf-8'))

        if not isinstance(result, dict):
            raise TonLibWrongResult(f'result must be a dictionary, got {type(result)}')

        fr = inspect.getouterframes(inspect.currentframe())[1]
        hidden_query = self.hide_dict(query)
        hidden_result = self.hide_dict(result)
        logger.debug(f'{fr.filename}:{fr.lineno} at {fr.function}() called ton_async_execute({hidden_query}) -> {hidden_result}')

        return result 
开发者ID:formony,项目名称:ton_client,代码行数:21,代码来源:tonlib.py

示例6: ton_sync_execute

# 需要导入模块: import inspect [as 别名]
# 或者: from inspect import getouterframes [as 别名]
def ton_sync_execute(self, query):
        if not isinstance(query, dict):
            raise TonLibWrongResult(f'query must be a dictionary, got {type(query)}')

        unhidden_query = json.dumps(query).encode('utf-8')
        result = self._tonlib_json_client_execute(None, unhidden_query)
        if result:
            result = json.loads(result.decode('utf-8'))

        if not isinstance(result, dict):
            raise TonLibWrongResult(f'result must be a dictionary, got {type(result)}')

        fr = inspect.getouterframes(inspect.currentframe())[1]
        hidden_query = self.hide_dict(query)
        hidden_result = self.hide_dict(result)
        logger.debug(f'{fr.filename}:{fr.lineno} at {fr.function}() called ton_sync_execute({hidden_query}) -> {hidden_result}')

        return result 
开发者ID:formony,项目名称:ton_client,代码行数:20,代码来源:tonlib.py

示例7: __init__

# 需要导入模块: import inspect [as 别名]
# 或者: from inspect import getouterframes [as 别名]
def __init__(self, smarthome):
        self._sh = smarthome
        self.logger = logging.getLogger(__name__)

        global _items_instance
        if _items_instance is not None:
            import inspect
            curframe = inspect.currentframe()
            calframe = inspect.getouterframes(curframe, 4)
            self.logger.critical("A second 'items' object has been created. There should only be ONE instance of class 'Items'!!! Called from: {} ({})".format(calframe[1][1], calframe[1][3]))

        _items_instance = self
        self.structs = Structs()

        self.logger.warning("WARNING >>> Working with refactored version of lib.item <<< WARNING")


    # -----------------------------------------------------------------------------------------
    #   Following (static) method of the class Items implement the API for Items in SmartHomeNG
    # ----------------------------------------------------------------------------------------- 
开发者ID:smarthomeNG,项目名称:smarthome,代码行数:22,代码来源:items.py

示例8: __init__

# 需要导入模块: import inspect [as 别名]
# 或者: from inspect import getouterframes [as 别名]
def __init__(self, smarthome):
        threading.Thread.__init__(self, name='Scheduler')
        logger.info('Init Scheduler')
        self._sh = smarthome
        self._lock = threading.Lock()
        self._runc = threading.Condition()

        global _scheduler_instance
        if _scheduler_instance is not None:
            import inspect
            curframe = inspect.currentframe()
            calframe = inspect.getouterframes(curframe, 4)
            logger.critical("A second 'scheduler' object has been created. There should only be ONE instance of class 'Scheduler'!!! Called from: {} ({})".format(calframe[1][1], calframe[1][3]))

        _scheduler_instance = self

        self.shtime = Shtime.get_instance()
        self.items = Items.get_instance()
        self.mqtt = None


    # --------------------------------------------------------------------------------------------------
    #   Following (static) method of the class Scheduler implement the API for schedulers in SmartHomeNG
    # -------------------------------------------------------------------------------------------------- 
开发者ID:smarthomeNG,项目名称:smarthome,代码行数:26,代码来源:scheduler.py

示例9: __init__

# 需要导入模块: import inspect [as 别名]
# 或者: from inspect import getouterframes [as 别名]
def __init__(self, smarthome):
        self._sh = smarthome

        global _items_instance
        if _items_instance is not None:
            import inspect
            curframe = inspect.currentframe()
            calframe = inspect.getouterframes(curframe, 4)
            logger.critical("A second 'items' object has been created. There should only be ONE instance of class 'Items'!!! Called from: {} ({})".format(calframe[1][1], calframe[1][3]))

        _items_instance = self


    # -----------------------------------------------------------------------------------------
    #   Following (static) method of the class Items implement the API for Items in SmartHomeNG
    # ----------------------------------------------------------------------------------------- 
开发者ID:smarthomeNG,项目名称:smarthome,代码行数:18,代码来源:item.py

示例10: __init__

# 需要导入模块: import inspect [as 别名]
# 或者: from inspect import getouterframes [as 别名]
def __init__(self, smarthome):
        self._sh = smarthome
        global _shtime_instance
        if _shtime_instance is not None:
            import inspect
            curframe = inspect.currentframe()
            calframe = inspect.getouterframes(curframe, 4)
            logger.critical(self.translate("A second 'shtime' object has been created. There should only be ONE instance of class 'Shtime'!!! Called from: {callframe1} ({callframe3})").format(callframe1=calframe[1][1], callframe3=calframe[1][3]))

        _shtime_instance = self

        self._starttime = datetime.datetime.now()

        # set default timezone to UTC
#        global TZ
        self._tz = 'UTC'
        os.environ['TZ'] = self._tz
        self.set_tzinfo(dateutil.tz.gettz('UTC'))


    # -----------------------------------------------------------------------------------------------------
    #   Following (static) method of the class Shtime implement the API for date and time handling in shNG
    # ----------------------------------------------------------------------------------------------------- 
开发者ID:smarthomeNG,项目名称:smarthome,代码行数:25,代码来源:shtime.py

示例11: init_argparser

# 需要导入模块: import inspect [as 别名]
# 或者: from inspect import getouterframes [as 别名]
def init_argparser(self, argparser):
        level = len(getouterframes(currentframe()))
        if level > self.recursionlimit:
            # turns out we need to emulate this to make pypy not
            # blow up coverage reporting; also make it die
            # quicker, and this emulation works good enough as
            # it turns out.
            raise RuntimeError('maximum recursion depth exceeded')
        super(BadSimpleRuntime, self).init_argparser(argparser) 
开发者ID:calmjs,项目名称:calmjs,代码行数:11,代码来源:runtime.py

示例12: get_default_config_directory

# 需要导入模块: import inspect [as 别名]
# 或者: from inspect import getouterframes [as 别名]
def get_default_config_directory():
        """Return default config directory, based in the actual test path

        :returns: default config directory
        """
        test_path = os.path.dirname(os.path.realpath(inspect.getouterframes(inspect.currentframe())[2][1]))
        return os.path.join(test_path, 'conf') 
开发者ID:Telefonica,项目名称:toolium,代码行数:9,代码来源:driver_wrappers_pool.py

示例13: instances

# 需要导入模块: import inspect [as 别名]
# 或者: from inspect import getouterframes [as 别名]
def instances():
    f = inspect.currentframe()
    d = inspect.getouterframes(f)[1][0].f_locals
    l = []
    for v in d.values():
        if _isGenSeq(v):
            l.append(v)
    return l 
开发者ID:myhdl,项目名称:myhdl,代码行数:10,代码来源:_misc.py

示例14: deprecated

# 需要导入模块: import inspect [as 别名]
# 或者: from inspect import getouterframes [as 别名]
def deprecated(text="", eos="", max_num_warnings=None):
    """
    Args:
        text, eos, max_num_warnings: same as :func:`log_deprecated`.

    Returns:
        a decorator which deprecates the function.

    Example:
        .. code-block:: python

            @deprecated("Explanation of what to do instead.", "2017-11-4")
            def foo(...):
                pass
    """

    def get_location():
        import inspect
        frame = inspect.currentframe()
        if frame:
            callstack = inspect.getouterframes(frame)[-1]
            return '%s:%i' % (callstack[1], callstack[2])
        else:
            stack = inspect.stack(0)
            entry = stack[2]
            return '%s:%i' % (entry[1], entry[2])

    def deprecated_inner(func):
        @functools.wraps(func)
        def new_func(*args, **kwargs):
            name = "{} [{}]".format(func.__name__, get_location())
            log_deprecated(name, text, eos, max_num_warnings=max_num_warnings)
            return func(*args, **kwargs)
        return new_func
    return deprecated_inner 
开发者ID:tensorpack,项目名称:dataflow,代码行数:37,代码来源:develop.py

示例15: get_function_name

# 需要导入模块: import inspect [as 别名]
# 或者: from inspect import getouterframes [as 别名]
def get_function_name(frame):
    return inspect.getouterframes(frame)[1][3] 
开发者ID:jtushman,项目名称:state_machine,代码行数:4,代码来源:__init__.py


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