bitstring 4.2.0b2__tar.gz → 4.2.1__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 (43) hide show
  1. {bitstring-4.2.0b2/bitstring.egg-info → bitstring-4.2.1}/PKG-INFO +6 -16
  2. {bitstring-4.2.0b2 → bitstring-4.2.1}/README.md +5 -15
  3. {bitstring-4.2.0b2 → bitstring-4.2.1}/bitstring/__init__.py +11 -5
  4. {bitstring-4.2.0b2 → bitstring-4.2.1}/bitstring/array_.py +4 -2
  5. {bitstring-4.2.0b2 → bitstring-4.2.1}/bitstring/bitarray_.py +1 -0
  6. {bitstring-4.2.0b2 → bitstring-4.2.1}/bitstring/bits.py +3 -11
  7. {bitstring-4.2.0b2 → bitstring-4.2.1}/bitstring/bitstream.py +10 -0
  8. {bitstring-4.2.0b2 → bitstring-4.2.1}/bitstring/dtypes.py +23 -20
  9. {bitstring-4.2.0b2 → bitstring-4.2.1}/bitstring/utils.py +2 -0
  10. {bitstring-4.2.0b2 → bitstring-4.2.1/bitstring.egg-info}/PKG-INFO +6 -16
  11. {bitstring-4.2.0b2 → bitstring-4.2.1}/pyproject.toml +1 -1
  12. {bitstring-4.2.0b2 → bitstring-4.2.1}/release_notes.txt +28 -6
  13. {bitstring-4.2.0b2 → bitstring-4.2.1}/tests/test_bitarray.py +13 -0
  14. {bitstring-4.2.0b2 → bitstring-4.2.1}/tests/test_bitstream.py +6 -0
  15. {bitstring-4.2.0b2 → bitstring-4.2.1}/LICENSE +0 -0
  16. {bitstring-4.2.0b2 → bitstring-4.2.1}/MANIFEST.in +0 -0
  17. {bitstring-4.2.0b2 → bitstring-4.2.1}/bitstring/__main__.py +0 -0
  18. {bitstring-4.2.0b2 → bitstring-4.2.1}/bitstring/bitstore.py +0 -0
  19. {bitstring-4.2.0b2 → bitstring-4.2.1}/bitstring/bitstore_helpers.py +0 -0
  20. {bitstring-4.2.0b2 → bitstring-4.2.1}/bitstring/bitstring_options.py +0 -0
  21. {bitstring-4.2.0b2 → bitstring-4.2.1}/bitstring/exceptions.py +0 -0
  22. {bitstring-4.2.0b2 → bitstring-4.2.1}/bitstring/fp8.py +0 -0
  23. {bitstring-4.2.0b2 → bitstring-4.2.1}/bitstring/luts.py +0 -0
  24. {bitstring-4.2.0b2 → bitstring-4.2.1}/bitstring/methods.py +0 -0
  25. {bitstring-4.2.0b2 → bitstring-4.2.1}/bitstring/mxfp.py +0 -0
  26. {bitstring-4.2.0b2 → bitstring-4.2.1}/bitstring/py.typed +0 -0
  27. {bitstring-4.2.0b2 → bitstring-4.2.1}/bitstring.egg-info/SOURCES.txt +0 -0
  28. {bitstring-4.2.0b2 → bitstring-4.2.1}/bitstring.egg-info/dependency_links.txt +0 -0
  29. {bitstring-4.2.0b2 → bitstring-4.2.1}/bitstring.egg-info/requires.txt +0 -0
  30. {bitstring-4.2.0b2 → bitstring-4.2.1}/bitstring.egg-info/top_level.txt +0 -0
  31. {bitstring-4.2.0b2 → bitstring-4.2.1}/setup.cfg +0 -0
  32. {bitstring-4.2.0b2 → bitstring-4.2.1}/tests/__init__.py +0 -0
  33. {bitstring-4.2.0b2 → bitstring-4.2.1}/tests/smalltestfile +0 -0
  34. {bitstring-4.2.0b2 → bitstring-4.2.1}/tests/test.m1v +0 -0
  35. {bitstring-4.2.0b2 → bitstring-4.2.1}/tests/test_array.py +0 -0
  36. {bitstring-4.2.0b2 → bitstring-4.2.1}/tests/test_bits.py +0 -0
  37. {bitstring-4.2.0b2 → bitstring-4.2.1}/tests/test_bitstore.py +0 -0
  38. {bitstring-4.2.0b2 → bitstring-4.2.1}/tests/test_bitstring.py +0 -0
  39. {bitstring-4.2.0b2 → bitstring-4.2.1}/tests/test_constbitstream.py +0 -0
  40. {bitstring-4.2.0b2 → bitstring-4.2.1}/tests/test_dtypes.py +0 -0
  41. {bitstring-4.2.0b2 → bitstring-4.2.1}/tests/test_fp8.py +0 -0
  42. {bitstring-4.2.0b2 → bitstring-4.2.1}/tests/test_mxfp.py +0 -0
  43. {bitstring-4.2.0b2 → bitstring-4.2.1}/tests/test_scaled_dtypes.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: bitstring
