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


Python six.get_function_code方法代码示例

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


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

示例1: _build_from_function

# 需要导入模块: import six [as 别名]
# 或者: from six import get_function_code [as 别名]
def _build_from_function(node, name, member, module):
    # verify this is not an imported function
    try:
        code = six.get_function_code(member)
    except AttributeError:
        # Some implementations don't provide the code object,
        # such as Jython.
        code = None
    filename = getattr(code, 'co_filename', None)
    if filename is None:
        assert isinstance(member, object)
        object_build_methoddescriptor(node, member, name)
    elif filename != getattr(module, '__file__', None):
        attach_dummy_node(node, name, member)
    else:
        object_build_function(node, member, name) 
开发者ID:AtomLinter,项目名称:linter-pylama,代码行数:18,代码来源:raw_building.py

示例2: test_frame_stack

# 需要导入模块: import six [as 别名]
# 或者: from six import get_function_code [as 别名]
def test_frame_stack():
    def to_code_names(frames):
        code_names = deque()
        for frame in reversed(frames):
            code_name = frame.f_code.co_name
            if code_name not in mock_code_names:
                break
            code_names.appendleft(code_name)
        return list(code_names)
    baz_frame = foo()
    foo_frame = baz_frame.f_back.f_back
    frames = frame_stack(baz_frame)
    assert to_code_names(frames) == ['foo', 'bar', 'baz']
    # base frame.
    frames = frame_stack(baz_frame, base_frame=foo_frame)
    assert to_code_names(frames) == ['bar', 'baz']
    # ignored codes.
    frames = frame_stack(baz_frame, ignored_codes=[
        six.get_function_code(foo),
        six.get_function_code(baz),
    ])
    assert to_code_names(frames) == ['bar'] 
开发者ID:what-studio,项目名称:profiling,代码行数:24,代码来源:test_utils.py

示例3: deprecated

# 需要导入模块: import six [as 别名]
# 或者: from six import get_function_code [as 别名]
def deprecated(version, version_removed):
    '''This is a decorator which can be used to mark functions
    as deprecated.

    It will result in a warning being emitted when the function is used.'''

    def __wrapper(func, *args, **kwargs):
        '''Warn the user, and then proceed.'''
        code = six.get_function_code(func)
        warnings.warn_explicit(
            "{:s}.{:s}\n\tDeprecated as of JAMS version {:s}."
            "\n\tIt will be removed in JAMS version {:s}."
            .format(func.__module__, func.__name__,
                    version, version_removed),
            category=DeprecationWarning,
            filename=code.co_filename,
            lineno=code.co_firstlineno + 1
        )
        return func(*args, **kwargs)

    return decorator(__wrapper) 
开发者ID:marl,项目名称:jams,代码行数:23,代码来源:core.py

示例4: make_decorator

# 需要导入模块: import six [as 别名]
# 或者: from six import get_function_code [as 别名]
def make_decorator(func):
    """
    Wraps a test decorator so as to properly replicate metadata
    of the decorated function, including nose's additional stuff
    (namely, setup and teardown).
    """
    def decorate(newfunc):
        if hasattr(func, 'compat_func_name'):
            name = func.compat_func_name
        else:
            name = func.__name__
        newfunc.__dict__ = func.__dict__
        newfunc.__doc__ = func.__doc__
        newfunc.__module__ = func.__module__
        if not hasattr(newfunc, 'compat_co_firstlineno'):
            newfunc.compat_co_firstlineno = six.get_function_code(func).co_firstlineno
        try:
            newfunc.__name__ = name
        except TypeError:
            # can't set func name in 2.3
            newfunc.compat_func_name = name
        return newfunc
    return decorate 
开发者ID:spdx,项目名称:tools-python,代码行数:25,代码来源:testing_utils.py

示例5: from_function

# 需要导入模块: import six [as 别名]
# 或者: from six import get_function_code [as 别名]
def from_function(cls, f, *args, **kwargs):
        """
        Create a new instance from a function. Gets the code object from
        the function and passes it and any other specified parameters to
        :meth:`from_code`.

        Arguments:
            f(function): The function to get the code object from.

        Returns:
            CodeObject: A new :class:`CodeObject` instance.
        """

        return cls.from_code(six.get_function_code(f), *args, **kwargs) 
开发者ID:edibledinos,项目名称:pwnypack,代码行数:16,代码来源:bytecode.py

