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


Python _weakref.proxy方法代码示例

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


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

示例1: __init__

# 需要导入模块: import _weakref [as 别名]
# 或者: from _weakref import proxy [as 别名]
def __init__(*args, **kwds):
        '''Initialize an ordered dictionary.  The signature is the same as
        regular dictionaries, but keyword arguments are not recommended because
        their insertion order is arbitrary.

        '''
        if not args:
            raise TypeError("descriptor '__init__' of 'OrderedDict' object "
                            "needs an argument")
        self = args[0]
        args = args[1:]
        if len(args) > 1:
            raise TypeError('expected at most 1 arguments, got %d' % len(args))
        try:
            self.__root
        except AttributeError:
            self.__hardroot = _Link()
            self.__root = root = _proxy(self.__hardroot)
            root.prev = root.next = root
            self.__map = {}
        self.__update(*args, **kwds) 
开发者ID:Soft8Soft,项目名称:verge3d-blender-addon,代码行数:23,代码来源:misc.py

示例2: test_proxy_dir

# 需要导入模块: import _weakref [as 别名]
# 或者: from _weakref import proxy [as 别名]
def test_proxy_dir(self):
        # dir on a deletex proxy should return an empty list,
        # not throw.
        for cls in [NonCallableClass, CallableClass]:
            def run_test():
                a = cls()
                b = _weakref.proxy(a)

                self.assertEqual(dir(a), dir(b))
                del(a)

                return b

            prxy = run_test()
            gc.collect()
            # gc collection seems to take longer on OSX
            if is_osx: time.sleep(2)
            #This will fail if original object has not been garbage collected.
            self.assertEqual(dir(prxy), []) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:21,代码来源:test__weakref.py

示例3: test_special_methods

# 需要导入模块: import _weakref [as 别名]
# 或者: from _weakref import proxy [as 别名]
def test_special_methods(self):
        for cls in [NonCallableClass, CallableClass]:
            # calling repr should give us weakproxy's repr,
            # calling __repr__ should give us the underlying objects
            # repr
            a = cls()
            b = _weakref.proxy(a)

            self.assertTrue(repr(b).startswith('<weakproxy at'))

            self.assertEqual(repr(a), b.__repr__())

            keep_alive(a)

        # calling a special method should work
        class strable(object):
                def __str__(self): return 'abc'

        a = strable()
        b = _weakref.proxy(a)
        self.assertEqual(str(b), 'abc')

        keep_alive(a) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:25,代码来源:test__weakref.py

示例4: test_equals

# 需要导入模块: import _weakref [as 别名]
# 或者: from _weakref import proxy [as 别名]
def test_equals(self):
        global called
        class C:
            for method, op in [('__eq__', '=='), ('__gt__', '>'), ('__lt__', '<'), ('__ge__', '>='), ('__le__', '<='), ('__ne__', '!=')]:
                exec("""
def %s(self, *args, **kwargs):
    global called
    called = '%s'
    return True
""" % (method, op))

        a = C()
        x = _weakref.proxy(a)
        for op in ('==', '>', '<', '>=', '<=', '!='):
            self.assertEqual(eval('a ' + op + ' 3'), True);  self.assertEqual(called, op); called = None
            if op == '==' or op == '!=':
                self.assertEqual(eval('x ' + op + ' 3'), op == '!='); self.assertEqual(called, None)
                self.assertEqual(eval('3 ' + op + ' x'), op == '!='); self.assertEqual(called, None)
            else:
                res1, res2 = eval('x ' + op + ' 3'), eval('3 ' + op + ' x')
                self.assertEqual(called, None)
                self.assertTrue((res1 == True and res2 == False) or (res1 == False and res2 == True)) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:24,代码来源:test__weakref.py

示例5: __init__

# 需要导入模块: import _weakref [as 别名]
# 或者: from _weakref import proxy [as 别名]
def __init__(*args, **kwds):
        '''Initialize an ordered dictionary.  The signature is the same as
        regular dictionaries, but keyword arguments are not recommended because
        their insertion order is arbitrary.

        '''
        if not args:
            raise TypeError("descriptor '__init__' of 'OrderedDict' object "
                            "needs an argument")
        self, *args = args
        if len(args) > 1:
            raise TypeError('expected at most 1 arguments, got %d' % len(args))
        try:
            self.__root
        except AttributeError:
            self.__hardroot = _Link()
            self.__root = root = _proxy(self.__hardroot)
            root.prev = root.next = root
            self.__map = {}
        self.__update(*args, **kwds) 
