Edit File by line
/home/barbar84/www/wp-conte.../plugins/sujqvwi/ShExBy/shex_roo.../proc/self/root/lib64/python3....
File: _weakrefset.py
# Access WeakSet through the weakref module.
[0] Fix | Delete
# This code is separated-out because it is needed
[1] Fix | Delete
# by abc.py to load everything else at startup.
[2] Fix | Delete
[3] Fix | Delete
from _weakref import ref
[4] Fix | Delete
[5] Fix | Delete
__all__ = ['WeakSet']
[6] Fix | Delete
[7] Fix | Delete
[8] Fix | Delete
class _IterationGuard:
[9] Fix | Delete
# This context manager registers itself in the current iterators of the
[10] Fix | Delete
# weak container, such as to delay all removals until the context manager
[11] Fix | Delete
# exits.
[12] Fix | Delete
# This technique should be relatively thread-safe (since sets are).
[13] Fix | Delete
[14] Fix | Delete
def __init__(self, weakcontainer):
[15] Fix | Delete
# Don't create cycles
[16] Fix | Delete
self.weakcontainer = ref(weakcontainer)
[17] Fix | Delete
[18] Fix | Delete
def __enter__(self):
[19] Fix | Delete
w = self.weakcontainer()
[20] Fix | Delete
if w is not None:
[21] Fix | Delete
w._iterating.add(self)
[22] Fix | Delete
return self
[23] Fix | Delete
[24] Fix | Delete
def __exit__(self, e, t, b):
[25] Fix | Delete
w = self.weakcontainer()
[26] Fix | Delete
if w is not None:
[27] Fix | Delete
s = w._iterating
[28] Fix | Delete
s.remove(self)
[29] Fix | Delete
if not s:
[30] Fix | Delete
w._commit_removals()
[31] Fix | Delete
[32] Fix | Delete
[33] Fix | Delete
class WeakSet:
[34] Fix | Delete
def __init__(self, data=None):
[35] Fix | Delete
self.data = set()
[36] Fix | Delete
def _remove(item, selfref=ref(self)):
[37] Fix | Delete
self = selfref()
[38] Fix | Delete
if self is not None:
[39] Fix | Delete
if self._iterating:
[40] Fix | Delete
self._pending_removals.append(item)
[41] Fix | Delete
else:
[42] Fix | Delete
self.data.discard(item)
[43] Fix | Delete
self._remove = _remove
[44] Fix | Delete
# A list of keys to be removed
[45] Fix | Delete
self._pending_removals = []
[46] Fix | Delete
self._iterating = set()
[47] Fix | Delete
if data is not None:
[48] Fix | Delete
self.update(data)
[49] Fix | Delete
[50] Fix | Delete
def _commit_removals(self):
[51] Fix | Delete
l = self._pending_removals
[52] Fix | Delete
discard = self.data.discard
[53] Fix | Delete
while l:
[54] Fix | Delete
discard(l.pop())
[55] Fix | Delete
[56] Fix | Delete
def __iter__(self):
[57] Fix | Delete
with _IterationGuard(self):
[58] Fix | Delete
for itemref in self.data:
[59] Fix | Delete
item = itemref()
[60] Fix | Delete
if item is not None:
[61] Fix | Delete
# Caveat: the iterator will keep a strong reference to
[62] Fix | Delete
# `item` until it is resumed or closed.
[63] Fix | Delete
yield item
[64] Fix | Delete
[65] Fix | Delete
def __len__(self):
[66] Fix | Delete
return len(self.data) - len(self._pending_removals)
[67] Fix | Delete
[68] Fix | Delete
def __contains__(self, item):
[69] Fix | Delete
try:
[70] Fix | Delete
wr = ref(item)
[71] Fix | Delete
except TypeError:
[72] Fix | Delete
return False
[73] Fix | Delete
return wr in self.data
[74] Fix | Delete
[75] Fix | Delete
def __reduce__(self):
[76] Fix | Delete
return (self.__class__, (list(self),),
[77] Fix | Delete
getattr(self, '__dict__', None))
[78] Fix | Delete
[79] Fix | Delete
def add(self, item):
[80] Fix | Delete
if self._pending_removals:
[81] Fix | Delete
self._commit_removals()
[82] Fix | Delete
self.data.add(ref(item, self._remove))
[83] Fix | Delete
[84] Fix | Delete
def clear(self):
[85] Fix | Delete
if self._pending_removals:
[86] Fix | Delete
self._commit_removals()
[87] Fix | Delete
self.data.clear()
[88] Fix | Delete
[89] Fix | Delete
def copy(self):
[90] Fix | Delete
return self.__class__(self)
[91] Fix | Delete
[92] Fix | Delete
def pop(self):
[93] Fix | Delete
if self._pending_removals:
[94] Fix | Delete
self._commit_removals()
[95] Fix | Delete
while True:
[96] Fix | Delete
try:
[97] Fix | Delete
itemref = self.data.pop()
[98] Fix | Delete
except KeyError:
[99] Fix | Delete
raise KeyError('pop from empty WeakSet')
[100] Fix | Delete
item = itemref()
[101] Fix | Delete
if item is not None:
[102] Fix | Delete
return item
[103] Fix | Delete
[104] Fix | Delete
def remove(self, item):
[105] Fix | Delete
if self._pending_removals:
[106] Fix | Delete
self._commit_removals()
[107] Fix | Delete
self.data.remove(ref(item))
[108] Fix | Delete
[109] Fix | Delete
def discard(self, item):
[110] Fix | Delete
if self._pending_removals:
[111] Fix | Delete
self._commit_removals()
[112] Fix | Delete
self.data.discard(ref(item))
[113] Fix | Delete
[114] Fix | Delete
def update(self, other):
[115] Fix | Delete
if self._pending_removals:
[116] Fix | Delete
self._commit_removals()
[117] Fix | Delete
for element in other:
[118] Fix | Delete
self.add(element)
[119] Fix | Delete
[120] Fix | Delete
def __ior__(self, other):
[121] Fix | Delete
self.update(other)
[122] Fix | Delete
return self
[123] Fix | Delete
[124] Fix | Delete
def difference(self, other):
[125] Fix | Delete
newset = self.copy()
[126] Fix | Delete
newset.difference_update(other)
[127] Fix | Delete
return newset
[128] Fix | Delete
__sub__ = difference
[129] Fix | Delete
[130] Fix | Delete
def difference_update(self, other):
[131] Fix | Delete
self.__isub__(other)
[132] Fix | Delete
def __isub__(self, other):
[133] Fix | Delete
if self._pending_removals:
[134] Fix | Delete
self._commit_removals()
[135] Fix | Delete
if self is other:
[136] Fix | Delete
self.data.clear()
[137] Fix | Delete
else:
[138] Fix | Delete
self.data.difference_update(ref(item) for item in other)
[139] Fix | Delete
return self
[140] Fix | Delete
[141] Fix | Delete
def intersection(self, other):
[142] Fix | Delete
return self.__class__(item for item in other if item in self)
[143] Fix | Delete
__and__ = intersection
[144] Fix | Delete
[145] Fix | Delete
def intersection_update(self, other):
[146] Fix | Delete
self.__iand__(other)
[147] Fix | Delete
def __iand__(self, other):
[148] Fix | Delete
if self._pending_removals:
[149] Fix | Delete
self._commit_removals()
[150] Fix | Delete
self.data.intersection_update(ref(item) for item in other)
[151] Fix | Delete
return self
[152] Fix | Delete
[153] Fix | Delete
def issubset(self, other):
[154] Fix | Delete
return self.data.issubset(ref(item) for item in other)
[155] Fix | Delete
__le__ = issubset
[156] Fix | Delete
[157] Fix | Delete
def __lt__(self, other):
[158] Fix | Delete
return self.data < set(ref(item) for item in other)
[159] Fix | Delete
[160] Fix | Delete
def issuperset(self, other):
[161] Fix | Delete
return self.data.issuperset(ref(item) for item in other)
[162] Fix | Delete
__ge__ = issuperset
[163] Fix | Delete
[164] Fix | Delete
def __gt__(self, other):
[165] Fix | Delete
return self.data > set(ref(item) for item in other)
[166] Fix | Delete
[167] Fix | Delete
def __eq__(self, other):
[168] Fix | Delete
if not isinstance(other, self.__class__):
[169] Fix | Delete
return NotImplemented
[170] Fix | Delete
return self.data == set(ref(item) for item in other)
[171] Fix | Delete
[172] Fix | Delete
def symmetric_difference(self, other):
[173] Fix | Delete
newset = self.copy()
[174] Fix | Delete
newset.symmetric_difference_update(other)
[175] Fix | Delete
return newset
[176] Fix | Delete
__xor__ = symmetric_difference
[177] Fix | Delete
[178] Fix | Delete
def symmetric_difference_update(self, other):
[179] Fix | Delete
self.__ixor__(other)
[180] Fix | Delete
def __ixor__(self, other):
[181] Fix | Delete
if self._pending_removals:
[182] Fix | Delete
self._commit_removals()
[183] Fix | Delete
if self is other:
[184] Fix | Delete
self.data.clear()
[185] Fix | Delete
else:
[186] Fix | Delete
self.data.symmetric_difference_update(ref(item, self._remove) for item in other)
[187] Fix | Delete
return self
[188] Fix | Delete
[189] Fix | Delete
def union(self, other):
[190] Fix | Delete
return self.__class__(e for s in (self, other) for e in s)
[191] Fix | Delete
__or__ = union
[192] Fix | Delete
[193] Fix | Delete
def isdisjoint(self, other):
[194] Fix | Delete
return len(self.intersection(other)) == 0
[195] Fix | Delete
[196] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function