Python _weakref 模块,ref() 实例源码

我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用_weakref.ref()

项目:deb-python-cassandra-driver    作者:openstack    | 项目源码 | 文件源码
def __init__(self, data=None):
        self.data = set()

        def _remove(item, selfref=ref(self)):
            self = selfref()
            if self is not None:
                if self._iterating:
                    self._pending_removals.append(item)
                else:
                    self.data.discard(item)

        self._remove = _remove
        # A list of keys to be removed
        self._pending_removals = []
        self._iterating = set()
        if data is not None:
            self.update(data)
项目:SwiftKitten    作者:johncsnyder    | 项目源码 | 文件源码
def test_new_handle():
    import _weakref
    BVoidP = new_pointer_type(new_void_type())
    BCharP = new_pointer_type(new_primitive_type("char"))
    class mylist(list):
        pass
    o = mylist([2, 3, 4])
    x = newp_handle(BVoidP, o)
    assert repr(x) == "<cdata 'void *' handle to [2, 3, 4]>"
    assert x
    assert from_handle(x) is o
    assert from_handle(cast(BCharP, x)) is o
    wr = _weakref.ref(o)
    del o
    import gc; gc.collect()
    assert wr() is not None
    assert from_handle(x) == list((2, 3, 4))
    assert from_handle(cast(BCharP, x)) == list((2, 3, 4))
    del x
    for i in range(3):
        if wr() is not None:
            import gc; gc.collect()
    assert wr() is None
    py.test.raises(RuntimeError, from_handle, cast(BCharP, 0))
项目:intera_sdk    作者:RethinkRobotics    | 项目源码 | 文件源码
def __init__(self, data=None):
        self.data = set()

        def _remove(item, selfref=ref(self)):
            self = selfref()
            if self is not None:
                if self._iterating:
                    self._pending_removals.append(item)
                else:
                    self.data.discard(item)
        self._remove = _remove
        # A list of keys to be removed
        self._pending_removals = []
        self._iterating = set()
        if data is not None:
            self.update(data)
项目:python-    作者:secondtonone1    | 项目源码 | 文件源码
def __init__(self, weakcontainer):
        # Don't create cycles
        self.weakcontainer = ref(weakcontainer)
项目:python-    作者:secondtonone1    | 项目源码 | 文件源码
def __init__(self, data=None):
        self.data = set()
        def _remove(item, selfref=ref(self)):
            self = selfref()
            if self is not None:
                if self._iterating:
                    self._pending_removals.append(item)
                else:
                    self.data.discard(item)
        self._remove = _remove
        # A list of keys to be removed
        self._pending_removals = []
        self._iterating = set()
        if data is not None:
            self.update(data)
项目:python-    作者:secondtonone1    | 项目源码 | 文件源码
def __contains__(self, item):
        try:
            wr = ref(item)
        except TypeError:
            return False
        return wr in self.data
项目:python-    作者:secondtonone1    | 项目源码 | 文件源码
def add(self, item):
        if self._pending_removals:
            self._commit_removals()
        self.data.add(ref(item, self._remove))
项目:python-    作者:secondtonone1    | 项目源码 | 文件源码
def remove(self, item):
        if self._pending_removals:
            self._commit_removals()
        self.data.remove(ref(item))
项目:python-    作者:secondtonone1    | 项目源码 | 文件源码
def __isub__(self, other):
        if self._pending_removals:
            self._commit_removals()
        if self is other:
            self.data.clear()
        else:
            self.data.difference_update(ref(item) for item in other)
        return self
项目:python-    作者:secondtonone1    | 项目源码 | 文件源码
def __iand__(self, other):
        if self._pending_removals:
            self._commit_removals()
        self.data.intersection_update(ref(item) for item in other)
        return self
项目:python-    作者:secondtonone1    | 项目源码 | 文件源码
def issubset(self, other):
        return self.data.issubset(ref(item) for item in other)
项目:python-    作者:secondtonone1    | 项目源码 | 文件源码
def __lt__(self, other):
        return self.data < set(ref(item) for item in other)
项目:python-    作者:secondtonone1    | 项目源码 | 文件源码
def issuperset(self, other):
        return self.data.issuperset(ref(item) for item in other)
项目:python-    作者:secondtonone1    | 项目源码 | 文件源码
def __eq__(self, other):
        if not isinstance(other, self.__class__):
            return NotImplemented
        return self.data == set(ref(item) for item in other)
