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


Python six.get_method_self方法代码示例

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


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

示例1: subscribe

# 需要导入模块: import six [as 别名]
# 或者: from six import get_method_self [as 别名]
def subscribe(func):
    '''
    Add a subscriber function to option events

    Parameters
    ----------
    func : callable
        A callable object that takes two parameters: key and value.
        This function is called with the name and value of any option
        that is set.

    Returns
    -------
    None

    '''
    if isinstance(func, types.MethodType):
        obj = six.get_method_self(func)
        func = six.get_method_function(func)
        _subscribers[func] = (weakref.ref(func), weakref.ref(obj))
    else:
        _subscribers[func] = (weakref.ref(func), None) 
开发者ID:sassoftware,项目名称:python-esppy,代码行数:24,代码来源:config.py

示例2: is_same_callback

# 需要导入模块: import six [as 别名]
# 或者: from six import get_method_self [as 别名]
def is_same_callback(callback1, callback2, strict=True):
    """Returns if the two callbacks are the same."""
    if callback1 is callback2:
        # This happens when plain methods are given (or static/non-bound
        # methods).
        return True
    if callback1 == callback2:
        if not strict:
            return True
        # Two bound methods are equal if functions themselves are equal and
        # objects they are applied to are equal. This means that a bound
        # method could be the same bound method on another object if the
        # objects have __eq__ methods that return true (when in fact it is a
        # different bound method). Python u so crazy!
        try:
            self1 = six.get_method_self(callback1)
            self2 = six.get_method_self(callback2)
            return self1 is self2
        except AttributeError:  # nosec
            pass
    return False 
开发者ID:openstack,项目名称:oslo.utils,代码行数:23,代码来源:reflection.py

示例3: jump_to

# 需要导入模块: import six [as 别名]
# 或者: from six import get_method_self [as 别名]
def jump_to(self, index):
        """Immediately jump to the start of the block at the given index.

        Args:
            index (number): block index to run.
        """
        self._run_index = index

        tracer = sys.gettrace()
        if tracer:
            debugger = six.get_method_self(tracer)

            def raise_jump(*_args):
                raise JumpException(self)

            debugger.postcmd = lambda *args: True
            debugger.do_continue(None)
            sys.settrace(raise_jump)

        else:
            raise JumpException(self) 
开发者ID:gregoil,项目名称:rotest,代码行数:23,代码来源:flow.py

示例4: _find_method

# 需要导入模块: import six [as 别名]
# 或者: from six import get_method_self [as 别名]
def _find_method(obj, func):
    if obj:
        try:
            func_self = six.get_method_self(func)
        except AttributeError:  # func has no __self__
            pass
        else:
            if func_self is obj:
                return six.get_method_function(func).__name__
    raise ValueError("Function %s is not a method of: %s" % (func, obj)) 
开发者ID:DarkSand,项目名称:fetchman,代码行数:12,代码来源:reqser.py

示例5: get_method_self

# 需要导入模块: import six [as 别名]
# 或者: from six import get_method_self [as 别名]
def get_method_self(method):
    """Gets the ``self`` object attached to this method (or none)."""
    if not inspect.ismethod(method):
        return None
    try:
        return six.get_method_self(method)
    except AttributeError:
        return None 
开发者ID:openstack,项目名称:debtcollector,代码行数:10,代码来源:_utils.py

示例6: _find_method

# 需要导入模块: import six [as 别名]
# 或者: from six import get_method_self [as 别名]
def _find_method(obj, func):
    if obj:
        try:
            func_self = six.get_method_self(func)
        except AttributeError:  # func has no __self__
            pass
        else:
            if func_self is obj:
                name = six.get_method_function(func).__name__
                if _is_private_method(name):
                    return _mangle_private_name(obj, func, name)
                return name
    raise ValueError("Function %s is not a method of: %s" % (func, obj)) 
开发者ID:wistbean,项目名称:learn_python3_spider,代码行数:15,代码来源:reqser.py

示例7: test_get_method_self

# 需要导入模块: import six [as 别名]
# 或者: from six import get_method_self [as 别名]
def test_get_method_self():
    class X(object):
        def m(self):
            pass
    x = X()
    assert six.get_method_self(x.m) is x
    pytest.raises(AttributeError, six.get_method_self, 42) 
开发者ID:benjaminp,项目名称:six,代码行数:9,代码来源:test_six.py

示例8: is_bound_method

# 需要导入模块: import six [as 别名]
# 或者: from six import get_method_self [as 别名]
def is_bound_method(ob):
    return inspect.ismethod(ob) and six.get_method_self(ob) is not None 
开发者ID:pecan,项目名称:pecan,代码行数:4,代码来源:__init__.py

示例9: __set_parent

# 需要导入模块: import six [as 别名]
# 或者: from six import get_method_self [as 别名]
def __set_parent(self, parent):
        if ismethod(parent):
            self._parent = six.get_method_self(parent)
        else:
            self._parent = parent 
开发者ID:pecan,项目名称:pecan,代码行数:7,代码来源:secure.py

示例10: handle_security

