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.
Files changed (45) hide show
  1. {bitstring-4.2.3 → bitstring-4.3.0}/LICENSE +1 -1
  2. {bitstring-4.2.3/bitstring.egg-info → bitstring-4.3.0}/PKG-INFO +8 -7
  3. {bitstring-4.2.3 → bitstring-4.3.0}/README.md +5 -5
  4. {bitstring-4.2.3 → bitstring-4.3.0}/bitstring/__init__.py +1 -1
  5. {bitstring-4.2.3 → bitstring-4.3.0}/bitstring/array_.py +2 -6
  6. {bitstring-4.2.3 → bitstring-4.3.0}/bitstring/bits.py +1 -6
  7. {bitstring-4.2.3 → bitstring-4.3.0}/bitstring/bitstore.py +34 -20
  8. {bitstring-4.2.3 → bitstring-4.3.0}/bitstring/utils.py +8 -5
  9. {bitstring-4.2.3 → bitstring-4.3.0/bitstring.egg-info}/PKG-INFO +8 -7
  10. bitstring-4.3.0/bitstring.egg-info/requires.txt +1 -0
  11. {bitstring-4.2.3 → bitstring-4.3.0}/pyproject.toml +3 -2
  12. {bitstring-4.2.3 → bitstring-4.3.0}/release_notes.md +7 -0
  13. {bitstring-4.2.3 → bitstring-4.3.0}/tests/test_bits.py +39 -3
  14. {bitstring-4.2.3 → bitstring-4.3.0}/tests/test_bitstream.py +12 -4
  15. bitstring-4.2.3/bitstring.egg-info/requires.txt +0 -1
  16. {bitstring-4.2.3 → bitstring-4.3.0}/MANIFEST.in +0 -0
  17. {bitstring-4.2.3 → bitstring-4.3.0}/bitstring/__main__.py +0 -0
  18. {bitstring-4.2.3 → bitstring-4.3.0}/bitstring/bitarray_.py +0 -0
  19. {bitstring-4.2.3 → bitstring-4.3.0}/bitstring/bitstore_helpers.py +0 -0
  20. {bitstring-4.2.3 → bitstring-4.3.0}/bitstring/bitstream.py +0 -0
  21. {bitstring-4.2.3 → bitstring-4.3.0}/bitstring/bitstring_options.py +0 -0
  22. {bitstring-4.2.3 → bitstring-4.3.0}/bitstring/dtypes.py +0 -0
  23. {bitstring-4.2.3 → bitstring-4.3.0}/bitstring/exceptions.py +0 -0
  24. {bitstring-4.2.3 → bitstring-4.3.0}/bitstring/fp8.py +0 -0
  25. {bitstring-4.2.3 → bitstring-4.3.0}/bitstring/luts.py +0 -0
  26. {bitstring-4.2.3 → bitstring-4.3.0}/bitstring/methods.py +0 -0
  27. {bitstring-4.2.3 → bitstring-4.3.0}/bitstring/mxfp.py +0 -0
  28. {bitstring-4.2.3 → bitstring-4.3.0}/bitstring/py.typed +0 -0
  29. {bitstring-4.2.3 → bitstring-4.3.0}/bitstring.egg-info/SOURCES.txt +0 -0
  30. {bitstring-4.2.3 → bitstring-4.3.0}/bitstring.egg-info/dependency_links.txt +0 -0
  31. {bitstring-4.2.3 → bitstring-4.3.0}/bitstring.egg-info/top_level.txt +0 -0
  32. {bitstring-4.2.3 → bitstring-4.3.0}/setup.cfg +0 -0
  33. {bitstring-4.2.3 → bitstring-4.3.0}/tests/__init__.py +0 -0
  34. {bitstring-4.2.3 → bitstring-4.3.0}/tests/smalltestfile +0 -0
  35. {bitstring-4.2.3 → bitstring-4.3.0}/tests/test.m1v +0 -0
  36. {bitstring-4.2.3 → bitstring-4.3.0}/tests/test_array.py +0 -0
  37. {bitstring-4.2.3 → bitstring-4.3.0}/tests/test_benchmarks.py +0 -0
  38. {bitstring-4.2.3 → bitstring-4.3.0}/tests/test_bitarray.py +0 -0
  39. {bitstring-4.2.3 → bitstring-4.3.0}/tests/test_bitstore.py +0 -0
  40. {bitstring-4.2.3 → bitstring-4.3.0}/tests/test_bitstring.py +0 -0
  41. {bitstring-4.2.3 → bitstring-4.3.0}/tests/test_constbitstream.py +0 -0
  42. {bitstring-4.2.3 → bitstring-4.3.0}/tests/test_dtypes.py +0 -0
  43. {bitstring-4.2.3 → bitstring-4.3.0}/tests/test_fp8.py +0 -0
  44. {bitstring-4.2.3 → bitstring-4.3.0}/tests/test_mxfp.py +0 -0
  45. {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.2.3
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.0.0,>=2.9.0
24
+ Requires-Dist: bitarray<3.1,>=3.0.0
24
25
 
25
26
 
26
27
 
27
28
  ![bitstring](https://raw.githubusercontent.com/scott-griffiths/bitstring/main/doc/bitstring_logo_small.png "bitstring")
28
29
 
29
- **bitstring** is a Python module to help make the creation and analysis of all types of bit-level binary data as simple and efficient as possible.
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
- It has been actively maintained since 2006.
32
+ The library has has now been downloaded over 100 million times! &nbsp; &nbsp; ✨ [![Pepy Total Downloads](https://img.shields.io/pepy/dt/bitstring?label=Downloads:&labelColor=orange&color=orange)](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
  [![Codacy Badge](https://img.shields.io/codacy/grade/8869499b2eed44548fa1a5149dd451f4?logo=codacy)](https://app.codacy.com/gh/scott-griffiths/bitstring/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_grade)
38
39
  [![Dependents (via libraries.io)](https://img.shields.io/librariesio/dependents/pypi/bitstring?logo=libraries.io&logoColor=white)](https://libraries.io/pypi/bitstring)
39
40
  &nbsp; &nbsp;
40
- [![Pepy Total Downlods](https://img.shields.io/pepy/dt/bitstring?logo=python&logoColor=white&labelColor=blue&color=blue)](https://www.pepy.tech/projects/bitstring)
41
+ [![Pepy Total Downloads](https://img.shields.io/pepy/dt/bitstring?logo=python&logoColor=white&labelColor=blue&color=blue)](https://www.pepy.tech/projects/bitstring)
41
42
  [![PyPI - Downloads](https://img.shields.io/pypi/dm/bitstring?label=%40&labelColor=blue&color=blue)](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 module is available.
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 - 2024 Scott Griffiths</sub>
134
+ <sub>Copyright (c) 2006 - 2025 Scott Griffiths</sub>
@@ -2,9 +2,9 @@
2
2
 
3
3
  ![bitstring](https://raw.githubusercontent.com/scott-griffiths/bitstring/main/doc/bitstring_logo_small.png "bitstring")
4
4
 
5
- **bitstring** is a Python module to help make the creation and analysis of all types of bit-level binary data as simple and efficient as possible.
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
- It has been actively maintained since 2006.
7
+ The library has has now been downloaded over 100 million times! &nbsp; &nbsp; ✨ [![Pepy Total Downloads](https://img.shields.io/pepy/dt/bitstring?label=Downloads:&labelColor=orange&color=orange)](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
  [![Codacy Badge](https://img.shields.io/codacy/grade/8869499b2eed44548fa1a5149dd451f4?logo=codacy)](https://app.codacy.com/gh/scott-griffiths/bitstring/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_grade)
14
14
  [![Dependents (via libraries.io)](https://img.shields.io/librariesio/dependents/pypi/bitstring?logo=libraries.io&logoColor=white)](https://libraries.io/pypi/bitstring)
15
15
  &nbsp; &nbsp;
16
- [![Pepy Total Downlods](https://img.shields.io/pepy/dt/bitstring?logo=python&logoColor=white&labelColor=blue&color=blue)](https://www.pepy.tech/projects/bitstring)
16
+ [![Pepy Total Downloads](https://img.shields.io/pepy/dt/bitstring?logo=python&logoColor=white&labelColor=blue&color=blue)](https://www.pepy.tech/projects/bitstring)
17
17
  [![PyPI - Downloads](https://img.shields.io/pypi/dm/bitstring?label=%40&labelColor=blue&color=blue)](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 module is available.
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 - 2024 Scott Griffiths</sub>
109
+ <sub>Copyright (c) 2006 - 2025 Scott Griffiths</sub>
@@ -55,7 +55,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
55
55
  THE SOFTWARE.
56
56
  """
57
57
 
58
- __version__ = "4.2.3"
58
+ __version__ = "4.3.0"
59
59
 
60
60
  __author__ = "Scott Griffiths"
61
61
 
@@ -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
- try:
764
- other = self.__class__(self.dtype, other)
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
- Indices are in units of the step parameter (default 1 bit).
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
- # First convert slice to all integers
10
- # Length already should take account of the offset
11
- start, stop, step = key.indices(length)
12
- new_start = length - stop
13
- new_stop = length - start
14
- # For negative step we sometimes get a negative stop, which can't be used correctly in a new slice
15
- return slice(new_start, None if new_stop < 0 else new_stop, step)
16
-
17
-
18
- def offset_start_stop_lsb0(start: Optional[int], stop: Optional[int], length: int) -> tuple[int, int]:
19
- # First convert slice to all integers
20
- # Length already should take account of the offset
21
- start, stop, _ = slice(start, stop, None).indices(length)
22
- new_start = length - stop
23
- new_stop = length - start
24
- return new_start, new_stop
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.itersearch(bs._bitarray, start, end)
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.itersearch(bs._bitarray, start, end, right=True)
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
- start, stop = offset_start_stop_lsb0(start, stop, len(self))
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*[bBhHlLqQefd])+)$')
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*[bBhHlLqQefd])+)$')
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>[bBhHlLqQefd])$')
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*[bBhHlLqQefd]')
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.2.3
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.0.0,>=2.9.0
24
+ Requires-Dist: bitarray<3.1,>=3.0.0
24
25
 
25
26
 
26
27
 
27
28
  ![bitstring](https://raw.githubusercontent.com/scott-griffiths/bitstring/main/doc/bitstring_logo_small.png "bitstring")
28
29
 
29
- **bitstring** is a Python module to help make the creation and analysis of all types of bit-level binary data as simple and efficient as possible.
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
- It has been actively maintained since 2006.
32
+ The library has has now been downloaded over 100 million times! &nbsp; &nbsp; ✨ [![Pepy Total Downloads](https://img.shields.io/pepy/dt/bitstring?label=Downloads:&labelColor=orange&color=orange)](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
  [![Codacy Badge](https://img.shields.io/codacy/grade/8869499b2eed44548fa1a5149dd451f4?logo=codacy)](https://app.codacy.com/gh/scott-griffiths/bitstring/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_grade)
38
39
  [![Dependents (via libraries.io)](https://img.shields.io/librariesio/dependents/pypi/bitstring?logo=libraries.io&logoColor=white)](https://libraries.io/pypi/bitstring)
39
40
  &nbsp; &nbsp;
40
- [![Pepy Total Downlods](https://img.shields.io/pepy/dt/bitstring?logo=python&logoColor=white&labelColor=blue&color=blue)](https://www.pepy.tech/projects/bitstring)
41
+ [![Pepy Total Downloads](https://img.shields.io/pepy/dt/bitstring?logo=python&logoColor=white&labelColor=blue&color=blue)](https://www.pepy.tech/projects/bitstring)
41
42
  [![PyPI - Downloads](https://img.shields.io/pypi/dm/bitstring?label=%40&labelColor=blue&color=blue)](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 module is available.
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 - 2024 Scott Griffiths</sub>
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.2.3"
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 >= 2.9.0, < 3.0.0",
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('0b100000100100100')
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('=2L', 40, 40)
2541
+ s = pack('=2i', 40, 40)
2534
2542
  if sys.byteorder == 'little':
2535
- assert s == pack('<2L', 40, 40)
2543
+ assert s == pack('<2i', 40, 40)
2536
2544
  else:
2537
2545
  assert sys.byteorder == 'big'
2538
- assert s == pack('>2L', 40, 40)
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('<QL, >QL') == [1001, 43, 21, 9999]
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