示例6: primal_name

# 需要导入模块: import six [as 别名]
# 或者: from six import get_function_code [as 别名]
def primal_name(func, wrt):
  """Name for the primal of a function."""
  if not isinstance(func, types.FunctionType):
    raise TypeError(func)
  varnames = six.get_function_code(func).co_varnames
  return PRIMAL_NAME.format(func.__name__, ''.join(varnames[i] for i in wrt)) 
开发者ID:google,项目名称:tangent,代码行数:8,代码来源:naming.py

示例7: _adjoint_name

# 需要导入模块: import six [as 别名]
# 或者: from six import get_function_code [as 别名]
def _adjoint_name(func, wrt, template):
  if not isinstance(func, types.FunctionType):
    raise TypeError
  varnames = six.get_function_code(func).co_varnames
  return template.format(func.__name__, ''.join(varnames[i] for i in wrt)) 
开发者ID:google,项目名称:tangent,代码行数:7,代码来源:naming.py

示例8: fix_js_args

# 需要导入模块: import six [as 别名]
# 或者: from six import get_function_code [as 别名]
def fix_js_args(func):
    '''Use this function when unsure whether func takes this and arguments as its last 2 args.
       It will append 2 args if it does not.'''
    fcode = six.get_function_code(func)
    fargs = fcode.co_varnames[fcode.co_argcount - 2:fcode.co_argcount]
    if fargs == ('this', 'arguments') or fargs == ('arguments', 'var'):
        return func
    code = append_arguments(six.get_function_code(func), ('this', 'arguments'))

    return types.FunctionType(
        code,
        six.get_function_globals(func),
        func.__name__,
        closure=six.get_function_closure(func)) 
开发者ID:alfa-addon,项目名称:addon,代码行数:16,代码来源:injector.py

示例9: fix_js_args

# 需要导入模块: import six [as 别名]
# 或者: from six import get_function_code [as 别名]
def fix_js_args(func):
    '''Use this function when unsure whether func takes this and arguments as its last 2 args.
       It will append 2 args if it does not.'''
    fcode = six.get_function_code(func)
    fargs = fcode.co_varnames[fcode.co_argcount-2:fcode.co_argcount]
    if fargs==('this', 'arguments') or fargs==('arguments', 'var'):
        return func
    code = append_arguments(six.get_function_code(func), ('this','arguments'))

    return types.FunctionType(code, six.get_function_globals(func), func.__name__, closure=six.get_function_closure(func)) 
开发者ID:taxigps,项目名称:xbmc-addons-chinese,代码行数:12,代码来源:injector.py

示例10: __init__

# 需要导入模块: import six [as 别名]
# 或者: from six import get_function_code [as 别名]
def __init__(self, func, prototype=None, extensible=True, source=None):
        cand = fix_js_args(func)
        has_scope = cand is func
        func = cand
        self.argcount = six.get_function_code(func).co_argcount - 2 - has_scope
        self.code = func
        self.source = source if source else '{ [python code] }'
        self.func_name = func.__name__ if not func.__name__.startswith('PyJs_anonymous') else ''
        self.extensible = extensible
        self.prototype = prototype
        self.own = {}
        #set own property length to the number of arguments
        self.define_own_property('length', {'value': Js(self.argcount), 'writable': False,
                                            'enumerable': False, 'configurable': False})

        if self.func_name:
            self.define_own_property('name', {'value': Js(self.func_name), 'writable': False,
                                            'enumerable': False, 'configurable': True})

        # set own prototype
        proto = Js({})
        # constructor points to this function
        proto.define_own_property('constructor',{'value': self, 'writable': True,
                                                 'enumerable': False, 'configurable': True})
        self.define_own_property('prototype', {'value': proto, 'writable': True,
                                                 'enumerable': False, 'configurable': False}) 
开发者ID:taxigps,项目名称:xbmc-addons-chinese,代码行数:28,代码来源:base.py

示例11: construct_new_test_function

