Linux ip-148-66-134-25.ip.secureserver.net 3.10.0-1160.119.1.el7.tuxcare.els10.x86_64 #1 SMP Fri Oct 11 21:40:41 UTC 2024 x86_64
Apache
: 148.66.134.25 | : 18.191.200.223
66 Domain
8.0.30
amvm
www.github.com/MadExploits
Terminal
AUTO ROOT
Adminer
Backdoor Destroyer
Linux Exploit
Lock Shell
Lock File
Create User
CREATE RDP
PHP Mailer
BACKCONNECT
UNLOCK SHELL
HASH IDENTIFIER
CPANEL RESET
BLACK DEFEND!
README
+ Create Folder
+ Create File
/
opt /
python35 /
lib /
python3.5 /
[ HOME SHELL ]
Name
Size
Permission
Action
__pycache__
[ DIR ]
drwxr-xr-x
asyncio
[ DIR ]
drwxr-xr-x
collections
[ DIR ]
drwxr-xr-x
concurrent
[ DIR ]
drwxr-xr-x
config-3.5m
[ DIR ]
drwxr-xr-x
ctypes
[ DIR ]
drwxr-xr-x
curses
[ DIR ]
drwxr-xr-x
dbm
[ DIR ]
drwxr-xr-x
distutils
[ DIR ]
drwxr-xr-x
email
[ DIR ]
drwxr-xr-x
encodings
[ DIR ]
drwxr-xr-x
ensurepip
[ DIR ]
drwxr-xr-x
html
[ DIR ]
drwxr-xr-x
http
[ DIR ]
drwxr-xr-x
idlelib
[ DIR ]
drwxr-xr-x
importlib
[ DIR ]
drwxr-xr-x
json
[ DIR ]
drwxr-xr-x
lib-dynload
[ DIR ]
drwxr-xr-x
lib2to3
[ DIR ]
drwxr-xr-x
logging
[ DIR ]
drwxr-xr-x
multiprocessing
[ DIR ]
drwxr-xr-x
plat-linux
[ DIR ]
drwxr-xr-x
pydoc_data
[ DIR ]
drwxr-xr-x
site-packages
[ DIR ]
drwxr-xr-x
sqlite3
[ DIR ]
drwxr-xr-x
tkinter
[ DIR ]
drwxr-xr-x
turtledemo
[ DIR ]
drwxr-xr-x
unittest
[ DIR ]
drwxr-xr-x
urllib
[ DIR ]
drwxr-xr-x
venv
[ DIR ]
drwxr-xr-x
wsgiref
[ DIR ]
drwxr-xr-x
xml
[ DIR ]
drwxr-xr-x
xmlrpc
[ DIR ]
drwxr-xr-x
LICENSE.txt
12.46
KB
-rw-r--r--
__future__.py
4.73
KB
-rw-r--r--
__phello__.foo.py
64
B
-rw-r--r--
_bootlocale.py
1.27
KB
-rw-r--r--
_collections_abc.py
24.21
KB
-rw-r--r--
_compat_pickle.py
8.36
KB
-rw-r--r--
_compression.py
5.21
KB
-rw-r--r--
_dummy_thread.py
5
KB
-rw-r--r--
_markupbase.py
14.26
KB
-rw-r--r--
_osx_support.py
18.67
KB
-rw-r--r--
_pydecimal.py
223.27
KB
-rw-r--r--
_pyio.py
85.91
KB
-rw-r--r--
_sitebuiltins.py
3.04
KB
-rw-r--r--
_strptime.py
21.67
KB
-rw-r--r--
_sysconfigdata.py
18.33
KB
-rw-r--r--
_threading_local.py
7.24
KB
-rw-r--r--
_weakrefset.py
5.57
KB
-rw-r--r--
abc.py
8.43
KB
-rw-r--r--
aifc.py
31.22
KB
-rw-r--r--
antigravity.py
476
B
-rw-r--r--
argparse.py
88.03
KB
-rw-r--r--
ast.py
11.72
KB
-rw-r--r--
asynchat.py
11.69
KB
-rw-r--r--
asyncore.py
19.63
KB
-rw-r--r--
base64.py
20.03
KB
-rwxr-xr-x
bdb.py
22.81
KB
-rw-r--r--
binhex.py
13.63
KB
-rw-r--r--
bisect.py
2.53
KB
-rw-r--r--
bz2.py
12.13
KB
-rw-r--r--
cProfile.py
5.19
KB
-rwxr-xr-x
calendar.py
22.46
KB
-rw-r--r--
cgi.py
35.2
KB
-rwxr-xr-x
cgitb.py
11.74
KB
-rw-r--r--
chunk.py
5.3
KB
-rw-r--r--
cmd.py
14.51
KB
-rw-r--r--
code.py
9.88
KB
-rw-r--r--
codecs.py
35.38
KB
-rw-r--r--
codeop.py
5.85
KB
-rw-r--r--
colorsys.py
3.97
KB
-rw-r--r--
compileall.py
11.44
KB
-rw-r--r--
configparser.py
52.2
KB
-rw-r--r--
contextlib.py
12.16
KB
-rw-r--r--
copy.py
8.74
KB
-rw-r--r--
copyreg.py
6.67
KB
-rw-r--r--
crypt.py
1.83
KB
-rw-r--r--
csv.py
15.75
KB
-rw-r--r--
datetime.py
74.12
KB
-rw-r--r--
decimal.py
320
B
-rw-r--r--
difflib.py
82.23
KB
-rw-r--r--
dis.py
16.94
KB
-rw-r--r--
doctest.py
101.6
KB
-rw-r--r--
dummy_threading.py
2.75
KB
-rw-r--r--
enum.py
21.71
KB
-rw-r--r--
filecmp.py
9.6
KB
-rw-r--r--
fileinput.py
13.92
KB
-rw-r--r--
fnmatch.py
3.09
KB
-rw-r--r--
formatter.py
14.79
KB
-rw-r--r--
fractions.py
24.04
KB
-rw-r--r--
ftplib.py
34.13
KB
-rw-r--r--
functools.py
28.27
KB
-rw-r--r--
genericpath.py
4.26
KB
-rw-r--r--
getopt.py
7.31
KB
-rw-r--r--
getpass.py
5.85
KB
-rw-r--r--
gettext.py
21.03
KB
-rw-r--r--
glob.py
4.95
KB
-rw-r--r--
gzip.py
19.79
KB
-rw-r--r--
hashlib.py
7.79
KB
-rw-r--r--
heapq.py
22.39
KB
-rw-r--r--
hmac.py
4.94
KB
-rw-r--r--
imaplib.py
50.96
KB
-rw-r--r--
imghdr.py
3.67
KB
-rw-r--r--
imp.py
10.43
KB
-rw-r--r--
inspect.py
111.52
KB
-rw-r--r--
io.py
3.32
KB
-rw-r--r--
ipaddress.py
73.96
KB
-rw-r--r--
keyword.py
2.16
KB
-rwxr-xr-x
linecache.py
5.19
KB
-rw-r--r--
locale.py
72.96
KB
-rw-r--r--
lzma.py
12.62
KB
-rw-r--r--
macpath.py
5.77
KB
-rw-r--r--
macurl2path.py
2.67
KB
-rw-r--r--
mailbox.py
76.58
KB
-rw-r--r--
mailcap.py
7.91
KB
-rw-r--r--
mimetypes.py
20.36
KB
-rw-r--r--
modulefinder.py
22.54
KB
-rw-r--r--
netrc.py
5.61
KB
-rw-r--r--
nntplib.py
42.07
KB
-rw-r--r--
ntpath.py
22.26
KB
-rw-r--r--
nturl2path.py
2.39
KB
-rw-r--r--
numbers.py
10
KB
-rw-r--r--
opcode.py
5.75
KB
-rw-r--r--
operator.py
10.61
KB
-rw-r--r--
optparse.py
58.93
KB
-rw-r--r--
os.py
36.17
KB
-rw-r--r--
pathlib.py
45.9
KB
-rw-r--r--
pdb.py
59.71
KB
-rwxr-xr-x
pickle.py
54.86
KB
-rw-r--r--
pickletools.py
89.61
KB
-rw-r--r--
pipes.py
8.71
KB
-rw-r--r--
pkgutil.py
20.85
KB
-rw-r--r--
platform.py
45.05
KB
-rwxr-xr-x
plistlib.py
30.73
KB
-rw-r--r--
poplib.py
14.37
KB
-rw-r--r--
posixpath.py
14.56
KB
-rw-r--r--
pprint.py
20.37
KB
-rw-r--r--
profile.py
21.5
KB
-rwxr-xr-x
pstats.py
25.94
KB
-rw-r--r--
pty.py
4.65
KB
-rw-r--r--
py_compile.py
7.01
KB
-rw-r--r--
pyclbr.py
13.25
KB
-rw-r--r--
pydoc.py
101.21
KB
-rwxr-xr-x
queue.py
8.57
KB
-rw-r--r--
quopri.py
7.08
KB
-rwxr-xr-x
random.py
25.84
KB
-rw-r--r--
re.py
15.14
KB
-rw-r--r--
reprlib.py
5.21
KB
-rw-r--r--
rlcompleter.py
6.16
KB
-rw-r--r--
runpy.py
11.68
KB
-rw-r--r--
sched.py
6.07
KB
-rw-r--r--
selectors.py
18.98
KB
-rw-r--r--
shelve.py
8.33
KB
-rw-r--r--
shlex.py
11.18
KB
-rw-r--r--
shutil.py
39.11
KB
-rw-r--r--
signal.py
2.07
KB
-rw-r--r--
site.py
20.74
KB
-rw-r--r--
smtpd.py
34.53
KB
-rwxr-xr-x
smtplib.py
42.6
KB
-rwxr-xr-x
sndhdr.py
6.27
KB
-rw-r--r--
socket.py
26.5
KB
-rw-r--r--
socketserver.py
24.09
KB
-rw-r--r--
sre_compile.py
17.98
KB
-rw-r--r--
sre_constants.py
6.66
KB
-rw-r--r--
sre_parse.py
34.29
KB
-rw-r--r--
ssl.py
41.36
KB
-rw-r--r--
stat.py
4.92
KB
-rw-r--r--
statistics.py
19.08
KB
-rw-r--r--
string.py
11.58
KB
-rw-r--r--
stringprep.py
12.61
KB
-rw-r--r--
struct.py
257
B
-rw-r--r--
subprocess.py
57.53
KB
-rw-r--r--
sunau.py
17.67
KB
-rw-r--r--
symbol.py
2.05
KB
-rwxr-xr-x
symtable.py
7.02
KB
-rw-r--r--
sysconfig.py
23.77
KB
-rw-r--r--
tabnanny.py
11.14
KB
-rwxr-xr-x
tarfile.py
90.88
KB
-rwxr-xr-x
telnetlib.py
22.48
KB
-rw-r--r--
tempfile.py
26.01
KB
-rw-r--r--
textwrap.py
19.1
KB
-rw-r--r--
this.py
1003
B
-rw-r--r--
threading.py
47.88
KB
-rw-r--r--
timeit.py
12.1
KB
-rwxr-xr-x
token.py
3
KB
-rw-r--r--
tokenize.py
27.14
KB
-rw-r--r--
trace.py
30.8
KB
-rwxr-xr-x
traceback.py
21.66
KB
-rw-r--r--
tracemalloc.py
15.27
KB
-rw-r--r--
tty.py
879
B
-rw-r--r--
turtle.py
140.25
KB
-rw-r--r--
types.py
8.59
KB
-rw-r--r--
typing.py
78.26
KB
-rw-r--r--
uu.py
6.6
KB
-rwxr-xr-x
uuid.py
22.72
KB
-rw-r--r--
warnings.py
15.48
KB
-rw-r--r--
wave.py
17.27
KB
-rw-r--r--
weakref.py
19.99
KB
-rw-r--r--
webbrowser.py
21.31
KB
-rwxr-xr-x
xdrlib.py
5.77
KB
-rw-r--r--
zipapp.py
6.99
KB
-rw-r--r--
zipfile.py
71.95
KB
-rw-r--r--
Delete
Unzip
Zip
${this.title}
Close
Code Editor : _collections_abc.py
# Copyright 2007 Google, Inc. All Rights Reserved. # Licensed to PSF under a Contributor Agreement. """Abstract Base Classes (ABCs) for collections, according to PEP 3119. Unit tests are in test_collections. """ from abc import ABCMeta, abstractmethod import sys __all__ = ["Awaitable", "Coroutine", "AsyncIterable", "AsyncIterator", "Hashable", "Iterable", "Iterator", "Generator", "Sized", "Container", "Callable", "Set", "MutableSet", "Mapping", "MutableMapping", "MappingView", "KeysView", "ItemsView", "ValuesView", "Sequence", "MutableSequence", "ByteString", ] # This module has been renamed from collections.abc to _collections_abc to # speed up interpreter startup. Some of the types such as MutableMapping are # required early but collections module imports a lot of other modules. # See issue #19218 __name__ = "collections.abc" # Private list of types that we want to register with the various ABCs # so that they will pass tests like: # it = iter(somebytearray) # assert isinstance(it, Iterable) # Note: in other implementations, these types might not be distinct # and they may have their own implementation specific types that # are not included on this list. bytes_iterator = type(iter(b'')) bytearray_iterator = type(iter(bytearray())) #callable_iterator = ??? dict_keyiterator = type(iter({}.keys())) dict_valueiterator = type(iter({}.values())) dict_itemiterator = type(iter({}.items())) list_iterator = type(iter([])) list_reverseiterator = type(iter(reversed([]))) range_iterator = type(iter(range(0))) longrange_iterator = type(iter(range(1 << 1000))) set_iterator = type(iter(set())) str_iterator = type(iter("")) tuple_iterator = type(iter(())) zip_iterator = type(iter(zip())) ## views ## dict_keys = type({}.keys()) dict_values = type({}.values()) dict_items = type({}.items()) ## misc ## mappingproxy = type(type.__dict__) generator = type((lambda: (yield))()) ## coroutine ## async def _coro(): pass _coro = _coro() coroutine = type(_coro) _coro.close() # Prevent ResourceWarning del _coro ### ONE-TRICK PONIES ### class Hashable(metaclass=ABCMeta): __slots__ = () @abstractmethod def __hash__(self): return 0 @classmethod def __subclasshook__(cls, C): if cls is Hashable: for B in C.__mro__: if "__hash__" in B.__dict__: if B.__dict__["__hash__"]: return True break return NotImplemented class Awaitable(metaclass=ABCMeta): __slots__ = () @abstractmethod def __await__(self): yield @classmethod def __subclasshook__(cls, C): if cls is Awaitable: for B in C.__mro__: if "__await__" in B.__dict__: if B.__dict__["__await__"]: return True break return NotImplemented class Coroutine(Awaitable): __slots__ = () @abstractmethod def send(self, value): """Send a value into the coroutine. Return next yielded value or raise StopIteration. """ raise StopIteration @abstractmethod def throw(self, typ, val=None, tb=None): """Raise an exception in the coroutine. Return next yielded value or raise StopIteration. """ if val is None: if tb is None: raise typ val = typ() if tb is not None: val = val.with_traceback(tb) raise val def close(self): """Raise GeneratorExit inside coroutine. """ try: self.throw(GeneratorExit) except (GeneratorExit, StopIteration): pass else: raise RuntimeError("coroutine ignored GeneratorExit") @classmethod def __subclasshook__(cls, C): if cls is Coroutine: mro = C.__mro__ for method in ('__await__', 'send', 'throw', 'close'): for base in mro: if method in base.__dict__: break else: return NotImplemented return True return NotImplemented Coroutine.register(coroutine) class AsyncIterable(metaclass=ABCMeta): __slots__ = () @abstractmethod def __aiter__(self): return AsyncIterator() @classmethod def __subclasshook__(cls, C): if cls is AsyncIterable: if any("__aiter__" in B.__dict__ for B in C.__mro__): return True return NotImplemented class AsyncIterator(AsyncIterable): __slots__ = () @abstractmethod async def __anext__(self): """Return the next item or raise StopAsyncIteration when exhausted.""" raise StopAsyncIteration def __aiter__(self): return self @classmethod def __subclasshook__(cls, C): if cls is AsyncIterator: if (any("__anext__" in B.__dict__ for B in C.__mro__) and any("__aiter__" in B.__dict__ for B in C.__mro__)): return True return NotImplemented class Iterable(metaclass=ABCMeta): __slots__ = () @abstractmethod def __iter__(self): while False: yield None @classmethod def __subclasshook__(cls, C): if cls is Iterable: if any("__iter__" in B.__dict__ for B in C.__mro__): return True return NotImplemented class Iterator(Iterable): __slots__ = () @abstractmethod def __next__(self): 'Return the next item from the iterator. When exhausted, raise StopIteration' raise StopIteration def __iter__(self): return self @classmethod def __subclasshook__(cls, C): if cls is Iterator: if (any("__next__" in B.__dict__ for B in C.__mro__) and any("__iter__" in B.__dict__ for B in C.__mro__)): return True return NotImplemented Iterator.register(bytes_iterator) Iterator.register(bytearray_iterator) #Iterator.register(callable_iterator) Iterator.register(dict_keyiterator) Iterator.register(dict_valueiterator) Iterator.register(dict_itemiterator) Iterator.register(list_iterator) Iterator.register(list_reverseiterator) Iterator.register(range_iterator) Iterator.register(longrange_iterator) Iterator.register(set_iterator) Iterator.register(str_iterator) Iterator.register(tuple_iterator) Iterator.register(zip_iterator) class Generator(Iterator): __slots__ = () def __next__(self): """Return the next item from the generator. When exhausted, raise StopIteration. """ return self.send(None) @abstractmethod def send(self, value): """Send a value into the generator. Return next yielded value or raise StopIteration. """ raise StopIteration @abstractmethod def throw(self, typ, val=None, tb=None): """Raise an exception in the generator. Return next yielded value or raise StopIteration. """ if val is None: if tb is None: raise typ val = typ() if tb is not None: val = val.with_traceback(tb) raise val def close(self): """Raise GeneratorExit inside generator. """ try: self.throw(GeneratorExit) except (GeneratorExit, StopIteration): pass else: raise RuntimeError("generator ignored GeneratorExit") @classmethod def __subclasshook__(cls, C): if cls is Generator: mro = C.__mro__ for method in ('__iter__', '__next__', 'send', 'throw', 'close'): for base in mro: if method in base.__dict__: break else: return NotImplemented return True return NotImplemented Generator.register(generator) class Sized(metaclass=ABCMeta): __slots__ = () @abstractmethod def __len__(self): return 0 @classmethod def __subclasshook__(cls, C): if cls is Sized: if any("__len__" in B.__dict__ for B in C.__mro__): return True return NotImplemented class Container(metaclass=ABCMeta): __slots__ = () @abstractmethod def __contains__(self, x): return False @classmethod def __subclasshook__(cls, C): if cls is Container: if any("__contains__" in B.__dict__ for B in C.__mro__): return True return NotImplemented class Callable(metaclass=ABCMeta): __slots__ = () @abstractmethod def __call__(self, *args, **kwds): return False @classmethod def __subclasshook__(cls, C): if cls is Callable: if any("__call__" in B.__dict__ for B in C.__mro__): return True return NotImplemented ### SETS ### class Set(Sized, Iterable, Container): """A set is a finite, iterable container. This class provides concrete generic implementations of all methods except for __contains__, __iter__ and __len__. To override the comparisons (presumably for speed, as the semantics are fixed), redefine __le__ and __ge__, then the other operations will automatically follow suit. """ __slots__ = () def __le__(self, other): if not isinstance(other, Set): return NotImplemented if len(self) > len(other): return False for elem in self: if elem not in other: return False return True def __lt__(self, other): if not isinstance(other, Set): return NotImplemented return len(self) < len(other) and self.__le__(other) def __gt__(self, other): if not isinstance(other, Set): return NotImplemented return len(self) > len(other) and self.__ge__(other) def __ge__(self, other): if not isinstance(other, Set): return NotImplemented if len(self) < len(other): return False for elem in other: if elem not in self: return False return True def __eq__(self, other): if not isinstance(other, Set): return NotImplemented return len(self) == len(other) and self.__le__(other) @classmethod def _from_iterable(cls, it): '''Construct an instance of the class from any iterable input. Must override this method if the class constructor signature does not accept an iterable for an input. ''' return cls(it) def __and__(self, other): if not isinstance(other, Iterable): return NotImplemented return self._from_iterable(value for value in other if value in self) __rand__ = __and__ def isdisjoint(self, other): 'Return True if two sets have a null intersection.' for value in other: if value in self: return False return True def __or__(self, other): if not isinstance(other, Iterable): return NotImplemented chain = (e for s in (self, other) for e in s) return self._from_iterable(chain) __ror__ = __or__ def __sub__(self, other): if not isinstance(other, Set): if not isinstance(other, Iterable): return NotImplemented other = self._from_iterable(other) return self._from_iterable(value for value in self if value not in other) def __rsub__(self, other): if not isinstance(other, Set): if not isinstance(other, Iterable): return NotImplemented other = self._from_iterable(other) return self._from_iterable(value for value in other if value not in self) def __xor__(self, other): if not isinstance(other, Set): if not isinstance(other, Iterable): return NotImplemented other = self._from_iterable(other) return (self - other) | (other - self) __rxor__ = __xor__ def _hash(self): """Compute the hash value of a set. Note that we don't define __hash__: not all sets are hashable. But if you define a hashable set type, its __hash__ should call this function. This must be compatible __eq__. All sets ought to compare equal if they contain the same elements, regardless of how they are implemented, and regardless of the order of the elements; so there's not much freedom for __eq__ or __hash__. We match the algorithm used by the built-in frozenset type. """ MAX = sys.maxsize MASK = 2 * MAX + 1 n = len(self) h = 1927868237 * (n + 1) h &= MASK for x in self: hx = hash(x) h ^= (hx ^ (hx << 16) ^ 89869747) * 3644798167 h &= MASK h = h * 69069 + 907133923 h &= MASK if h > MAX: h -= MASK + 1 if h == -1: h = 590923713 return h Set.register(frozenset) class MutableSet(Set): """A mutable set is a finite, iterable container. This class provides concrete generic implementations of all methods except for __contains__, __iter__, __len__, add(), and discard(). To override the comparisons (presumably for speed, as the semantics are fixed), all you have to do is redefine __le__ and then the other operations will automatically follow suit. """ __slots__ = () @abstractmethod def add(self, value): """Add an element.""" raise NotImplementedError @abstractmethod def discard(self, value): """Remove an element. Do not raise an exception if absent.""" raise NotImplementedError def remove(self, value): """Remove an element. If not a member, raise a KeyError.""" if value not in self: raise KeyError(value) self.discard(value) def pop(self): """Return the popped value. Raise KeyError if empty.""" it = iter(self) try: value = next(it) except StopIteration: raise KeyError self.discard(value) return value def clear(self): """This is slow (creates N new iterators!) but effective.""" try: while True: self.pop() except KeyError: pass def __ior__(self, it): for value in it: self.add(value) return self def __iand__(self, it): for value in (self - it): self.discard(value) return self def __ixor__(self, it): if it is self: self.clear() else: if not isinstance(it, Set): it = self._from_iterable(it) for value in it: if value in self: self.discard(value) else: self.add(value) return self def __isub__(self, it): if it is self: self.clear() else: for value in it: self.discard(value) return self MutableSet.register(set) ### MAPPINGS ### class Mapping(Sized, Iterable, Container): __slots__ = () """A Mapping is a generic container for associating key/value pairs. This class provides concrete generic implementations of all methods except for __getitem__, __iter__, and __len__. """ @abstractmethod def __getitem__(self, key): raise KeyError def get(self, key, default=None): 'D.get(k[,d]) -> D[k] if k in D, else d. d defaults to None.' try: return self[key] except KeyError: return default def __contains__(self, key): try: self[key] except KeyError: return False else: return True def keys(self): "D.keys() -> a set-like object providing a view on D's keys" return KeysView(self) def items(self): "D.items() -> a set-like object providing a view on D's items" return ItemsView(self) def values(self): "D.values() -> an object providing a view on D's values" return ValuesView(self) def __eq__(self, other): if not isinstance(other, Mapping): return NotImplemented return dict(self.items()) == dict(other.items()) Mapping.register(mappingproxy) class MappingView(Sized): __slots__ = '_mapping', def __init__(self, mapping): self._mapping = mapping def __len__(self): return len(self._mapping) def __repr__(self): return '{0.__class__.__name__}({0._mapping!r})'.format(self) class KeysView(MappingView, Set): __slots__ = () @classmethod def _from_iterable(self, it): return set(it) def __contains__(self, key): return key in self._mapping def __iter__(self): yield from self._mapping KeysView.register(dict_keys) class ItemsView(MappingView, Set): __slots__ = () @classmethod def _from_iterable(self, it): return set(it) def __contains__(self, item): key, value = item try: v = self._mapping[key] except KeyError: return False else: return v == value def __iter__(self): for key in self._mapping: yield (key, self._mapping[key]) ItemsView.register(dict_items) class ValuesView(MappingView): __slots__ = () def __contains__(self, value): for key in self._mapping: if value == self._mapping[key]: return True return False def __iter__(self): for key in self._mapping: yield self._mapping[key] ValuesView.register(dict_values) class MutableMapping(Mapping): __slots__ = () """A MutableMapping is a generic container for associating key/value pairs. This class provides concrete generic implementations of all methods except for __getitem__, __setitem__, __delitem__, __iter__, and __len__. """ @abstractmethod def __setitem__(self, key, value): raise KeyError @abstractmethod def __delitem__(self, key): raise KeyError __marker = object() def pop(self, key, default=__marker): '''D.pop(k[,d]) -> v, remove specified key and return the corresponding value. If key is not found, d is returned if given, otherwise KeyError is raised. ''' try: value = self[key] except KeyError: if default is self.__marker: raise return default else: del self[key] return value def popitem(self): '''D.popitem() -> (k, v), remove and return some (key, value) pair as a 2-tuple; but raise KeyError if D is empty. ''' try: key = next(iter(self)) except StopIteration: raise KeyError value = self[key] del self[key] return key, value def clear(self): 'D.clear() -> None. Remove all items from D.' try: while True: self.popitem() except KeyError: pass def update(*args, **kwds): ''' D.update([E, ]**F) -> None. Update D from mapping/iterable E and F. If E present and has a .keys() method, does: for k in E: D[k] = E[k] If E present and lacks .keys() method, does: for (k, v) in E: D[k] = v In either case, this is followed by: for k, v in F.items(): D[k] = v ''' if not args: raise TypeError("descriptor 'update' of 'MutableMapping' object " "needs an argument") self, *args = args if len(args) > 1: raise TypeError('update expected at most 1 arguments, got %d' % len(args)) if args: other = args[0] if isinstance(other, Mapping): for key in other: self[key] = other[key] elif hasattr(other, "keys"): for key in other.keys(): self[key] = other[key] else: for key, value in other: self[key] = value for key, value in kwds.items(): self[key] = value def setdefault(self, key, default=None): 'D.setdefault(k[,d]) -> D.get(k,d), also set D[k]=d if k not in D' try: return self[key] except KeyError: self[key] = default return default MutableMapping.register(dict) ### SEQUENCES ### class Sequence(Sized, Iterable, Container): """All the operations on a read-only sequence. Concrete subclasses must override __new__ or __init__, __getitem__, and __len__. """ __slots__ = () @abstractmethod def __getitem__(self, index): raise IndexError def __iter__(self): i = 0 try: while True: v = self[i] yield v i += 1 except IndexError: return def __contains__(self, value): for v in self: if v == value: return True return False def __reversed__(self): for i in reversed(range(len(self))): yield self[i] def index(self, value, start=0, stop=None): '''S.index(value, [start, [stop]]) -> integer -- return first index of value. Raises ValueError if the value is not present. ''' if start is not None and start < 0: start = max(len(self) + start, 0) if stop is not None and stop < 0: stop += len(self) i = start while stop is None or i < stop: try: if self[i] == value: return i except IndexError: break i += 1 raise ValueError def count(self, value): 'S.count(value) -> integer -- return number of occurrences of value' return sum(1 for v in self if v == value) Sequence.register(tuple) Sequence.register(str) Sequence.register(range) Sequence.register(memoryview) class ByteString(Sequence): """This unifies bytes and bytearray. XXX Should add all their methods. """ __slots__ = () ByteString.register(bytes) ByteString.register(bytearray) class MutableSequence(Sequence): __slots__ = () """All the operations on a read-write sequence. Concrete subclasses must provide __new__ or __init__, __getitem__, __setitem__, __delitem__, __len__, and insert(). """ @abstractmethod def __setitem__(self, index, value): raise IndexError @abstractmethod def __delitem__(self, index): raise IndexError @abstractmethod def insert(self, index, value): 'S.insert(index, value) -- insert value before index' raise IndexError def append(self, value): 'S.append(value) -- append value to the end of the sequence' self.insert(len(self), value) def clear(self): 'S.clear() -> None -- remove all items from S' try: while True: self.pop() except IndexError: pass def reverse(self): 'S.reverse() -- reverse *IN PLACE*' n = len(self) for i in range(n//2): self[i], self[n-i-1] = self[n-i-1], self[i] def extend(self, values): 'S.extend(iterable) -- extend sequence by appending elements from the iterable' for v in values: self.append(v) def pop(self, index=-1): '''S.pop([index]) -> item -- remove and return item at index (default last). Raise IndexError if list is empty or index is out of range. ''' v = self[index] del self[index] return v def remove(self, value): '''S.remove(value) -- remove first occurrence of value. Raise ValueError if the value is not present. ''' del self[self.index(value)] def __iadd__(self, values): self.extend(values) return self MutableSequence.register(list) MutableSequence.register(bytearray) # Multiply inheriting, see ByteString
Close