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


Python six.get_unbound_function方法代码示例

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


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

示例1: test_one_stub_duplicated_as_context_manager

# 需要导入模块: import six [as 别名]
# 或者: from six import get_unbound_function [as 别名]
def test_one_stub_duplicated_as_context_manager(self):
        original_client_send_request = Client.send_request
        original_client_get_all_responses = Client.get_all_responses

        stub = stub_action('test_service', 'test_action_1', body={'value': 1})

        with stub as stub_test_action_1, stub as second_stub_test_action_1:
            response = self.client.call_action('test_service', 'test_action_1')

        # Check stub is correctly reverted
        for client_func, original_func in (
            (Client.send_request, original_client_send_request),
            (Client.get_all_responses, original_client_get_all_responses),
        ):
            self.assertTrue(
                six.get_unbound_function(client_func) is six.get_unbound_function(original_func)  # type: ignore
            )

        self.assertEqual({'value': 1}, response.body)

        self.assertTrue(stub_test_action_1 is second_stub_test_action_1)
        self.assertEqual(1, stub_test_action_1.call_count)
        self.assertEqual({}, stub_test_action_1.call_body)
        stub_test_action_1.assert_called_once_with({}) 
开发者ID:eventbrite,项目名称:pysoa,代码行数:26,代码来源:test_stub_service.py

示例2: get_unbound_function

# 需要导入模块: import six [as 别名]
# 或者: from six import get_unbound_function [as 别名]
def get_unbound_function(unbound):
        # Op.make_thunk isn't bound, so don't have a __func__ attr.
        # But bound method, have a __func__ method that point to the
        # not bound method. That is what we want.
        if hasattr(unbound, '__func__'):
            return unbound.__func__
        return unbound 
开发者ID:muhanzhang,项目名称:D-VAE,代码行数:9,代码来源:__init__.py

示例3: autodoc

# 需要导入模块: import six [as 别名]
# 或者: from six import get_unbound_function [as 别名]
def autodoc(base_doc="", classess=DEFAULT_CLASSESS, add_classess=None, skip_classess=None):
    def copy_method(cls, method_name, method):
        """ create facade for a method with preservation of original docstring """
        @wraps(method)
        def shadow_method(self, *args, **kwargs):
            return method(self, *args, **kwargs)
        shadow_method.__doc__ = method.__doc__
        setattr(cls, method_name, shadow_method)

    def wrapped(cls):
        applies_to = set([])
        classess_to_apply = [c for c in classess if not skip_classess or c not in skip_classess]
        if add_classess:
            classess_to_apply += [c for c in add_classess if not skip_classess or c not in skip_classess]

        for autodoc_class in classess_to_apply:
            applies_to |= set(autodoc_class.applies_to)

        # Create facades for original methods - docstring of methods are immutable, so we need to change docstring of
        # functions. But without shadowing the method.__func__ will point to the same function for classes that
        # inherits them from the same parents.
        for method_name in applies_to:
            method = getattr(cls, method_name, None)
            if method:
                copy_method(cls, method_name, method)

        # update docstrings
        for autodoc_class in classess_to_apply:
            for method_name in autodoc_class.applies_to:
                method = getattr(cls, method_name, None)
                if method:
                    six.get_unbound_function(method).__doc__ = \
                        autodoc_class.update_docstring(cls, base_doc, six.get_unbound_function(method).__doc__,
                                                       method_name)
        return cls
    return wrapped 
开发者ID:HealthByRo,项目名称:drf_tweaks,代码行数:38,代码来源:autodoc.py

示例4: test_get_unbound_function

# 需要导入模块: import six [as 别名]
# 或者: from six import get_unbound_function [as 别名]
def test_get_unbound_function():
    class X(object):
        def m(self):
            pass
    assert six.get_unbound_function(X.m) is X.__dict__["m"] 
开发者ID:benjaminp,项目名称:six,代码行数:7,代码来源:test_six.py

示例5: __getattr__

# 需要导入模块: import six [as 别名]
# 或者: from six import get_unbound_function [as 别名]
def __getattr__(self, name):
        if name in (_[0] for _ in getmembers(UserEditable, predicate=isroutine)) and \
                self.is_content_editable:
            self._content_editable = True
            setattr(self, name, six.create_bound_method(
                six.get_unbound_function(getattr(UserEditable, name)), self))
            return getattr(self, name)
        else:
            raise AttributeError("Element '{}' has no attribute "
                                 "'{}'".format(self.__class__.__name__.capitalize(), name)) 
开发者ID:watir,项目名称:nerodia,代码行数:12,代码来源:element.py


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