项目:python-    作者:secondtonone1    | 项目源码 | 文件源码
def __ixor__(self, other):
        if self._pending_removals:
            self._commit_removals()
        if self is other:
            self.data.clear()
        else:
            self.data.symmetric_difference_update(ref(item, self._remove) for item in other)
        return self
项目:kinect-2-libras    作者:inessadl    | 项目源码 | 文件源码
def __init__(self, weakcontainer):
        # Don't create cycles
        self.weakcontainer = ref(weakcontainer)
项目:kinect-2-libras    作者:inessadl    | 项目源码 | 文件源码
def __init__(self, data=None):
        self.data = set()
        def _remove(item, selfref=ref(self)):
            self = selfref()
            if self is not None:
                if self._iterating:
                    self._pending_removals.append(item)
                else:
                    self.data.discard(item)
        self._remove = _remove
        # A list of keys to be removed
        self._pending_removals = []
        self._iterating = set()
        if data is not None:
            self.update(data)
项目:kinect-2-libras    作者:inessadl    | 项目源码 | 文件源码
def __contains__(self, item):
        try:
            wr = ref(item)
        except TypeError:
            return False
        return wr in self.data
项目:kinect-2-libras    作者:inessadl    | 项目源码 | 文件源码
def add(self, item):
        if self._pending_removals:
            self._commit_removals()
        self.data.add(ref(item, self._remove))
项目:kinect-2-libras    作者:inessadl    | 项目源码 | 文件源码
def remove(self, item):
        if self._pending_removals:
            self._commit_removals()
        self.data.remove(ref(item))
项目:kinect-2-libras    作者:inessadl    | 项目源码 | 文件源码
def difference_update(self, other):
        if self._pending_removals:
            self._commit_removals()
        if self is other:
            self.data.clear()
        else:
            self.data.difference_update(ref(item) for item in other)
项目:kinect-2-libras    作者:inessadl    | 项目源码 | 文件源码
def __isub__(self, other):
        if self._pending_removals:
            self._commit_removals()
        if self is other:
            self.data.clear()
        else:
            self.data.difference_update(ref(item) for item in other)
        return self
项目:kinect-2-libras    作者:inessadl    | 项目源码 | 文件源码
def intersection_update(self, other):
        if self._pending_removals:
            self._commit_removals()
        self.data.intersection_update(ref(item) for item in other)
项目:kinect-2-libras    作者:inessadl    | 项目源码 | 文件源码
def __iand__(self, other):
        if self._pending_removals:
            self._commit_removals()
        self.data.intersection_update(ref(item) for item in other)
        return self
项目:kinect-2-libras    作者:inessadl    | 项目源码 | 文件源码
def issubset(self, other):
        return self.data.issubset(ref(item) for item in other)
项目:kinect-2-libras    作者:inessadl    | 项目源码 | 文件源码
def issuperset(self, other):
        return self.data.issuperset(ref(item) for item in other)
项目:kinect-2-libras    作者:inessadl    | 项目源码 | 文件源码
def __ge__(self, other):
        return self.data >= set(ref(item) for item in other)
项目:kinect-2-libras    作者:inessadl    | 项目源码 | 文件源码
def __eq__(self, other):
        if not isinstance(other, self.__class__):
            return NotImplemented
        return self.data == set(ref(item) for item in other)
项目:kinect-2-libras    作者:inessadl    | 项目源码 | 文件源码
def symmetric_difference_update(self, other):
        if self._pending_removals:
            self._commit_removals()
        if self is other:
            self.data.clear()
        else:
            self.data.symmetric_difference_update(ref(item) for item in other)
项目:kinect-2-libras    作者:inessadl    | 项目源码 | 文件源码
def __ixor__(self, other):
        if self._pending_removals:
            self._commit_removals()
        if self is other:
            self.data.clear()
        else:
            self.data.symmetric_difference_update(ref(item) for item in other)
        return self
项目:deb-python-cassandra-driver    作者:openstack    | 项目源码 | 文件源码
def __init__(self, weakcontainer):
        # Don't create cycles
        self.weakcontainer = ref(weakcontainer)
项目:deb-python-cassandra-driver    作者:openstack    | 项目源码 | 文件源码
def __contains__(self, item):
        return ref(item) in self.data