3
- Version: 4.2.0b2
3
+ Version: 4.2.1
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
@@ -43,18 +43,16 @@ It has been actively maintained since 2006.
43
43
 
44
44
  News
45
45
  ----
46
- **March 2024**: bitstring 4.2.0b2 released. This is the final beta release before 4.2.
47
-
48
- Install the beta with `pip install bitstring==4.2.0b2`, or use `pip install bitstring` for the latest stable version.
49
-
50
- New in 4.2:
46
+ **April 2024**: bitstring 4.2.1 released.
47
+
48
+ New in version 4.2:
51
49
 
52
50
  * Dropped support for Python 3.7. Minimum version is now 3.8.
53
51
  * A new `Dtype` class can be optionally used to specify types.
54
52
  * The `bitstring.options` object is now the preferred method for changing module options.
55
53
  * New `fromstring` method as another way to create bitstrings from formatted strings.
56
54
  * More types can now be pretty printed.
57
- * A range of 8-bit, 6-bit and even 4-bit float formats added (beta):
55
+ * A range of 8-bit, 6-bit and even 4-bit floating point formats added (beta):
58
56
  * Performance improvements.
59
57
 
60
58
  See the [release notes](https://github.com/scott-griffiths/bitstring/blob/main/release_notes.txt) for details. Please let me know if you encounter any problems.
@@ -81,7 +79,7 @@ Some starting points are given below:
81
79
  * [Quick Reference](https://bitstring.readthedocs.io/en/stable/quick_reference.html)
82
80
  * [Full Reference](https://bitstring.readthedocs.io/en/stable/reference.html)
83
81
 
84
- You can also try out the interactive walkthrough notebook on [binder](https://mybinder.org/v2/gh/scott-griffiths/bitstring/main?labpath=doc%2Fwalkthrough.ipynb).
82
+ There is also an introductory walkthrough notebook on [binder](https://mybinder.org/v2/gh/scott-griffiths/bitstring/main?labpath=doc%2Fwalkthrough.ipynb).
85
83
 
86
84
  Release Notes
87
85
  -------------
@@ -146,12 +144,4 @@ Examples
146
144
 
147
145
 
148
146
 
149
- Credits
150
- -------
151
-
152
- Created in 2006 to help with ad hoc parsing and creation of compressed video files.
153
- Maintained and expanded ever since as it became unexpectedly popular.
154
- Thanks to all those who have contributed ideas and code (and bug reports) over the years.
155
-
156
-
157
147
  <sub>Copyright (c) 2006 - 2024 Scott Griffiths</sub>
@@ -19,18 +19,16 @@ It has been actively maintained since 2006.
19
19
 
20
20
  News
21
21
  ----
22
- **March 2024**: bitstring 4.2.0b2 released. This is the final beta release before 4.2.
23
-
24
- Install the beta with `pip install bitstring==4.2.0b2`, or use `pip install bitstring` for the latest stable version.
25
-
26
- New in 4.2:
22
+ **April 2024**: bitstring 4.2.1 released.
23
+
24
+ New in version 4.2:
27
25
 
28
26
  * Dropped support for Python 3.7. Minimum version is now 3.8.
29
27
  * A new `Dtype` class can be optionally used to specify types.
30
28
  * The `bitstring.options` object is now the preferred method for changing module options.
31
29
  * New `fromstring` method as another way to create bitstrings from formatted strings.
32
30
  * More types can now be pretty printed.
33
- * A range of 8-bit, 6-bit and even 4-bit float formats added (beta):
31
+ * A range of 8-bit, 6-bit and even 4-bit floating point formats added (beta):
34
32
  * Performance improvements.
35
33
 
36
34
  See the [release notes](https://github.com/scott-griffiths/bitstring/blob/main/release_notes.txt) for details. Please let me know if you encounter any problems.
@@ -57,7 +55,7 @@ Some starting points are given below:
57
55
  * [Quick Reference](https://bitstring.readthedocs.io/en/stable/quick_reference.html)
58
56
  * [Full Reference](https://bitstring.readthedocs.io/en/stable/reference.html)
59
57
 
60
- You can also try out the interactive walkthrough notebook on [binder](https://mybinder.org/v2/gh/scott-griffiths/bitstring/main?labpath=doc%2Fwalkthrough.ipynb).
58
+ There is also an introductory walkthrough notebook on [binder](https://mybinder.org/v2/gh/scott-griffiths/bitstring/main?labpath=doc%2Fwalkthrough.ipynb).
61
59
 
62
60
  Release Notes
63
61
  -------------
@@ -122,12 +120,4 @@ Examples
122
120
 
123
121
 
124
122
 
125
- Credits
126
- -------
127
-
128
- Created in 2006 to help with ad hoc parsing and creation of compressed video files.
129
- Maintained and expanded ever since as it became unexpectedly popular.
130
- Thanks to all those who have contributed ideas and code (and bug reports) over the years.
131
-
132
-
133
123
  <sub>Copyright (c) 2006 - 2024 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.0b2"
58
+ __version__ = "4.2.1"
59
59
 
60
60
  __author__ = "Scott Griffiths"
61
61
 
@@ -86,6 +86,7 @@ bytealigned = lsb0 = None
86
86
 
87
87
 
88
88
  # An opaque way of adding module level properties. Taken from https://peps.python.org/pep-0549/
89
+ # This is now deprecated. Use the options object directly instead.
89
90
  class _MyModuleType(types.ModuleType):
90
91
  @property
91
92
  def bytealigned(self) -> bool:
@@ -301,10 +302,15 @@ for alias in aliases:
301
302
  property_docstrings = [f'{name} -- Interpret as {dtype_register[name].description}.' for name in dtype_register.names]
302
303
  property_docstring = '\n '.join(property_docstrings)
303
304
 
304
- Bits.__doc__ = Bits.__doc__.replace('[GENERATED_PROPERTY_DESCRIPTIONS]', property_docstring)
305
- BitArray.__doc__ = BitArray.__doc__.replace('[GENERATED_PROPERTY_DESCRIPTIONS]', property_docstring)
306
- ConstBitStream.__doc__ = ConstBitStream.__doc__.replace('[GENERATED_PROPERTY_DESCRIPTIONS]', property_docstring)
307
- BitStream.__doc__ = BitStream.__doc__.replace('[GENERATED_PROPERTY_DESCRIPTIONS]', property_docstring)
305
+ # We can't be sure the docstrings are present, as it might be compiled without docstrings.
306
+ if Bits.__doc__ is not None:
307
+ Bits.__doc__ = Bits.__doc__.replace('[GENERATED_PROPERTY_DESCRIPTIONS]', property_docstring)
308
+ if BitArray.__doc__ is not None:
309
+ BitArray.__doc__ = BitArray.__doc__.replace('[GENERATED_PROPERTY_DESCRIPTIONS]', property_docstring)
310
+ if ConstBitStream.__doc__ is not None:
311
+ ConstBitStream.__doc__ = ConstBitStream.__doc__.replace('[GENERATED_PROPERTY_DESCRIPTIONS]', property_docstring)
312
+ if BitStream.__doc__ is not None:
313
+ BitStream.__doc__ = BitStream.__doc__.replace('[GENERATED_PROPERTY_DESCRIPTIONS]', property_docstring)
308
314
 
309
315
 
310
316
  __all__ = ['ConstBitStream', 'BitStream', 'BitArray', 'Array',
@@ -540,8 +540,10 @@ class Array:
540
540
  def _apply_op_between_arrays(self, op, other: Array, is_comparison: bool = False) -> Array:
541
541
  if len(self) != len(other):
542
542
  msg = f"Cannot operate element-wise on Arrays with different lengths ({len(self)} and {len(other)})."
543
- if op == operator.add or op == operator.iadd:
544
- msg += " Use extend() if you want to concatenate Arrays."
543
+ if op in [operator.add, operator.iadd]:
544
+ msg += " Use extend() method to concatenate Arrays."
545
+ if op in [operator.eq, operator.ne]:
546
+ msg += " Use equals() method to compare Arrays for a single boolean result."
545
547
  raise ValueError(msg)
546
548
  if is_comparison:
547
549
  new_type = dtype_register.get_dtype('bool', 1)
@@ -42,6 +42,7 @@ class BitArray(Bits):
42
42
  endswith() -- Return whether the bitstring ends with a sub-string.
43
43
  find() -- Find a sub-bitstring in the current bitstring.
44
44
  findall() -- Find all occurrences of a sub-bitstring in the current bitstring.
45
+ fromstring() -- Create a bitstring from a formatted string.
45
46
  join() -- Join bitstrings together using current bitstring.
46
47
  pp() -- Pretty print the bitstring.
47
48
  rfind() -- Seek backwards to find a sub-bitstring.
@@ -44,6 +44,7 @@ class Bits:
44
44
  endswith() -- Return whether the bitstring ends with a sub-string.
45
45
  find() -- Find a sub-bitstring in the current bitstring.
46
46
  findall() -- Find all occurrences of a sub-bitstring in the current bitstring.
47
+ fromstring() -- Create a bitstring from a formatted string.
47
48
  join() -- Join bitstrings together using current bitstring.
48
49
  pp() -- Pretty print the bitstring.
49
50
  rfind() -- Seek backwards to find a sub-bitstring.
@@ -610,10 +611,9 @@ class Bits:
610
611
  def _setmxint(self, f: float) -> None:
611
612
  self._bitstore = bitstore_helpers.mxint2bitstore(f)
612
613
 
613
- def _setbytes(self, data: Union[bytearray, bytes], length:None = None) -> None:
614
+ def _setbytes(self, data: Union[bytearray, bytes, List], length:None = None) -> None:
614
615
  """Set the data from a bytes or bytearray object."""
615
- self._bitstore = BitStore.frombytes(data)
616
- return
616
+ self._bitstore = BitStore.frombytes(bytes(data))
617
617
 
618
618
  def _setbytes_with_truncation(self, data: Union[bytearray, bytes], length: Optional[int] = None, offset: Optional[int] = None) -> None:
619
619
  """Set the data from a bytes or bytearray object, with optional offset and length truncations."""
@@ -1588,14 +1588,6 @@ class Bits:
1588
1588
  count = self._bitstore.count(1)
1589
1589
  return count if value else len(self) - count
1590
1590
 
1591
- @staticmethod
1592
- def _chars_in_token(fmt:str) -> Tuple[str, Optional[int]]:
1593
- dtype = Dtype(fmt)
1594
- bpc = Bits._bits_per_char(dtype.name)
1595
- if dtype.bitlength is not None and dtype.bitlength % bpc != 0:
1596
- raise ValueError(f"Bits per group must be a multiple of {bpc} for '{fmt}' format.")
1597
- return dtype.name, dtype.bitlength
1598
-
1599
1591
  @staticmethod
1600
1592
  def _format_bits(bits: Bits, bits_per_group: int, sep: str, dtype: Dtype,
1601
1593
  colour_start: str, colour_end: str, width: Optional[int]=None) -> Tuple[str, int]:
@@ -25,6 +25,7 @@ class ConstBitStream(Bits):
25
25
  endswith() -- Return whether the bitstring ends with a sub-string.
26
26
  find() -- Find a sub-bitstring in the current bitstring.
27
27
  findall() -- Find all occurrences of a sub-bitstring in the current bitstring.
28
+ fromstring() -- Create a bitstring from a formatted string.
28
29
  join() -- Join bitstrings together using current bitstring.
29
30
  pp() -- Pretty print the bitstring.
30
31
  rfind() -- Seek backwards to find a sub-bitstring.
@@ -469,6 +470,14 @@ class ConstBitStream(Bits):
469
470
  x._bitstore.immutable = True
470
471
  return x
471
472
 
473
+ @overload
474
+ def __getitem__(self: TBits, key: slice, /) -> TBits:
475
+ ...
476
+
477
+ @overload
478
+ def __getitem__(self: TBits, key: int, /) -> bool:
479
+ ...
480
+
472
481
  def __getitem__(self: TBits, key: Union[slice, int], /) -> Union[TBits, bool]:
473
482
  """Return a new bitstring representing a slice of the current bitstring."""
474
483
  if isinstance(key, numbers.Integral):
@@ -509,6 +518,7 @@ class BitStream(ConstBitStream, bitstring.BitArray):
509
518
  endswith() -- Return whether the bitstring ends with a sub-string.
510
519
  find() -- Find a sub-bitstring in the current bitstring.
511
520
  findall() -- Find all occurrences of a sub-bitstring in the current bitstring.
521
+ fromstring() -- Create a bitstring from a formatted string.
512
522
  insert() -- Insert a bitstring.
513
523
  invert() -- Flip bit(s) between one and zero.
514
524
  join() -- Join bitstrings together using current bitstring.
@@ -155,7 +155,7 @@ class Dtype:
155
155
  x._bitlength *= x._bits_per_item
156
156
  x._set_fn_needs_length = definition.set_fn_needs_length
157
157
  x._variable_length = definition.variable_length
158
- if x._variable_length or len(dtype_register.names[x._name].allowed_lengths) == 1:
158
+ if x._variable_length or dtype_register.names[x._name].allowed_lengths.only_one_value():
159
159
  x._read_fn = definition.read_fn
160
160
  else:
161
161
  x._read_fn = functools.partial(definition.read_fn, length=x._bitlength)
@@ -191,12 +191,12 @@ class Dtype:
191
191
  def __str__(self) -> str:
192
192
  if self._scale is not None:
193
193
  return self.__repr__()
194
- hide_length = self._variable_length or len(dtype_register.names[self._name].allowed_lengths) == 1 or self._length is None
194
+ hide_length = self._variable_length or dtype_register.names[self._name].allowed_lengths.only_one_value() or self._length is None
195
195
  length_str = '' if hide_length else str(self._length)
196
196
  return f"{self._name}{length_str}"
197
197
 
198
198
  def __repr__(self) -> str:
199
- hide_length = self._variable_length or len(dtype_register.names[self._name].allowed_lengths) == 1 or self._length is None
199
+ hide_length = self._variable_length or dtype_register.names[self._name].allowed_lengths.only_one_value() or self._length is None
200
200
  length_str = '' if hide_length else ', ' + str(self._length)
201
201
  if self._scale is None:
202
202
  scale_str = ''
@@ -227,21 +227,24 @@ class AllowedLengths:
227
227
  for i in range(1, len(value) - 1):
228
228
  if value[i] - value[i - 1] != step:
229
229
  raise ValueError(f"Allowed length tuples must be equally spaced when final element is Ellipsis, but got {value}.")
230
- infinity = 1_000_000_000_000_000 # Rough approximation.
231
- self.value = range(value[0], infinity, step)
230
+ self.values = (value[0], value[1], Ellipsis)
232
231
  else:
233
- self.value = value
232
+ self.values = value
234
233
 
235
234
  def __str__(self) -> str:
236
- if isinstance(self.value, range):
237
- return f"({self.value[0]}, {self.value[1]}, ...)"
238
- return str(self.value)
235
+ if self.values and self.values[-1] is Ellipsis:
236
+ return f"({self.values[0]}, {self.values[1]}, ...)"
237
+ return str(self.values)
239
238
 
240
239
  def __contains__(self, other: Any) -> bool:
241
- return other in self.value
240
+ if not self.values:
241
+ return True
242
+ if self.values[-1] is Ellipsis:
243
+ return (other - self.values[0]) % (self.values[1] - self.values[0]) == 0
244
+ return other in self.values
242
245
 
243
- def __len__(self) -> int:
244
- return len(self.value)
246
+ def only_one_value(self) -> bool:
247
+ return self.values and len(self.values) == 1
245
248
 
246
249
 
247
250
  class DtypeDefinition:
@@ -275,8 +278,8 @@ class DtypeDefinition:
275
278
  if self.allowed_lengths:
276
279
  def allowed_length_checked_get_fn(bs):
277
280
  if len(bs) not in self.allowed_lengths:
278
- if len(self.allowed_lengths) == 1:
279
- raise bitstring.InterpretError(f"'{self.name}' dtypes must have a length of {self.allowed_lengths.value[0]}, but received a length of {len(bs)}.")
281
+ if self.allowed_lengths.only_one_value():
282
+ raise bitstring.InterpretError(f"'{self.name}' dtypes must have a length of {self.allowed_lengths.values[0]}, but received a length of {len(bs)}.")
280
283
  else:
281
284
  raise bitstring.InterpretError(f"'{self.name}' dtypes must have a length in {self.allowed_lengths}, but received a length of {len(bs)}.")
282
285
  return get_fn(bs)
@@ -286,9 +289,9 @@ class DtypeDefinition:
286
289
 
287
290
  # Create a reading function from the get_fn.
288
291
  if not self.variable_length:
289
- if len(self.allowed_lengths) == 1:
292
+ if self.allowed_lengths.only_one_value():
290
293
  def read_fn(bs, start):
291
- return self.get_fn(bs[start:start + self.allowed_lengths.value[0]])
294
+ return self.get_fn(bs[start:start + self.allowed_lengths.values[0]])
292
295
  else:
293
296
  def read_fn(bs, start, length):
294
297
  return self.get_fn(bs[start:start + length])
@@ -314,12 +317,12 @@ class DtypeDefinition:
314
317
  def get_dtype(self, length: Optional[int] = None, scale: Union[None, float, int] = None) -> Dtype:
315
318
  if self.allowed_lengths:
316
319
  if length is None:
317
- if len(self.allowed_lengths) == 1:
318
- length = self.allowed_lengths.value[0]
320
+ if self.allowed_lengths.only_one_value():
321
+ length = self.allowed_lengths.values[0]
319
322
  else:
320
323
  if length not in self.allowed_lengths:
321
- if len(self.allowed_lengths) == 1:
322
- raise ValueError(f"A length of {length} was supplied for the '{self.name}' dtype, but its only allowed length is {self.allowed_lengths.value[0]}.")
324
+ if self.allowed_lengths.only_one_value():
325
+ raise ValueError(f"A length of {length} was supplied for the '{self.name}' dtype, but its only allowed length is {self.allowed_lengths.values[0]}.")
323
326
  else:
324
327
  raise ValueError(f"A length of {length} was supplied for the '{self.name}' dtype which is not one of its possible lengths (must be one of {self.allowed_lengths}).")
325
328
  if length is None:
@@ -143,6 +143,8 @@ def preprocess_tokens(fmt: str) -> List[str]:
143
143
  final_tokens = []
144
144
 
145
145
  for meta_token in meta_tokens:
146
+ if meta_token == '':
147
+ continue
146
148
  # Extract factor and actual token if a multiplicative factor exists
147
149
  factor = 1
148
150
  if m := MULTIPLICATIVE_RE.match(meta_token):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: bitstring
3
- Version: 4.2.0b2
3
+ Version: 4.2.1
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
@@ -43,18 +43,16 @@ It has been actively maintained since 2006.
43
43
 
44
44
  News
45
45
  ----
46
- **March 2024**: bitstring 4.2.0b2 released. This is the final beta release before 4.2.
47
-
48
- Install the beta with `pip install bitstring==4.2.0b2`, or use `pip install bitstring` for the latest stable version.
49
-
50
- New in 4.2:
46
+ **April 2024**: bitstring 4.2.1 released.
47
+
48
+ New in version 4.2:
51
49
 
52
50
  * Dropped support for Python 3.7. Minimum version is now 3.8.
53
51
  * A new `Dtype` class can be optionally used to specify types.
54
52
  * The `bitstring.options` object is now the preferred method for changing module options.
55
53
  * New `fromstring` method as another way to create bitstrings from formatted strings.
56
54
  * More types can now be pretty printed.
57
- * A range of 8-bit, 6-bit and even 4-bit float formats added (beta):
55
+ * A range of 8-bit, 6-bit and even 4-bit floating point formats added (beta):
58
56
  * Performance improvements.
59
57
 
60
58
  See the [release notes](https://github.com/scott-griffiths/bitstring/blob/main/release_notes.txt) for details. Please let me know if you encounter any problems.
@@ -81,7 +79,7 @@ Some starting points are given below:
81
79
  * [Quick Reference](https://bitstring.readthedocs.io/en/stable/quick_reference.html)
82
80
  * [Full Reference](https://bitstring.readthedocs.io/en/stable/reference.html)
83
81
 
84
- You can also try out the interactive walkthrough notebook on [binder](https://mybinder.org/v2/gh/scott-griffiths/bitstring/main?labpath=doc%2Fwalkthrough.ipynb).
82
+ There is also an introductory walkthrough notebook on [binder](https://mybinder.org/v2/gh/scott-griffiths/bitstring/main?labpath=doc%2Fwalkthrough.ipynb).
85
83
 
86
84
  Release Notes
87
85
  -------------
@@ -146,12 +144,4 @@ Examples
146
144
 
147
145
 
148
146
 
149
- Credits
150
- -------
151
-
152
- Created in 2006 to help with ad hoc parsing and creation of compressed video files.
153
- Maintained and expanded ever since as it became unexpectedly popular.
154
- Thanks to all those who have contributed ideas and code (and bug reports) over the years.
155
-
156
-
157
147
  <sub>Copyright (c) 2006 - 2024 Scott Griffiths</sub>
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "bitstring"
7
- version = "4.2.0b2"
7
+ version = "4.2.1"
8
8
  authors = [
9
9
  { name="Scott Griffiths", email="dr.scottgriffiths@gmail.com" },
10
10
  ]
@@ -3,11 +3,21 @@ bitstring module version history
3
3
  --------------------------------
4
4
 
5
5
  -------------------------
6
- March 2024: version 4.2.0
6
+ April 2024: version 4.2.1
7
+ -------------------------
8
+ Fixing a few regressions introduced in 4.2.0.
9
+
10
+ * Module crashes on import with 32-bit Python. Bug #317.
11
+ * Lists of integers not converted to bytes when using the bytes constructor. Bug #318.
12
+ * Empty comma separated tokens not handled correctly. Bug #319.
13
+ * Crash on import when docstrings not present due to optimize flag. Bug #321.
14
+
15
+ -------------------------
16
+ April 2024: version 4.2.0
7
17
  -------------------------
8
18
 
9
19
  This release contains a fairly large refactor of how different types are managed. This
10
- shouldn't affect the end user, and the main noticable change should be the new Dtype
20
+ shouldn't affect the end user, and the main noticeable change should be the new Dtype
11
21
  class, which is optional to use.
12
22
 
13
23
  Support for 8-bit and smaller floats has been reworked and expanded. These are still
@@ -25,11 +35,23 @@ Backwardly incompatible changes:
25
35
  Other changes:
26
36
 
27
37
  * The Array class is no longer 'beta'.
38
+
28
39
  * A new Dtype class can be optionally used to specify types.
40
+
29
41
  * The bitstring.options object is now the preferred method for changing module options.
42
+ The `bitstring.lsb0` and `bitstring.bytealigned` variables are now deprecated, use
43
+ `bitstring.options.lsb0` and `bitstring.options.bytealigned` instead.
44
+
30
45
  * New fromstring method as another way to create bitstrings from formatted strings.
31
- * More types can now be pretty printed.
46
+ Instead of relying on the `auto` parameter you can now optionally use `fromstring`.
47
+ >>> s1 = BitArray('u24=1000') # This is still fine
48
+ >>> s2 = BitArray.fromstring('u24=1000') # This may be clearer and more efficient.
49
+
50
+ * More types can now be pretty printed. For example integer and float formats can be used.
51
+ >>> s.pp('u15, bin')
52
+
32
53
  * Pretty printing is now prettier - optional terminal colours added.
54
+
33
55
  * A range of 8-bit, 6-bit and even 4-bit float formats added (beta):
34
56
  p3binary8: IEEE 8-bit floating point with 3 bit precision.
35
57
  p4binary8: IEEE 8-bit floating point with 4 bit precision.
@@ -40,8 +62,8 @@ Other changes:
40
62
  e2m1mxfp: OCP 4-bit floating point with 2 bit precision.
41
63
  e8m0mxfp: OCP 8-bit unsigned floating point designed to scale the other formats.
42
64
  mxint: OCP 8-bit floating point that is a scaled integer representation.
43
- * Performance improvements.
44
65
 
66
+ * Performance improvements.
45
67
 
46
68
  ----------------------------
47
69
  November 2023: version 4.1.4
@@ -89,7 +111,7 @@ A maintenance release, with some changes to the Array class which is still in 'b
89
111
  August 2023: version 4.1.0 released
90
112
  -----------------------------------
91
113
 
92
- This has turned into a suprisingly big release, with a major refactor and a brand new
114
+ This has turned into a surprisingly big release, with a major refactor and a brand new
93
115
  class (the first for 12 years!) There are also a couple of small possibly breaking changes
94
116
  detailed below, in particular 'auto' initialising bitstrings from integers is now disallowed.
95
117
 
@@ -144,7 +166,7 @@ Other changes:
144
166
  >>> a.float8_143
145
167
  16.0
146
168
 
147
- * Auto initialistion from ints has been removed and now raises a TypeError. Creating a
169
+ * Auto initialization from ints has been removed and now raises a TypeError. Creating a
148
170
  bitstring from an int still creates a zeroed bitstring of that length but ints won't
149
171
  be promoted to bitstrings as that has been a constant source of errors and confusion.
150
172
 
@@ -977,3 +977,16 @@ class TestNumpy:
977
977
  def test_creation(self):
978
978
  a = BitArray(np.longlong(12))
979
979
  assert a.hex == '000'
980
+
981
+
982
+ def test_bytes_from_list():
983
+ s = Bits(bytes=[1, 2])
984
+ assert s == '0x0102'
985
+ s = Bits(bytes=bytearray([1, 2]))
986
+ assert s == '0x0102'
987
+ s = BitArray(bytes=[1, 2])
988
+ assert s == '0x0102'
989
+ s = BitArray(bytes=bytearray([1, 2]))
990
+ assert s == '0x0102'
991
+ s.bytes = [10, 20]
992
+ assert s == '0x0a14'
@@ -4170,3 +4170,9 @@ class TestCacheingIssues:
4170
4170
  y = BitStream('0xdeadbeef002')
4171
4171
  with pytest.raises(bitstring.CreationError):
4172
4172
  x = BitStream('0xdeadbeef002', length=16)
4173
+
4174
+
4175
+ def test_unpack_error():
4176
+ format_with_commas = ',bytes:2,,bytes:1,'
4177
+ dp = BitStream(hex='010203').unpack(fmt=format_with_commas)
4178
+ assert dp == [b'\x01\x02', b'\x03']
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