-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path__init__.py
More file actions
50 lines (39 loc) · 1.85 KB
/
Copy path__init__.py
File metadata and controls
50 lines (39 loc) · 1.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
from bitarray._bitarray import (bitarray, bits2bytes,
get_default_endian, _set_default_endian)
__version__ = '2.4.1'
__all__ = ['bitarray', 'frozenbitarray', 'bits2bytes']
class frozenbitarray(bitarray):
"""frozenbitarray(initializer=0, /, endian='big', buffer=None) -> \
frozenbitarray
Return a frozenbitarray object, which is initialized the same way a bitarray
object is initialized. A frozenbitarray is immutable and hashable.
Its contents cannot be altered after it is created; however, it can be used
as a dictionary key.
"""
def __repr__(self):
return 'frozen' + bitarray.__repr__(self)
def __hash__(self):
"Return hash(self)."
if getattr(self, '_hash', None) is None:
# ensure hash is independent of endianness, also the copy will be
# mutable such that .tobytes() can zero out the pad bits
a = bitarray(self, 'big')
self._hash = hash((len(a), a.tobytes()))
return self._hash
# Technically the code below is not necessary, as all these methods will
# raise a TypeError on read-only memory. However, with a different error
# message.
def __delitem__(self, *args, **kwargs):
"" # no docstring
raise TypeError("frozenbitarray is immutable")
append = bytereverse = clear = extend = encode = fill = __delitem__
frombytes = fromfile = insert = invert = pack = pop = __delitem__
remove = reverse = setall = sort = __setitem__ = __delitem__
__iadd__ = __iand__ = __imul__ = __ior__ = __ixor__ = __delitem__
__ilshift__ = __irshift__ = __delitem__
def test(verbosity=1, repeat=1):
"""test(verbosity=1, repeat=1) -> TextTestResult
Run self-test, and return unittest.runner.TextTestResult object.
"""
from bitarray import test_bitarray
return test_bitarray.run(verbosity=verbosity, repeat=repeat)