bitstring 4.2.3__tar.gz → 4.3.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {bitstring-4.2.3 → bitstring-4.3.0}/LICENSE +1 -1
- {bitstring-4.2.3/bitstring.egg-info → bitstring-4.3.0}/PKG-INFO +8 -7
- {bitstring-4.2.3 → bitstring-4.3.0}/README.md +5 -5
- {bitstring-4.2.3 → bitstring-4.3.0}/bitstring/__init__.py +1 -1
- {bitstring-4.2.3 → bitstring-4.3.0}/bitstring/array_.py +2 -6
- {bitstring-4.2.3 → bitstring-4.3.0}/bitstring/bits.py +1 -6
- {bitstring-4.2.3 → bitstring-4.3.0}/bitstring/bitstore.py +34 -20
- {bitstring-4.2.3 → bitstring-4.3.0}/bitstring/utils.py +8 -5
- {bitstring-4.2.3 → bitstring-4.3.0/bitstring.egg-info}/PKG-INFO +8 -7
- bitstring-4.3.0/bitstring.egg-info/requires.txt +1 -0
- {bitstring-4.2.3 → bitstring-4.3.0}/pyproject.toml +3 -2
- {bitstring-4.2.3 → bitstring-4.3.0}/release_notes.md +7 -0
- {bitstring-4.2.3 → bitstring-4.3.0}/tests/test_bits.py +39 -3
- {bitstring-4.2.3 → bitstring-4.3.0}/tests/test_bitstream.py +12 -4
- bitstring-4.2.3/bitstring.egg-info/requires.txt +0 -1
- {bitstring-4.2.3 → bitstring-4.3.0}/MANIFEST.in +0 -0
- {bitstring-4.2.3 → bitstring-4.3.0}/bitstring/__main__.py +0 -0
- {bitstring-4.2.3 → bitstring-4.3.0}/bitstring/bitarray_.py +0 -0
- {bitstring-4.2.3 → bitstring-4.3.0}/bitstring/bitstore_helpers.py +0 -0
- {bitstring-4.2.3 → bitstring-4.3.0}/bitstring/bitstream.py +0 -0
- {bitstring-4.2.3 → bitstring-4.3.0}/bitstring/bitstring_options.py +0 -0
- {bitstring-4.2.3 → bitstring-4.3.0}/bitstring/dtypes.py +0 -0
- {bitstring-4.2.3 → bitstring-4.3.0}/bitstring/exceptions.py +0 -0
- {bitstring-4.2.3 → bitstring-4.3.0}/bitstring/fp8.py +0 -0
- {bitstring-4.2.3 → bitstring-4.3.0}/bitstring/luts.py +0 -0
- {bitstring-4.2.3 → bitstring-4.3.0}/bitstring/methods.py +0 -0
- {bitstring-4.2.3 → bitstring-4.3.0}/bitstring/mxfp.py +0 -0
- {bitstring-4.2.3 → bitstring-4.3.0}/bitstring/py.typed +0 -0
- {bitstring-4.2.3 → bitstring-4.3.0}/bitstring.egg-info/SOURCES.txt +0 -0
- {bitstring-4.2.3 → bitstring-4.3.0}/bitstring.egg-info/dependency_links.txt +0 -0
- {bitstring-4.2.3 → bitstring-4.3.0}/bitstring.egg-info/top_level.txt +0 -0
- {bitstring-4.2.3 → bitstring-4.3.0}/setup.cfg +0 -0
- {bitstring-4.2.3 → bitstring-4.3.0}/tests/__init__.py +0 -0
- {bitstring-4.2.3 → bitstring-4.3.0}/tests/smalltestfile +0 -0
- {bitstring-4.2.3 → bitstring-4.3.0}/tests/test.m1v +0 -0
- {bitstring-4.2.3 → bitstring-4.3.0}/tests/test_array.py +0 -0
- {bitstring-4.2.3 → bitstring-4.3.0}/tests/test_benchmarks.py +0 -0
- {bitstring-4.2.3 → bitstring-4.3.0}/tests/test_bitarray.py +0 -0
- {bitstring-4.2.3 → bitstring-4.3.0}/tests/test_bitstore.py +0 -0
- {bitstring-4.2.3 → bitstring-4.3.0}/tests/test_bitstring.py +0 -0
- {bitstring-4.2.3 → bitstring-4.3.0}/tests/test_constbitstream.py +0 -0
- {bitstring-4.2.3 → bitstring-4.3.0}/tests/test_dtypes.py +0 -0
- {bitstring-4.2.3 → bitstring-4.3.0}/tests/test_fp8.py +0 -0
- {bitstring-4.2.3 → bitstring-4.3.0}/tests/test_mxfp.py +0 -0
- {bitstring-4.2.3 → bitstring-4.3.0}/tests/test_scaled_dtypes.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
The MIT License
|
|
2
2
|
|
|
3
|
-
Copyright (c) 2006 Scott Griffiths (dr.scottgriffiths@gmail.com)
|
|
3
|
+
Copyright (c) 2006-2025 Scott Griffiths (dr.scottgriffiths@gmail.com)
|
|
4
4
|
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
6
|
of this software and associated documentation files (the "Software"), to deal
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: bitstring
|
|
3
|
-
Version: 4.
|
|
3
|
+
Version: 4.3.0
|
|
4
4
|
Summary: Simple construction, analysis and modification of binary data.
|
|
5
5
|
Author-email: Scott Griffiths <dr.scottgriffiths@gmail.com>
|
|
6
6
|
Project-URL: homepage, https://github.com/scott-griffiths/bitstring
|
|
@@ -15,20 +15,21 @@ Classifier: Programming Language :: Python :: 3.9
|
|
|
15
15
|
Classifier: Programming Language :: Python :: 3.10
|
|
16
16
|
Classifier: Programming Language :: Python :: 3.11
|
|
17
17
|
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
18
19
|
Classifier: License :: OSI Approved :: MIT License
|
|
19
20
|
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
20
21
|
Requires-Python: >=3.8
|
|
21
22
|
Description-Content-Type: text/markdown
|
|
22
23
|
License-File: LICENSE
|
|
23
|
-
Requires-Dist: bitarray<3.
|
|
24
|
+
Requires-Dist: bitarray<3.1,>=3.0.0
|
|
24
25
|
|
|
25
26
|
|
|
26
27
|
|
|
27
28
|