# 需要导入模块: import six [as 别名]
# 或者: from six import get_method_self [as 别名]
def handle_security(controller, im_self=None):
    """ Checks the security of a controller.  """
    if controller._pecan.get('secured', False):
        check_permissions = controller._pecan['check_permissions']

        if isinstance(check_permissions, six.string_types):
            check_permissions = getattr(
                im_self or six.get_method_self(controller),
                check_permissions
            )

        if not check_permissions():
            raise exc.HTTPUnauthorized 
开发者ID:pecan,项目名称:pecan,代码行数:15,代码来源:secure.py

示例11: test_get_method_self

# 需要导入模块: import six [as 别名]
# 或者: from six import get_method_self [as 别名]
def test_get_method_self():
    class X(object):
        def m(self):
            pass
    x = X()
    assert six.get_method_self(x.m) is x
    py.test.raises(AttributeError, six.get_method_self, 42) 
开发者ID:NiklasRosenstein,项目名称:c4ddev,代码行数:9,代码来源:test_six.py

示例12: get_class_name

# 需要导入模块: import six [as 别名]
# 或者: from six import get_method_self [as 别名]
def get_class_name(obj, fully_qualified=True, truncate_builtins=True):
    """Get class name for object.

    If object is a type, returns name of the type. If object is a bound
    method or a class method, returns its ``self`` object's class name.
    If object is an instance of class, returns instance's class name.
    Else, name of the type of the object is returned. If fully_qualified
    is True, returns fully qualified name of the type. For builtin types,
    just name is returned. TypeError is raised if can't get class name from
    object.
    """
    if inspect.isfunction(obj):
        raise TypeError("Can't get class name.")

    if inspect.ismethod(obj):
        obj = get_method_self(obj)
    if not isinstance(obj, six.class_types):
        obj = type(obj)
    if truncate_builtins:
        try:
            built_in = obj.__module__ in _BUILTIN_MODULES
        except AttributeError:  # nosec
            pass
        else:
            if built_in:
                return obj.__name__
    if fully_qualified and hasattr(obj, '__module__'):
        return '%s.%s' % (obj.__module__, obj.__name__)
    else:
        return obj.__name__ 
开发者ID:openstack,项目名称:oslo.utils,代码行数:32,代码来源:reflection.py

示例13: get_callable_name

# 需要导入模块: import six [as 别名]
# 或者: from six import get_method_self [as 别名]
def get_callable_name(function):
    """Generate a name from callable.

    Tries to do the best to guess fully qualified callable name.
    """
    method_self = get_method_self(function)
    if method_self is not None:
        # This is a bound method.
        if isinstance(method_self, six.class_types):
            # This is a bound class method.
            im_class = method_self
        else:
            im_class = type(method_self)
        try:
            parts = (im_class.__module__, function.__qualname__)
        except AttributeError:
            parts = (im_class.__module__, im_class.__name__, function.__name__)
    elif inspect.ismethod(function) or inspect.isfunction(function):
        # This could be a function, a static method, a unbound method...
        try:
            parts = (function.__module__, function.__qualname__)
        except AttributeError:
            if hasattr(function, 'im_class'):
                # This is a unbound method, which exists only in python 2.x
                im_class = function.im_class
                parts = (im_class.__module__,
                         im_class.__name__, function.__name__)
            else:
                parts = (function.__module__, function.__name__)
    else:
        im_class = type(function)
        if im_class is _TYPE_TYPE:
            im_class = function
        try:
            parts = (im_class.__module__, im_class.__qualname__)
        except AttributeError:
            parts = (im_class.__module__, im_class.__name__)
    return '.'.join(parts) 
开发者ID:openstack,项目名称:oslo.utils,代码行数:40,代码来源:reflection.py

示例14: is_bound_method

# 需要导入模块: import six [as 别名]
# 或者: from six import get_method_self [as 别名]
def is_bound_method(method):
    """Returns if the given method is bound to an object."""
    return get_method_self(method) is not None 
开发者ID:openstack,项目名称:oslo.utils,代码行数:5,代码来源:reflection.py

示例15: get_function_path

# 需要导入模块: import six [as 别名]
# 或者: from six import get_method_self [as 别名]
def get_function_path(function, bound_to=None):
    """Get received function path (as string), to import function later
    with `import_string`.
    """
    if isinstance(function, six.string_types):
        return function

    # static and class methods
    if hasattr(function, '__func__'):
        real_function = function.__func__
    elif callable(function):
        real_function = function
    else:
        return function

    func_path = []

    module = getattr(real_function, '__module__', '__main__')
    if module:
        func_path.append(module)

    if not bound_to:
        try:
            bound_to = six.get_method_self(function)
        except AttributeError:
            pass

    if bound_to:
        if isinstance(bound_to, six.class_types):
            func_path.append(bound_to.__name__)
        else:
            func_path.append(bound_to.__class__.__name__)
        func_path.append(real_function.__name__)
    else:
        # qualname is available in Python 3 only
        func_path.append(getattr(real_function, '__qualname__', real_function.__name__))

    return '.'.join(func_path) 
开发者ID:Bahus,项目名称:easy_cache,代码行数:40,代码来源:utils.py


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