开发者ID:awemulya,项目名称:kobo-predict,代码行数:22,代码来源:__init__.py

示例6: __init__

# 需要导入模块: import _weakref [as 别名]
# 或者: from _weakref import proxy [as 别名]
def __init__(*args, **kwds):
        '''Initialize an ordered dictionary.  The signature is the same as
        regular dictionaries.  Keyword argument order is preserved.
        '''
        if not args:
            raise TypeError("descriptor '__init__' of 'OrderedDict' object "
                            "needs an argument")
        self, *args = args
        if len(args) > 1:
            raise TypeError('expected at most 1 arguments, got %d' % len(args))
        try:
            self.__root
        except AttributeError:
            self.__hardroot = _Link()
            self.__root = root = _proxy(self.__hardroot)
            root.prev = root.next = root
            self.__map = {}
        self.__update(*args, **kwds) 
开发者ID:Relph1119,项目名称:GraphicDesignPatternByPython,代码行数:20,代码来源:__init__.py

示例7: test_cp14632

# 需要导入模块: import _weakref [as 别名]
# 或者: from _weakref import proxy [as 别名]
def test_cp14632(self):
        '''
        Make sure '_weakref.proxy(...)==xyz' does not throw after '...'
        has been deleted.
        '''
        def helper_func():
            class C:
                def __eq__(self, *args, **kwargs): return True

            a = C()
            self.assertTrue(C()==3)
            x = _weakref.proxy(a)
            y = _weakref.proxy(a)
            self.assertEqual(x, y)
            keep_alive(a) #Just to keep 'a' alive up to this point.

            return x, y

        x, y = helper_func()
        gc.collect()

        self.assertRaises(ReferenceError, lambda: x==3)
        self.assertRaises(ReferenceError, lambda: x==y) 
开发者ID:IronLanguages,项目名称:ironpython3,代码行数:25,代码来源:test__weakref.py

示例8: test_comparison

# 需要导入模块: import _weakref [as 别名]
# 或者: from _weakref import proxy [as 别名]
def test_comparison(self):
        global called
        class C:
            for method, op in [('__eq__', '=='), ('__gt__', '>'), ('__lt__', '<'), ('__ge__', '>='), ('__le__', '<='), ('__ne__', '!=')]:
                exec("""
def %s(self, *args, **kwargs):
    global called
    called = '%s'
    return True
""" % (method, op))

        class D(C):
            def __call__(self):
                pass

        A = [ C(), D() ]
        X = [ _weakref.proxy(a) for a in A ]
        for (a, x) in zip(A, X):
            for op in ('==', '>', '<', '>=', '<=', '!='):
                self.assertEqual(eval('a ' + op + ' 3'), True);  self.assertEqual(called, op); called = None
                self.assertEqual(eval('x ' + op + ' 3'), True);  self.assertEqual(called, op); called = None 
开发者ID:IronLanguages,项目名称:ironpython3,代码行数:23,代码来源:test__weakref.py

示例9: __setitem__

# 需要导入模块: import _weakref [as 别名]
# 或者: from _weakref import proxy [as 别名]
def __setitem__(self, key, value,
                    dict_setitem=dict.__setitem__, proxy=_proxy, Link=_Link):
        'od.__setitem__(i, y) <==> od[i]=y'
        # Setting a new item creates a new link at the end of the linked list,
        # and the inherited dictionary is updated with the new key/value pair.
        if key not in self:
            self.__map[key] = link = Link()
            root = self.__root
            last = root.prev
            link.prev, link.next, link.key = last, root, key
            last.next = link
            root.prev = proxy(link)
        dict_setitem(self, key, value) 
开发者ID:Soft8Soft,项目名称:verge3d-blender-addon,代码行数:15,代码来源:misc.py


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