|
|
28
29
|
|
|
29
|
-
**bitstring** is a Python
|
|
30
|
+
**bitstring** is a Python library to help make the creation and analysis of all types of bit-level binary data as simple and efficient as possible. It has been actively maintained since 2006.
|
|
30
31
|
|
|
31
|
-
|
|
32
|
+
The library has has now been downloaded over 100 million times! ✨ [](https://www.pepy.tech/projects/bitstring) ✨
|
|
32
33
|
|
|
33
34
|
|
|
34
35
|
|
|
@@ -37,7 +38,7 @@ It has been actively maintained since 2006.
|
|
|
37
38
|
[](https://app.codacy.com/gh/scott-griffiths/bitstring/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_grade)
|
|
38
39
|
[](https://libraries.io/pypi/bitstring)
|
|
39
40
|
|
|
40
|
-
[](https://www.pepy.tech/projects/bitstring)
|
|
41
42
|
[](https://pypistats.org/packages/bitstring)
|
|
42
43
|
|
|
43
44
|
----
|
|
@@ -59,7 +60,7 @@ It has been actively maintained since 2006.
|
|
|
59
60
|
|
|
60
61
|
# Documentation
|
|
61
62
|
|
|
62
|
-
Extensive documentation for the bitstring
|
|
63
|
+
Extensive documentation for the bitstring library is available.
|
|
63
64
|
Some starting points are given below:
|
|
64
65
|
|
|
65
66
|
* [Overview](https://bitstring.readthedocs.io/en/stable/index.html)
|
|
@@ -130,4 +131,4 @@ Array('uint7', [45, 100, 15, 1])
|
|
|
130
131
|
```
|
|
131
132
|
|
|
132
133
|
|
|
133
|
-
<sub>Copyright (c) 2006 -
|
|
134
|
+
<sub>Copyright (c) 2006 - 2025 Scott Griffiths</sub>
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|

|
|
4
4
|
|
|
5
|
-
**bitstring** is a Python
|
|
5
|
+
**bitstring** is a Python library to help make the creation and analysis of all types of bit-level binary data as simple and efficient as possible. It has been actively maintained since 2006.
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
The library has has now been downloaded over 100 million times! ✨ [](https://www.pepy.tech/projects/bitstring) ✨
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
|
|
@@ -13,7 +13,7 @@ It has been actively maintained since 2006.
|
|
|
13
13
|
[](https://app.codacy.com/gh/scott-griffiths/bitstring/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_grade)
|
|
14
14
|
[](https://libraries.io/pypi/bitstring)
|
|
15
15
|
|
|
16
|
-
[](https://www.pepy.tech/projects/bitstring)
|
|
17
17
|
[](https://pypistats.org/packages/bitstring)
|
|
18
18
|
|
|
19
19
|
----
|
|
@@ -35,7 +35,7 @@ It has been actively maintained since 2006.
|
|
|
35
35
|
|
|
36
36
|
# Documentation
|
|
37
37
|
|
|
38
|
-
Extensive documentation for the bitstring
|
|
38
|
+
Extensive documentation for the bitstring library is available.
|
|
39
39
|
Some starting points are given below:
|
|
40
40
|
|
|
41
41
|
* [Overview](https://bitstring.readthedocs.io/en/stable/index.html)
|
|
@@ -106,4 +106,4 @@ Array('uint7', [45, 100, 15, 1])
|
|
|
106
106
|
```
|
|
107
107
|
|
|
108
108
|
|
|
109
|
-
<sub>Copyright (c) 2006 -
|
|
109
|
+
<sub>Copyright (c) 2006 - 2025 Scott Griffiths</sub>
|
|
@@ -760,12 +760,8 @@ class Array:
|
|
|
760
760
|
def _eq_ne(self, op, other: Any) -> Array:
|
|
761
761
|
if isinstance(other, (int, float, str, Bits)):
|
|
762
762
|
return self._apply_op_to_all_elements(op, other, is_comparison=True)
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
except:
|
|
766
|
-
return NotImplemented
|
|
767
|
-
finally:
|
|
768
|
-
return self._apply_op_between_arrays(op, other, is_comparison=True)
|
|
763
|
+
other = self.__class__(self.dtype, other)
|
|
764
|
+
return self._apply_op_between_arrays(op, other, is_comparison=True)
|
|
769
765
|
|
|
770
766
|
def __eq__(self, other: Any) -> Array:
|
|
771
767
|
return self._eq_ne(operator.eq, other)
|
|
@@ -231,13 +231,8 @@ class Bits:
|
|
|
231
231
|
def __getitem__(self: TBits, key: Union[slice, int], /) -> Union[TBits, bool]:
|
|
232
232
|
"""Return a new bitstring representing a slice of the current bitstring.
|
|
233
233
|
|
|
234
|
-
|
|
235
|
-
Stepping is used to specify the number of bits in each item.
|
|
236
|
-
|
|
237
|
-
>>> print(BitArray('0b00110')[1:4])
|
|
234
|
+
>>> print(Bits('0b00110')[1:4])
|
|
238
235
|
'0b011'
|
|
239
|
-
>>> print(BitArray('0x00112233')[1:3:8])
|
|
240
|
-
'0x1122'
|
|
241
236
|
|
|
242
237
|
"""
|
|
243
238
|
if isinstance(key, numbers.Integral):
|
|
@@ -4,24 +4,38 @@ import bitarray
|
|
|
4
4
|
from bitstring.exceptions import CreationError
|
|
5
5
|
from typing import Union, Iterable, Optional, overload, Iterator, Any
|
|
6
6
|
|
|
7
|
+
if bitarray.__version__.startswith("2."):
|
|
8
|
+
raise ImportError(f"bitstring version 4.3 requires bitarray version 3 or higher. Found version {bitarray.__version__}.")
|
|
9
|
+
|
|
10
|
+
def indices(s: slice, length: int) -> tuple[int, int | None, int]:
|
|
11
|
+
"""A better implementation of slice.indices such that a
|
|
12
|
+
slice made from [start:stop:step] will actually equal the original slice."""
|
|
13
|
+
if s.step is None or s.step > 0:
|
|
14
|
+
return s.indices(length)
|
|
15
|
+
assert s.step < 0
|
|
16
|
+
start, stop, step = s.indices(length)
|
|
17
|
+
if stop < 0:
|
|
18
|
+
stop = None
|
|
19
|
+
return start, stop, step
|
|
7
20
|
|
|
8
21
|
def offset_slice_indices_lsb0(key: slice, length: int) -> slice:
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
22
|
+
start, stop, step = indices(key, length)
|
|
23
|
+
if step is not None and step < 0:
|
|
24
|
+
if stop is None:
|
|
25
|
+
new_start = start + 1
|
|
26
|
+
new_stop = None
|
|
27
|
+
else:
|
|
28
|
+
first_element = start
|
|
29
|
+
last_element = start + ((stop + 1 - start) // step) * step
|
|
30
|
+
new_start = length - last_element
|
|
31
|
+
new_stop = length - first_element - 1
|
|
32
|
+
else:
|
|
33
|
+
first_element = start
|
|
34
|
+
# The last element will usually be stop - 1, but needs to be adjusted if step != 1.
|
|
35
|
+
last_element = start + ((stop - 1 - start) // step) * step
|
|
36
|
+
new_start = length - last_element - 1
|
|
37
|
+
new_stop = length - first_element
|
|
38
|
+
return slice(new_start, new_stop, key.step)
|
|
25
39
|
|
|
26
40
|
|
|
27
41
|
class BitStore:
|
|
@@ -150,7 +164,7 @@ class BitStore:
|
|
|
150
164
|
byte_pos = byte_pos + 1
|
|
151
165
|
return
|
|
152
166
|
# General case
|
|
153
|
-
i = self._bitarray.
|
|
167
|
+
i = self._bitarray.search(bs._bitarray, start, end)
|
|
154
168
|
if not bytealigned:
|
|
155
169
|
for p in i:
|
|
156
170
|
yield p
|
|
@@ -160,7 +174,7 @@ class BitStore:
|
|
|
160
174
|
yield p
|
|
161
175
|
|
|
162
176
|
def rfindall_msb0(self, bs: BitStore, start: int, end: int, bytealigned: bool = False) -> Iterator[int]:
|
|
163
|
-
i = self._bitarray.
|
|
177
|
+
i = self._bitarray.search(bs._bitarray, start, end, right=True)
|
|
164
178
|
if not bytealigned:
|
|
165
179
|
for p in i:
|
|
166
180
|
yield p
|
|
@@ -213,8 +227,8 @@ class BitStore:
|
|
|
213
227
|
return BitStore(self._bitarray[start:stop])
|
|
214
228
|
|
|
215
229
|
def getslice_lsb0(self, start: Optional[int], stop: Optional[int], /) -> BitStore:
|
|
216
|
-
|
|
217
|
-
return BitStore(self._bitarray[start:stop])
|
|
230
|
+
s = offset_slice_indices_lsb0(slice(start, stop, None), len(self))
|
|
231
|
+
return BitStore(self._bitarray[s.start:s.stop])
|
|
218
232
|
|
|
219
233
|
def getindex_lsb0(self, index: int, /) -> bool:
|
|
220
234
|
return bool(self._bitarray.__getitem__(-index - 1))
|
|
@@ -21,26 +21,28 @@ MULTIPLICATIVE_RE: Pattern[str] = re.compile(r'^(?P<factor>.*)\*(?P<token>.+)')
|
|
|
21
21
|
LITERAL_RE: Pattern[str] = re.compile(r'^(?P<name>0([xob]))(?P<value>.+)', re.IGNORECASE)
|
|
22
22
|
|
|
23
23
|
# An endianness indicator followed by one or more struct.pack codes
|
|
24
|
-
STRUCT_PACK_RE: Pattern[str] = re.compile(r'^(?P<endian>[<>@=])(?P<fmt>(?:\d*[
|
|
24
|
+
STRUCT_PACK_RE: Pattern[str] = re.compile(r'^(?P<endian>[<>@=])(?P<fmt>(?:\d*[bBhHlLiIqQefd])+)$')
|
|
25
25
|
# The same as above, but it doesn't insist on an endianness as it's byteswapping anyway.
|
|
26
|
-
BYTESWAP_STRUCT_PACK_RE: Pattern[str] = re.compile(r'^(?P<endian>[<>@=])?(?P<fmt>(?:\d*[
|
|
26
|
+
BYTESWAP_STRUCT_PACK_RE: Pattern[str] = re.compile(r'^(?P<endian>[<>@=])?(?P<fmt>(?:\d*[bBhHlLiIqQefd])+)$')
|
|
27
27
|
# An endianness indicator followed by exactly one struct.pack codes
|
|
28
|
-
SINGLE_STRUCT_PACK_RE: Pattern[str] = re.compile(r'^(?P<endian>[<>@=])(?P<fmt>[
|
|
28
|
+
SINGLE_STRUCT_PACK_RE: Pattern[str] = re.compile(r'^(?P<endian>[<>@=])(?P<fmt>[bBhHlLiIqQefd])$')
|
|
29
29
|
|
|
30
30
|
# A number followed by a single character struct.pack code
|
|
31
|
-
STRUCT_SPLIT_RE: Pattern[str] = re.compile(r'\d*[
|
|
31
|
+
STRUCT_SPLIT_RE: Pattern[str] = re.compile(r'\d*[bBhHlLiIqQefd]')
|
|
32
32
|
|
|
33
33
|
# These replicate the struct.pack codes
|
|
34
34
|
# Big-endian
|
|
35
35
|
REPLACEMENTS_BE: Dict[str, str] = {'b': 'int8', 'B': 'uint8',
|
|
36
36
|
'h': 'intbe16', 'H': 'uintbe16',
|
|
37
37
|
'l': 'intbe32', 'L': 'uintbe32',
|
|
38
|
+
'i': 'intbe32', 'I': 'uintbe32',
|
|
38
39
|
'q': 'intbe64', 'Q': 'uintbe64',
|
|
39
40
|
'e': 'floatbe16', 'f': 'floatbe32', 'd': 'floatbe64'}
|
|
40
41
|
# Little-endian
|
|
41
42
|
REPLACEMENTS_LE: Dict[str, str] = {'b': 'int8', 'B': 'uint8',
|
|
42
43
|
'h': 'intle16', 'H': 'uintle16',
|
|
43
44
|
'l': 'intle32', 'L': 'uintle32',
|
|
45
|
+
'i': 'intle32', 'I': 'uintle32',
|
|
44
46
|
'q': 'intle64', 'Q': 'uintle64',
|
|
45
47
|
'e': 'floatle16', 'f': 'floatle32', 'd': 'floatle64'}
|
|
46
48
|
|
|
@@ -48,11 +50,12 @@ REPLACEMENTS_LE: Dict[str, str] = {'b': 'int8', 'B': 'uint8',
|
|
|
48
50
|
REPLACEMENTS_NE: Dict[str, str] = {'b': 'int8', 'B': 'uint8',
|
|
49
51
|
'h': 'intne16', 'H': 'uintne16',
|
|
50
52
|
'l': 'intne32', 'L': 'uintne32',
|
|
53
|
+
'i': 'intne32', 'I': 'uintne32',
|
|
51
54
|
'q': 'intne64', 'Q': 'uintne64',
|
|
52
55
|
'e': 'floatne16', 'f': 'floatne32', 'd': 'floatne64'}
|
|
53
56
|
|
|
54
57
|
# Size in bytes of all the pack codes.
|
|
55
|
-
PACK_CODE_SIZE: Dict[str, int] = {'b': 1, 'B': 1, 'h': 2, 'H': 2, 'l': 4, 'L': 4,
|
|
58
|
+
PACK_CODE_SIZE: Dict[str, int] = {'b': 1, 'B': 1, 'h': 2, 'H': 2, 'l': 4, 'L': 4, 'i': 4, 'I': 4,
|
|
56
59
|
'q': 8, 'Q': 8, 'e': 2, 'f': 4, 'd': 8}
|
|
57
60
|
|
|
58
61
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: bitstring
|
|
3
|
-
Version: 4.
|
|
3
|
+
Version: 4.3.0
|
|
4
4
|
Summary: Simple construction, analysis and modification of binary data.
|
|
5
5
|
Author-email: Scott Griffiths <dr.scottgriffiths@gmail.com>
|
|
6
6
|
Project-URL: homepage, https://github.com/scott-griffiths/bitstring
|
|
@@ -15,20 +15,21 @@ Classifier: Programming Language :: Python :: 3.9
|
|
|
15
15
|
Classifier: Programming Language :: Python :: 3.10
|
|
16
16
|
Classifier: Programming Language :: Python :: 3.11
|
|
17
17
|
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
18
19
|
Classifier: License :: OSI Approved :: MIT License
|
|
19
20
|
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
20
21
|
Requires-Python: >=3.8
|
|
21
22
|
Description-Content-Type: text/markdown
|
|
22
23
|
License-File: LICENSE
|
|
23
|
-
Requires-Dist: bitarray<3.
|
|
24
|
+
Requires-Dist: bitarray<3.1,>=3.0.0
|
|
24
25
|
|
|
25
26
|
|
|
26
27
|
|
|
27
28
|

|
|
28
29
|
|
|
29
|
-
**bitstring** is a Python
|
|
30
|
+
**bitstring** is a Python library to help make the creation and analysis of all types of bit-level binary data as simple and efficient as possible. It has been actively maintained since 2006.
|
|
30
31
|
|
|
31
|
-
|
|
32
|
+
The library has has now been downloaded over 100 million times! ✨ [](https://www.pepy.tech/projects/bitstring) ✨
|
|
32
33
|
|
|
33
34
|
|
|
34
35
|
|
|
@@ -37,7 +38,7 @@ It has been actively maintained since 2006.
|
|
|
37
38
|
[](https://app.codacy.com/gh/scott-griffiths/bitstring/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_grade)
|
|
38
39
|
[](https://libraries.io/pypi/bitstring)
|
|
39
40
|
|
|
40
|
-
[](https://www.pepy.tech/projects/bitstring)
|
|
41
42
|
[](https://pypistats.org/packages/bitstring)
|
|
42
43
|
|
|
43
44
|
----
|
|
@@ -59,7 +60,7 @@ It has been actively maintained since 2006.
|
|
|
59
60
|
|
|
60
61
|
# Documentation
|
|
61
62
|
|
|
62
|
-
Extensive documentation for the bitstring
|
|
63
|
+
Extensive documentation for the bitstring library is available.
|
|
63
64
|
Some starting points are given below:
|
|
64
65
|
|
|
65
66
|
* [Overview](https://bitstring.readthedocs.io/en/stable/index.html)
|
|
@@ -130,4 +131,4 @@ Array('uint7', [45, 100, 15, 1])
|
|
|
130
131
|
```
|
|
131
132
|
|
|
132
133
|
|
|
133
|
-
<sub>Copyright (c) 2006 -
|
|
134
|
+
<sub>Copyright (c) 2006 - 2025 Scott Griffiths</sub>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
bitarray<3.1,>=3.0.0
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "bitstring"
|
|
7
|
-
version = "4.
|
|
7
|
+
version = "4.3.0"
|
|
8
8
|
authors = [
|
|
9
9
|
{ name="Scott Griffiths", email="dr.scottgriffiths@gmail.com" },
|
|
10
10
|
]
|
|
@@ -21,12 +21,13 @@ classifiers = [
|
|
|
21
21
|
"Programming Language :: Python :: 3.10",
|
|
22
22
|
"Programming Language :: Python :: 3.11",
|
|
23
23
|
"Programming Language :: Python :: 3.12",
|
|
24
|
+
"Programming Language :: Python :: 3.13",
|
|
24
25
|
"License :: OSI Approved :: MIT License",
|
|
25
26
|
"Topic :: Software Development :: Libraries :: Python Modules",
|
|
26
27
|
]
|
|
27
28
|
keywords = ["binary", "bitarray", "bitvector", "bitfield"]
|
|
28
29
|
dependencies = [
|
|
29
|
-
"bitarray >=
|
|
30
|
+
"bitarray >= 3.0.0, < 3.1"
|
|
30
31
|
]
|
|
31
32
|
|
|
32
33
|
[project.urls]
|
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
|
|
2
2
|
# Release Notes
|
|
3
3
|
|
|
4
|
+
### January 2025: version 4.3.0
|
|
5
|
+
|
|
6
|
+
* Upgraded bitarray dependency to >= 3.0.0.
|
|
7
|
+
* Explicit support for Python 3.13.
|
|
8
|
+
* Removed the 'experimental feature' label from the new exotic floating point types.
|
|
9
|
+
* Fix for LSB0 slicing issue. Bug #343.
|
|
10
|
+
|
|
4
11
|
### May 2024: version 4.2.3
|
|
5
12
|
|
|
6
13
|
#### More small bug fixes related to some of the new (beta) float formats.
|
|
@@ -8,9 +8,9 @@ import array
|
|
|
8
8
|
import os
|
|
9
9
|
import re
|
|
10
10
|
from bitstring import InterpretError, Bits, BitArray
|
|
11
|
-
from hypothesis import given, assume
|
|
11
|
+
from hypothesis import given, assume, reproduce_failure, settings
|
|
12
12
|
import hypothesis.strategies as st
|
|
13
|
-
|
|
13
|
+
from bitstring.bitstore import offset_slice_indices_lsb0
|
|
14
14
|
|
|
15
15
|
sys.path.insert(0, '..')
|
|
16
16
|
|
|
@@ -20,6 +20,33 @@ def remove_unprintable(s: str) -> str:
|
|
|
20
20
|
colour_escape = re.compile(r'(?:\x1B[@-_])[0-?]*[ -/]*[@-~]')
|
|
21
21
|
return colour_escape.sub('', s)
|
|
22
22
|
|
|
23
|
+
|
|
24
|
+
@settings(max_examples=500)
|
|
25
|
+
@given(length=st.integers(0, 9),
|
|
26
|
+
start=st.integers(-20, 20),
|
|
27
|
+
stop=st.integers(-20, 20),
|
|
28
|
+
step=st.integers(0, 7))
|
|
29
|
+
def test_lsb0_slicing(length, start, stop, step):
|
|
30
|
+
if start == -20:
|
|
31
|
+
start = None
|
|
32
|
+
if stop == -20:
|
|
33
|
+
stop = None
|
|
34
|
+
if step == 0:
|
|
35
|
+
step = None
|
|
36
|
+
values_fwd = list(range(0, length))
|
|
37
|
+
values_bwd = list(range(0, length))
|
|
38
|
+
values_bwd.reverse()
|
|
39
|
+
|
|
40
|
+
# Convert the start, stop, step to a range over the length
|
|
41
|
+
start1, stop1, step1 = slice(start, stop, step).indices(length)
|
|
42
|
+
values1 = values_fwd[start1:stop1:step1]
|
|
43
|
+
|
|
44
|
+
lsb0key = offset_slice_indices_lsb0(slice(start, stop, step), length)
|
|
45
|
+
values2 = values_bwd[lsb0key.start:lsb0key.stop:lsb0key.step]
|
|
46
|
+
values2.reverse()
|
|
47
|
+
assert values1 == values2
|
|
48
|
+
|
|
49
|
+
|
|
23
50
|
class TestCreation:
|
|
24
51
|
def test_creation_from_bytes(self):
|
|
25
52
|
s = Bits(bytes=b'\xa0\xff')
|
|
@@ -530,7 +557,7 @@ class TestLsb0Indexing:
|
|
|
530
557
|
assert a[:-8] == '0xcdef'
|
|
531
558
|
|
|
532
559
|
def test_extended_slicing(self):
|
|
533
|
-
a = Bits('
|
|
560
|
+
a = Bits('0b0100000100100100')
|
|
534
561
|
assert a[2::3] == '0b10111'
|
|
535
562
|
|
|
536
563
|
def test_all(self):
|
|
@@ -556,6 +583,15 @@ class TestLsb0Indexing:
|
|
|
556
583
|
assert a.endswith('0x123')
|
|
557
584
|
assert not a.endswith('0xabcd')
|
|
558
585
|
|
|
586
|
+
def test_lsb0_slicing_error(self):
|
|
587
|
+
a = Bits('0b01')
|
|
588
|
+
b = a[::-1]
|
|
589
|
+
assert b == '0b10'
|
|
590
|
+
t = Bits('0xf0a')[::-1]
|
|
591
|
+
assert t == '0x50f'
|
|
592
|
+
s = Bits('0xf0a')[::-1][::-1]
|
|
593
|
+
assert s == '0xf0a'
|
|
594
|
+
|
|
559
595
|
|
|
560
596
|
class TestLsb0Interpretations:
|
|
561
597
|
|
|
@@ -2488,6 +2488,8 @@ class TestSplit2:
|
|
|
2488
2488
|
assert pack('<H', 23) == BitStream('uintle:16=23')
|
|
2489
2489
|
assert pack('<l', 23) == BitStream('intle:32=23')
|
|
2490
2490
|
assert pack('<L', 23) == BitStream('uintle:32=23')
|
|
2491
|
+
assert pack('<i', 23) == BitStream('intle:32=23')
|
|
2492
|
+
assert pack('<I', 23) == BitStream('uintle:32=23')
|
|
2491
2493
|
assert pack('<q', 23) == BitStream('intle:64=23')
|
|
2492
2494
|
assert pack('<Q', 23) == BitStream('uintle:64=23')
|
|
2493
2495
|
assert pack('>b', 23) == BitStream('intbe:8=23')
|
|
@@ -2496,6 +2498,8 @@ class TestSplit2:
|
|
|
2496
2498
|
assert pack('>H', 23) == BitStream('uintbe:16=23')
|
|
2497
2499
|
assert pack('>l', 23) == BitStream('intbe:32=23')
|
|
2498
2500
|
assert pack('>L', 23) == BitStream('uintbe:32=23')
|
|
2501
|
+
assert pack('>i', 23) == BitStream('intbe:32=23')
|
|
2502
|
+
assert pack('>I', 23) == BitStream('uintbe:32=23')
|
|
2499
2503
|
assert pack('>q', 23) == BitStream('intbe:64=23')
|
|
2500
2504
|
assert pack('>Q', 23) == BitStream('uintbe:64=23')
|
|
2501
2505
|
with pytest.raises(bitstring.CreationError):
|
|
@@ -2517,6 +2521,8 @@ class TestSplit2:
|
|
|
2517
2521
|
assert pack('=H', 23) == BitStream('uintle:16=23')
|
|
2518
2522
|
assert pack('@l', 23) == BitStream('intle:32=23')
|
|
2519
2523
|
assert pack('@L', 23) == BitStream('uintle:32=23')
|
|
2524
|
+
assert pack('@i', 23) == BitStream('intle:32=23')
|
|
2525
|
+
assert pack('@I', 23) == BitStream('uintle:32=23')
|
|
2520
2526
|
assert pack('@q', 23) == BitStream('intle:64=23')
|
|
2521
2527
|
assert pack('@Q', 23) == BitStream('uintle:64=23')
|
|
2522
2528
|
else:
|
|
@@ -2526,23 +2532,25 @@ class TestSplit2:
|
|
|
2526
2532
|
assert pack('@H', 23) == BitStream('uintbe:16=23')
|
|
2527
2533
|
assert pack('@l', 23) == BitStream('intbe:32=23')
|
|
2528
2534
|
assert pack('@L', 23) == BitStream('uintbe:32=23')
|
|
2535
|
+
assert pack('@i', 23) == BitStream('intbe:32=23')
|
|
2536
|
+
assert pack('@I', 23) == BitStream('uintbe:32=23')
|
|
2529
2537
|
assert pack('@q', 23) == BitStream('intbe:64=23')
|
|
2530
2538
|
assert pack('@Q', 23) == BitStream('uintbe:64=23')
|
|
2531
2539
|
|
|
2532
2540
|
def test_native_endianness(self):
|
|
2533
|
-
s = pack('=
|
|
2541
|
+
s = pack('=2i', 40, 40)
|
|
2534
2542
|
if sys.byteorder == 'little':
|
|
2535
|
-
assert s == pack('<
|
|
2543
|
+
assert s == pack('<2i', 40, 40)
|
|
2536
2544
|
else:
|
|
2537
2545
|
assert sys.byteorder == 'big'
|
|
2538
|
-
assert s == pack('>
|
|
2546
|
+
assert s == pack('>2i', 40, 40)
|
|
2539
2547
|
|
|
2540
2548
|
def test_struct_tokens3(self):
|
|
2541
2549
|
s = pack('>hhl', 1, 2, 3)
|
|
2542
2550
|
a, b, c = s.unpack('>hhl')
|
|
2543
2551
|
assert (a, b, c) == (1, 2, 3)
|
|
2544
2552
|
s = pack('<QL, >Q \tL', 1001, 43, 21, 9999)
|
|
2545
|
-
assert s.unpack('<
|
|
2553
|
+
assert s.unpack('<QI, >QL') == [1001, 43, 21, 9999]
|
|
2546
2554
|
|
|
2547
2555
|
def test_struct_tokens_multiplicative_factors(self):
|
|
2548
2556
|
s = pack('<2h', 1, 2)
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
bitarray<3.0.0,>=2.9.0
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|