Lines Matching refs:self
60 def __reversed__(self):
61 yield from reversed(self._mapping)
65 def __reversed__(self):
66 for key in reversed(self._mapping):
67 yield (key, self._mapping[key])
71 def __reversed__(self):
72 for key in reversed(self._mapping):
73 yield self._mapping[key]
85 # The internal self.__map dict maps keys to links in a doubly linked list.
88 # The sentinel is in self.__hardroot with a weakref proxy in self.__root.
90 # Individual links are kept alive by the hard reference in self.__map.
93 def __init__(self, other=(), /, **kwds):
98 self.__root
100 self.__hardroot = _Link()
101 self.__root = root = _proxy(self.__hardroot)
103 self.__map = {}
104 self.__update(other, **kwds)
106 def __setitem__(self, key, value,
111 if key not in self:
112 self.__map[key] = link = Link()
113 root = self.__root
118 dict_setitem(self, key, value)
120 def __delitem__(self, key, dict_delitem=dict.__delitem__):
122 # Deleting an existing item uses self.__map to find the link which gets
124 dict_delitem(self, key)
125 link = self.__map.pop(key)
133 def __iter__(self):
136 root = self.__root
142 def __reversed__(self):
145 root = self.__root
151 def clear(self):
153 root = self.__root
155 self.__map.clear()
156 dict.clear(self)
158 def popitem(self, last=True):
163 if not self:
165 root = self.__root
177 del self.__map[key]
178 value = dict.pop(self, key)
181 def move_to_end(self, key, last=True):
186 link = self.__map[key]
192 root = self.__root
206 def __sizeof__(self):
208 n = len(self) + 1 # number of links including root
209 size = sizeof(self.__dict__) # instance dictionary
210 size += sizeof(self.__map) * 2 # internal dict and inherited dict
211 size += sizeof(self.__hardroot) * n # link objects
212 size += sizeof(self.__root) * n # proxy objects
217 def keys(self):
219 return _OrderedDictKeysView(self)
221 def items(self):
223 return _OrderedDictItemsView(self)
225 def values(self):
227 return _OrderedDictValuesView(self)
233 def pop(self, key, default=__marker):
239 marker = self.__marker
240 result = dict.pop(self, key, marker)
243 link = self.__map.pop(key)
255 def setdefault(self, key, default=None):
260 if key in self:
261 return self[key]
262 self[key] = default
266 def __repr__(self):
268 if not self:
269 return '%s()' % (self.__class__.__name__,)
270 return '%s(%r)' % (self.__class__.__name__, list(self.items()))
272 def __reduce__(self):
274 state = self.__getstate__()
289 return self.__class__, (), state, None, iter(self.items())
291 def copy(self):
293 return self.__class__(self)
299 self = cls()
301 self[key] = value
302 return self
304 def __eq__(self, other):
310 return dict.__eq__(self, other) and all(map(_eq, self, other))
311 return dict.__eq__(self, other)
313 def __ior__(self, other):
314 self.update(other)
315 return self
317 def __or__(self, other):
320 new = self.__class__(self)
324 def __ror__(self, other):
327 new = self.__class__(other)
328 new.update(self)
450 def _replace(self, /, **kwds):
451 result = self._make(_map(kwds.pop, field_names, self))
459 def __repr__(self):
461 return self.__class__.__name__ + repr_fmt % self
463 def _asdict(self):
465 return _dict(_zip(self._fields, self))
467 def __getnewargs__(self):
468 'Return self as a plain tuple. Used by copy and pickle.'
469 return _tuple(self)
585 def __init__(self, iterable=None, /, **kwds):
597 self.update(iterable, **kwds)
599 def __missing__(self, key):
601 # Needed so that self[missing_item] does not raise KeyError
604 def total(self):
606 return sum(self.values())
608 def most_common(self, n=None):
618 return sorted(self.items(), key=_itemgetter(1), reverse=True)
622 return heapq.nlargest(n, self.items(), key=_itemgetter(1))
624 def elements(self):
642 return _chain.from_iterable(_starmap(_repeat, self.items()))
658 def update(self, iterable=None, /, **kwds):
680 if self:
681 self_get = self.get
683 self[elem] = count + self_get(elem, 0)
688 _count_elements(self, iterable)
690 self.update(kwds)
692 def subtract(self, iterable=None, /, **kwds):
709 self_get = self.get
712 self[elem] = self_get(elem, 0) - count
715 self[elem] = self_get(elem, 0) - 1
717 self.subtract(kwds)
719 def copy(self):
721 return self.__class__(self)
723 def __reduce__(self):
724 return self.__class__, (dict(self),)
726 def __delitem__(self, elem):
728 if elem in self:
731 def __repr__(self):
732 if not self:
733 return f'{self.__class__.__name__}()'
736 d = dict(self.most_common())
739 d = dict(self)
740 return f'{self.__class__.__name__}({d!r})'
776 def __eq__(self, other):
780 return all(self[e] == other[e] for c in (self, other) for e in c)
782 def __ne__(self, other):
786 return not self == other
788 def __le__(self, other):
789 'True if all counts in self are a subset of those in other.'
792 return all(self[e] <= other[e] for c in (self, other) for e in c)
794 def __lt__(self, other):
795 'True if all counts in self are a proper subset of those in other.'
798 return self <= other and self != other
800 def __ge__(self, other):
801 'True if all counts in self are a superset of those in other.'
804 return all(self[e] >= other[e] for c in (self, other) for e in c)
806 def __gt__(self, other):
807 'True if all counts in self are a proper superset of those in other.'
810 return self >= other and self != other
812 def __add__(self, other):
822 for elem, count in self.items():
827 if elem not in self and count > 0:
831 def __sub__(self, other):
841 for elem, count in self.items():
846 if elem not in self and count < 0:
850 def __or__(self, other):
860 for elem, count in self.items():
866 if elem not in self and count > 0:
870 def __and__(self, other):
880 for elem, count in self.items():
887 def __pos__(self):
890 for elem, count in self.items():
895 def __neg__(self):
901 for elem, count in self.items():
906 def _keep_positive(self):
908 nonpositive = [elem for elem, count in self.items() if not count > 0]
910 del self[elem]
911 return self
913 def __iadd__(self, other):
923 self[elem] += count
924 return self._keep_positive()
926 def __isub__(self, other):
936 self[elem] -= count
937 return self._keep_positive()
939 def __ior__(self, other):
949 count = self[elem]
951 self[elem] = other_count
952 return self._keep_positive()
954 def __iand__(self, other):
963 for elem, count in self.items():
966 self[elem] = other_count
967 return self._keep_positive()
988 def __init__(self, *maps):
993 self.maps = list(maps) or [{}] # always at least one map
995 def __missing__(self, key):
998 def __getitem__(self, key):
999 for mapping in self.maps:
1004 return self.__missing__(key) # support subclasses that define __missing__
1006 def get(self, key, default=None):
1007 return self[key] if key in self else default
1009 def __len__(self):
1010 return len(set().union(*self.maps)) # reuses stored hash values if possible
1012 def __iter__(self):
1014 for mapping in reversed(self.maps):
1018 def __contains__(self, key):
1019 return any(key in m for m in self.maps)
1021 def __bool__(self):
1022 return any(self.maps)
1025 def __repr__(self):
1026 return f'{self.__class__.__name__}({", ".join(map(repr, self.maps))})'
1033 def copy(self):
1035 return self.__class__(self.maps[0].copy(), *self.maps[1:])
1039 def new_child(self, m=None, **kwargs): # like Django's Context.push()
1048 return self.__class__(m, *self.maps)
1051 def parents(self): # like Django's Context.pop()
1053 return self.__class__(*self.maps[1:])
1055 def __setitem__(self, key, value):
1056 self.maps[0][key] = value
1058 def __delitem__(self, key):
1060 del self.maps[0][key]
1064 def popitem(self):
1067 return self.maps[0].popitem()
1071 def pop(self, key, *args):
1074 return self.maps[0].pop(key, *args)
1078 def clear(self):
1080 self.maps[0].clear()
1082 def __ior__(self, other):
1083 self.maps[0].update(other)
1084 return self
1086 def __or__(self, other):
1089 m = self.copy()
1093 def __ror__(self, other):
1097 for child in reversed(self.maps):
1099 return self.__class__(m)
1109 def __init__(self, dict=None, /, **kwargs):
1110 self.data = {}
1112 self.update(dict)
1114 self.update(kwargs)
1116 def __len__(self):
1117 return len(self.data)
1119 def __getitem__(self, key):
1120 if key in self.data:
1121 return self.data[key]
1122 if hasattr(self.__class__, "__missing__"):
1123 return self.__class__.__missing__(self, key)
1126 def __setitem__(self, key, item):
1127 self.data[key] = item
1129 def __delitem__(self, key):
1130 del self.data[key]
1132 def __iter__(self):
1133 return iter(self.data)
1136 def __contains__(self, key):
1137 return key in self.data
1140 def __repr__(self):
1141 return repr(self.data)
1143 def __or__(self, other):
1145 return self.__class__(self.data | other.data)
1147 return self.__class__(self.data | other)
1150 def __ror__(self, other):
1152 return self.__class__(other.data | self.data)
1154 return self.__class__(other | self.data)
1157 def __ior__(self, other):
1159 self.data |= other.data
1161 self.data |= other
1162 return self
1164 def __copy__(self):
1165 inst = self.__class__.__new__(self.__class__)
1166 inst.__dict__.update(self.__dict__)
1168 inst.__dict__["data"] = self.__dict__["data"].copy()
1171 def copy(self):
1172 if self.__class__ is UserDict:
1173 return UserDict(self.data.copy())
1175 data = self.data
1177 self.data = {}
1178 c = copy.copy(self)
1180 self.data = data
1181 c.update(self)
1199 def __init__(self, initlist=None):
1200 self.data = []
1203 if type(initlist) == type(self.data):
1204 self.data[:] = initlist
1206 self.data[:] = initlist.data[:]
1208 self.data = list(initlist)
1210 def __repr__(self):
1211 return repr(self.data)
1213 def __lt__(self, other):
1214 return self.data < self.__cast(other)
1216 def __le__(self, other):
1217 return self.data <= self.__cast(other)
1219 def __eq__(self, other):
1220 return self.data == self.__cast(other)
1222 def __gt__(self, other):
1223 return self.data > self.__cast(other)
1225 def __ge__(self, other):
1226 return self.data >= self.__cast(other)
1228 def __cast(self, other):
1231 def __contains__(self, item):
1232 return item in self.data
1234 def __len__(self):
1235 return len(self.data)
1237 def __getitem__(self, i):
1239 return self.__class__(self.data[i])
1241 return self.data[i]
1243 def __setitem__(self, i, item):
1244 self.data[i] = item
1246 def __delitem__(self, i):
1247 del self.data[i]
1249 def __add__(self, other):
1251 return self.__class__(self.data + other.data)
1252 elif isinstance(other, type(self.data)):
1253 return self.__class__(self.data + other)
1254 return self.__class__(self.data + list(other))
1256 def __radd__(self, other):
1258 return self.__class__(other.data + self.data)
1259 elif isinstance(other, type(self.data)):
1260 return self.__class__(other + self.data)
1261 return self.__class__(list(other) + self.data)
1263 def __iadd__(self, other):
1265 self.data += other.data
1266 elif isinstance(other, type(self.data)):
1267 self.data += other
1269 self.data += list(other)
1270 return self
1272 def __mul__(self, n):
1273 return self.__class__(self.data * n)
1277 def __imul__(self, n):
1278 self.data *= n
1279 return self
1281 def __copy__(self):
1282 inst = self.__class__.__new__(self.__class__)
1283 inst.__dict__.update(self.__dict__)
1285 inst.__dict__["data"] = self.__dict__["data"][:]
1288 def append(self, item):
1289 self.data.append(item)
1291 def insert(self, i, item):
1292 self.data.insert(i, item)
1294 def pop(self, i=-1):
1295 return self.data.pop(i)
1297 def remove(self, item):
1298 self.data.remove(item)
1300 def clear(self):
1301 self.data.clear()
1303 def copy(self):
1304 return self.__class__(self)
1306 def count(self, item):
1307 return self.data.count(item)
1309 def index(self, item, *args):
1310 return self.data.index(item, *args)
1312 def reverse(self):
1313 self.data.reverse()
1315 def sort(self, /, *args, **kwds):
1316 self.data.sort(*args, **kwds)
1318 def extend(self, other):
1320 self.data.extend(other.data)
1322 self.data.extend(other)
1331 def __init__(self, seq):
1333 self.data = seq
1335 self.data = seq.data[:]
1337 self.data = str(seq)
1339 def __str__(self):
1340 return str(self.data)
1342 def __repr__(self):
1343 return repr(self.data)
1345 def __int__(self):
1346 return int(self.data)
1348 def __float__(self):
1349 return float(self.data)
1351 def __complex__(self):
1352 return complex(self.data)
1354 def __hash__(self):
1355 return hash(self.data)
1357 def __getnewargs__(self):
1358 return (self.data[:],)
1360 def __eq__(self, string):
1362 return self.data == string.data
1363 return self.data == string
1365 def __lt__(self, string):
1367 return self.data < string.data
1368 return self.data < string
1370 def __le__(self, string):
1372 return self.data <= string.data
1373 return self.data <= string
1375 def __gt__(self, string):
1377 return self.data > string.data
1378 return self.data > string
1380 def __ge__(self, string):
1382 return self.data >= string.data
1383 return self.data >= string
1385 def __contains__(self, char):
1388 return char in self.data
1390 def __len__(self):
1391 return len(self.data)
1393 def __getitem__(self, index):
1394 return self.__class__(self.data[index])
1396 def __add__(self, other):
1398 return self.__class__(self.data + other.data)
1400 return self.__class__(self.data + other)
1401 return self.__class__(self.data + str(other))
1403 def __radd__(self, other):
1405 return self.__class__(other + self.data)
1406 return self.__class__(str(other) + self.data)
1408 def __mul__(self, n):
1409 return self.__class__(self.data * n)
1413 def __mod__(self, args):
1414 return self.__class__(self.data % args)
1416 def __rmod__(self, template):
1417 return self.__class__(str(template) % self)
1420 def capitalize(self):
1421 return self.__class__(self.data.capitalize())
1423 def casefold(self):
1424 return self.__class__(self.data.casefold())
1426 def center(self, width, *args):
1427 return self.__class__(self.data.center(width, *args))
1429 def count(self, sub, start=0, end=_sys.maxsize):
1432 return self.data.count(sub, start, end)
1434 def removeprefix(self, prefix, /):
1437 return self.__class__(self.data.removeprefix(prefix))
1439 def removesuffix(self, suffix, /):
1442 return self.__class__(self.data.removesuffix(suffix))
1444 def encode(self, encoding='utf-8', errors='strict'):
1447 return self.data.encode(encoding, errors)
1449 def endswith(self, suffix, start=0, end=_sys.maxsize):
1450 return self.data.endswith(suffix, start, end)
1452 def expandtabs(self, tabsize=8):
1453 return self.__class__(self.data.expandtabs(tabsize))
1455 def find(self, sub, start=0, end=_sys.maxsize):
1458 return self.data.find(sub, start, end)
1460 def format(self, /, *args, **kwds):
1461 return self.data.format(*args, **kwds)
1463 def format_map(self, mapping):
1464 return self.data.format_map(mapping)
1466 def index(self, sub, start=0, end=_sys.maxsize):
1467 return self.data.index(sub, start, end)
1469 def isalpha(self):
1470 return self.data.isalpha()
1472 def isalnum(self):
1473 return self.data.isalnum()
1475 def isascii(self):
1476 return self.data.isascii()
1478 def isdecimal(self):
1479 return self.data.isdecimal()
1481 def isdigit(self):
1482 return self.data.isdigit()
1484 def isidentifier(self):
1485 return self.data.isidentifier()
1487 def islower(self):
1488 return self.data.islower()
1490 def isnumeric(self):
1491 return self.data.isnumeric()
1493 def isprintable(self):
1494 return self.data.isprintable()
1496 def isspace(self):
1497 return self.data.isspace()
1499 def istitle(self):
1500 return self.data.istitle()
1502 def isupper(self):
1503 return self.data.isupper()
1505 def join(self, seq):
1506 return self.data.join(seq)
1508 def ljust(self, width, *args):
1509 return self.__class__(self.data.ljust(width, *args))
1511 def lower(self):
1512 return self.__class__(self.data.lower())
1514 def lstrip(self, chars=None):
1515 return self.__class__(self.data.lstrip(chars))
1519 def partition(self, sep):
1520 return self.data.partition(sep)
1522 def replace(self, old, new, maxsplit=-1):
1527 return self.__class__(self.data.replace(old, new, maxsplit))
1529 def rfind(self, sub, start=0, end=_sys.maxsize):
1532 return self.data.rfind(sub, start, end)
1534 def rindex(self, sub, start=0, end=_sys.maxsize):
1535 return self.data.rindex(sub, start, end)
1537 def rjust(self, width, *args):
1538 return self.__class__(self.data.rjust(width, *args))
1540 def rpartition(self, sep):
1541 return self.data.rpartition(sep)
1543 def rstrip(self, chars=None):
1544 return self.__class__(self.data.rstrip(chars))
1546 def split(self, sep=None, maxsplit=-1):
1547 return self.data.split(sep, maxsplit)
1549 def rsplit(self, sep=None, maxsplit=-1):
1550 return self.data.rsplit(sep, maxsplit)
1552 def splitlines(self, keepends=False):
1553 return self.data.splitlines(keepends)
1555 def startswith(self, prefix, start=0, end=_sys.maxsize):
1556 return self.data.startswith(prefix, start, end)
1558 def strip(self, chars=None):
1559 return self.__class__(self.data.strip(chars))
1561 def swapcase(self):
1562 return self.__class__(self.data.swapcase())
1564 def title(self):
1565 return self.__class__(self.data.title())
1567 def translate(self, *args):
1568 return self.__class__(self.data.translate(*args))
1570 def upper(self):
1571 return self.__class__(self.data.upper())
1573 def zfill(self, width):
1574 return self.__class__(self.data.zfill(width))