# 需要导入模块: import six [as 别名]
# 或者: from six import get_function_code [as 别名]
def construct_new_test_function(original_func, name, build_params):
    """Builds a new test function based on parameterized data.

    :param original_func: The original test function that is used as a template
    :param name: The fullname of the new test function
    :param build_params: A dictionary or list containing args or kwargs
        for the new test
    :return: A new function object
    """
    new_func = types.FunctionType(
        six.get_function_code(original_func),
        six.get_function_globals(original_func),
        name=name,
        argdefs=six.get_function_defaults(original_func)
    )

    for key, val in original_func.__dict__.items():
        if key != 'build_data':
            new_func.__dict__[key] = val

    # Support either an arg list or kwarg dict for our data
    build_args = build_params if isinstance(build_params, list) else []
    build_kwargs = build_params if isinstance(build_params, dict) else {}

    # Build a test wrapper to execute with our kwargs
    def test_wrapper(func, test_args, test_kwargs):
        @functools.wraps(func)
        def wrapper(self):
            return func(self, *test_args, **test_kwargs)
        return wrapper

    return test_wrapper(new_func, build_args, build_kwargs) 
开发者ID:cloud-security-research,项目名称:sgx-kms,代码行数:34,代码来源:utils.py

示例12: test_get_function_code

# 需要导入模块: import six [as 别名]
# 或者: from six import get_function_code [as 别名]
def test_get_function_code():
    def f():
        pass
    assert isinstance(six.get_function_code(f), types.CodeType)
    if not hasattr(sys, "pypy_version_info"):
        pytest.raises(AttributeError, six.get_function_code, hasattr) 
开发者ID:benjaminp,项目名称:six,代码行数:8,代码来源:test_six.py

示例13: _is_in_app_main

# 需要导入模块: import six [as 别名]
# 或者: from six import get_function_code [as 别名]
def _is_in_app_main():
  # type: () -> bool
  """Returns True iff app.run is active."""
  f = sys._getframe().f_back  # pylint: disable=protected-access
  while f:
    if f.f_code == six.get_function_code(app.run):  # pytype: disable=wrong-arg-types
      return True
    f = f.f_back
  return False 
开发者ID:abseil,项目名称:abseil-py,代码行数:11,代码来源:absltest.py

示例14: construct_new_test_function

# 需要导入模块: import six [as 别名]
# 或者: from six import get_function_code [as 别名]
def construct_new_test_function(original_func, name, build_params):
    """Builds a new test function based on parameterized data.

    :param original_func: The original test function that is used as a template
    :param name: The fullname of the new test function
    :param build_params: A dictionary or list containing args or kwargs
        for the new test
    :return: A new function object
    """
    new_func = types.FunctionType(
        six.get_function_code(original_func),
        six.get_function_globals(original_func),
        name=name,
        argdefs=six.get_function_defaults(original_func)
    )

    # Support either an arg list or kwarg dict for our data
    build_args = build_params if isinstance(build_params, list) else []
    build_kwargs = build_params if isinstance(build_params, dict) else {}

    # Build a test wrapper to execute with our kwargs
    def test_wrapper(func, test_args, test_kwargs):
        @functools.wraps(func)
        def wrapper(self):
            return func(self, *test_args, **test_kwargs)
        return wrapper

    return test_wrapper(new_func, build_args, build_kwargs) 
开发者ID:openstack,项目名称:python-barbicanclient,代码行数:30,代码来源:utils.py

示例15: construct_new_test_function

# 需要导入模块: import six [as 别名]
# 或者: from six import get_function_code [as 别名]
def construct_new_test_function(original_func, name, build_params):
    """Builds a new test function based on parameterized data.

    :param original_func: The original test function that is used as a template
    :param name: The fullname of the new test function
    :param build_params: A dictionary or list containing args or kwargs
        for the new test
    :return: A new function object
    """
    new_func = types.FunctionType(
        six.get_function_code(original_func),
        six.get_function_globals(original_func),
        name=name,
        argdefs=six.get_function_defaults(original_func),
        closure=six.get_function_closure(original_func)
    )

    for key, val in original_func.__dict__.items():
        if key != 'build_data':
            new_func.__dict__[key] = val

    # Support either an arg list or kwarg dict for our data
    build_args = build_params if isinstance(build_params, list) else []
    build_kwargs = build_params if isinstance(build_params, dict) else {}

    # Build a test wrapper to execute with our kwargs
    def test_wrapper(func, test_args, test_kwargs):
        @functools.wraps(func)
        def wrapper(self):
            return func(self, *test_args, **test_kwargs)
        return wrapper

    return test_wrapper(new_func, build_args, build_kwargs) 
开发者ID:openstack,项目名称:barbican,代码行数:35,代码来源:utils.py


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