项目:deb-python-cassandra-driver    作者:openstack    | 项目源码 | 文件源码
def add(self, item):
        if self._pending_removals:
            self._commit_removals()
        self.data.add(ref(item, self._remove))
项目:deb-python-cassandra-driver    作者:openstack    | 项目源码 | 文件源码
def remove(self, item):
        if self._pending_removals:
            self._commit_removals()
        self.data.remove(ref(item))
项目:deb-python-cassandra-driver    作者:openstack    | 项目源码 | 文件源码
def difference_update(self, other):
        if self._pending_removals:
            self._commit_removals()
        if self is other:
            self.data.clear()
        else:
            self.data.difference_update(ref(item) for item in other)
项目:deb-python-cassandra-driver    作者:openstack    | 项目源码 | 文件源码
def __isub__(self, other):
        if self._pending_removals:
            self._commit_removals()
        if self is other:
            self.data.clear()
        else:
            self.data.difference_update(ref(item) for item in other)
        return self
项目:deb-python-cassandra-driver    作者:openstack    | 项目源码 | 文件源码
def intersection_update(self, other):
        if self._pending_removals:
            self._commit_removals()
        self.data.intersection_update(ref(item) for item in other)
项目:deb-python-cassandra-driver    作者:openstack    | 项目源码 | 文件源码
def __iand__(self, other):
        if self._pending_removals:
            self._commit_removals()
        self.data.intersection_update(ref(item) for item in other)
        return self
项目:deb-python-cassandra-driver    作者:openstack    | 项目源码 | 文件源码
def issubset(self, other):
        return self.data.issubset(ref(item) for item in other)
项目:deb-python-cassandra-driver    作者:openstack    | 项目源码 | 文件源码
def issuperset(self, other):
        return self.data.issuperset(ref(item) for item in other)
项目:deb-python-cassandra-driver    作者:openstack    | 项目源码 | 文件源码
def __ge__(self, other):
        return self.data >= set(ref(item) for item in other)
项目:deb-python-cassandra-driver    作者:openstack    | 项目源码 | 文件源码
def __eq__(self, other):
        if not isinstance(other, self.__class__):
            return NotImplemented
        return self.data == set(ref(item) for item in other)
项目:deb-python-cassandra-driver    作者:openstack    | 项目源码 | 文件源码
def symmetric_difference_update(self, other):
        if self._pending_removals:
            self._commit_removals()
        if self is other:
            self.data.clear()
        else:
            self.data.symmetric_difference_update(ref(item) for item in other)
项目:deb-python-cassandra-driver    作者:openstack    | 项目源码 | 文件源码
def __ixor__(self, other):
        if self._pending_removals:
            self._commit_removals()
        if self is other:
            self.data.clear()
        else:
            self.data.symmetric_difference_update(ref(item) for item in other)
        return self
项目:swjtu-pyscraper    作者:Desgard    | 项目源码 | 文件源码
def __init__(self, weakcontainer):
        # Don't create cycles
        self.weakcontainer = ref(weakcontainer)
项目:swjtu-pyscraper    作者:Desgard    | 项目源码 | 文件源码
def __init__(self, data=None):
        self.data = set()
        def _remove(item, selfref=ref(self)):
            self = selfref()
            if self is not None:
                if self._iterating:
                    self._pending_removals.append(item)
                else:
                    self.data.discard(item)
        self._remove = _remove
        # A list of keys to be removed
        self._pending_removals = []
        self._iterating = set()
        if data is not None:
            self.update(data)
项目:swjtu-pyscraper    作者:Desgard    | 项目源码 | 文件源码
def __contains__(self, item):
        try:
            wr = ref(item)
        except TypeError:
            return False
        return wr in self.data
项目:swjtu-pyscraper    作者:Desgard    | 项目源码 | 文件源码
def add(self, item):
        if self._pending_removals:
            self._commit_removals()
        self.data.add(ref(item, self._remove))
项目:swjtu-pyscraper    作者:Desgard    | 项目源码 | 文件源码
def remove(self, item):
        if self._pending_removals:
            self._commit_removals()
        self.data.remove(ref(item))
项目:swjtu-pyscraper    作者:Desgard    | 项目源码 | 文件源码
def __isub__(self, other):
        if self._pending_removals:
            self._commit_removals()
        if self is other:
            self.data.clear()
        else:
            self.data.difference_update(ref(item) for item in other)
        return self