dissect.cstruct 4.5.dev2__py3-none-any.whl → 4.5.dev4__py3-none-any.whl

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.
@@ -76,12 +76,12 @@ class EnumMetaType(EnumMeta, MetaType):
76
76
 
77
77
  __len__ = MetaType.__len__
78
78
 
79
- if not PY_312:
80
- # Backport __contains__ from CPython 3.12
81
- def __contains__(cls, value: Any) -> bool:
82
- if isinstance(value, cls):
83
- return True
84
- return value in cls._value2member_map_
79
+ def __contains__(cls, value: Any) -> bool:
80
+ # We used to let stdlib enum handle `__contains__``` but this commit is incompatible with our API:
81
+ # https://github.com/python/cpython/commit/8a9aee71268c77867d3cc96d43cbbdcbe8c0e1e8
82
+ if isinstance(value, cls):
83
+ return True
84
+ return value in cls._value2member_map_
85
85
 
86
86
  def _read(cls, stream: BinaryIO, context: dict[str, Any] | None = None) -> Self:
87
87
  return cls(cls.type._read(stream, context))
@@ -673,7 +673,9 @@ def _make_structure__init__(fields: list[str]) -> str:
673
673
  fields: List of field names.
674
674
  """
675
675
  field_args = ", ".join(f"{field} = None" for field in fields)
676
- field_init = "\n".join(f" self.{name} = {name} if {name} is not None else {i}" for i, name in enumerate(fields))
676
+ field_init = "\n".join(
677
+ f" self.{name} = {name} if {name} is not None else _{i}_default" for i, name in enumerate(fields)
678
+ )
677
679
 
678
680
  code = f"def __init__(self{', ' + field_args or ''}):\n"
679
681
  return code + (field_init or " pass")
@@ -688,7 +690,8 @@ def _make_union__init__(fields: list[str]) -> str:
688
690
  """
689
691
  field_args = ", ".join(f"{field} = None" for field in fields)
690
692
  field_init = "\n".join(
691
- f" object.__setattr__(self, '{name}', {name} if {name} is not None else {i})" for i, name in enumerate(fields)
693
+ f" object.__setattr__(self, '{name}', {name} if {name} is not None else _{i}_default)"
694
+ for i, name in enumerate(fields)
692
695
  )
693
696
 
694
697
  code = f"def __init__(self{', ' + field_args or ''}):\n"
@@ -780,11 +783,10 @@ def _generate_structure__init__(fields: list[Field]) -> FunctionType:
780
783
  template: FunctionType = _make_structure__init__(len(field_names))
781
784
  return type(template)(
782
785
  template.__code__.replace(
783
- co_consts=(None, *[field.type.__default__() for field in fields]),
784
- co_names=(*field_names,),
786
+ co_names=tuple(chain.from_iterable(zip((f"__{name}_default__" for name in field_names), field_names))),
785
787
  co_varnames=("self", *field_names),
786
788
  ),
787
- template.__globals__,
789
+ template.__globals__ | {f"__{field._name}_default__": field.type.__default__() for field in fields},
788
790
  argdefs=template.__defaults__,
789
791
  )
790
792
 
@@ -800,13 +802,11 @@ def _generate_union__init__(fields: list[Field]) -> FunctionType:
800
802
  template: FunctionType = _make_union__init__(len(field_names))
801
803
  return type(template)(
802
804
  template.__code__.replace(
803
- co_consts=(
804
- None,
805
- *sum([(field._name, field.type.__default__()) for field in fields], ()),
806
- ),
805
+ co_consts=(None, *field_names),
806
+ co_names=("object", "__setattr__", *(f"__{name}_default__" for name in field_names)),
807
807
  co_varnames=("self", *field_names),
808
808
  ),
809
- template.__globals__,
809
+ template.__globals__ | {f"__{field._name}_default__": field.type.__default__() for field in fields},
810
810
  argdefs=template.__defaults__,
811
811
  )
812
812
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: dissect.cstruct
3
- Version: 4.5.dev2
3
+ Version: 4.5.dev4
4
4
  Summary: A Dissect module implementing a parser for C-like structures: structure parsing in Python made easy
5
5
  Author-email: Dissect Team <dissect@fox-it.com>
6
6
  License: Apache License 2.0
@@ -11,19 +11,19 @@ dissect/cstruct/tools/stubgen.py,sha256=x-jlIet9mzONfl4sbaz6fTgEJ-FXg50HqdLhFKCE
11
11
  dissect/cstruct/types/__init__.py,sha256=e9Z6BhhAPquT4MJoK3i_SjC9AgIGWFH_-tAVFCFBiqE,847
12
12
  dissect/cstruct/types/base.py,sha256=UFDolAxpVW1W9JoVlykEf96wBzt_suXvuYy08iB54Sw,9677
13
13
  dissect/cstruct/types/char.py,sha256=9XYCjCF0D_5o3EYnmIcjev-5GI2NzxOhd1ct1xF6SAM,2457
14
- dissect/cstruct/types/enum.py,sha256=9mzlIeHYLHOdNtTmiPgGNvGBYe71HeDX5qQDspX5O80,7409
14
+ dissect/cstruct/types/enum.py,sha256=uSAayOYfEwfDZrl1tFGZteFceqdTbW_2GTtDyzuiG3M,7523
15
15
  dissect/cstruct/types/flag.py,sha256=7xxQjFEDPHSQOxBHgcc75WzPiAxflOquwr7Z7c3erLE,2347
16
16
  dissect/cstruct/types/int.py,sha256=MGsdUxJt-lj3nl9wzAgGX8cb_vJOtGLiCHwYZs1j_IA,1156
17
17
  dissect/cstruct/types/leb128.py,sha256=kDmsWGXX6vr1bm4uJcilsrQ7JABdQRio16rBZV21pno,2243
18
18
  dissect/cstruct/types/packed.py,sha256=tpZpb8tiSMXr1np6p0-nZqT4sY7zieO-4E16lmMmqJA,2128
19
19
  dissect/cstruct/types/pointer.py,sha256=PqeJOoNBUfMd5uO2kpF6OHeW7Q6R1N1W1V4q1MakN4I,3912
20
- dissect/cstruct/types/structure.py,sha256=6OBxXr7hMYhufe4GvHkBHpME1fvJQYlfbFxchouHIIc,29814
20
+ dissect/cstruct/types/structure.py,sha256=qzgy0bfU51pJDtKiDUY8NsmRdT-eZFVGp9r-TAatI4k,30003
21
21
  dissect/cstruct/types/void.py,sha256=VL2qJ86rq-oBUnkBprNsPPgPGgHV6UENRJTQ2jw0rxc,669
22
22
  dissect/cstruct/types/wchar.py,sha256=N9Y_XX2_hZEe2DwepJjxsB6xuRJ6zINRalcUofR59kY,2608
23
- dissect_cstruct-4.5.dev2.dist-info/licenses/COPYRIGHT,sha256=H-18RXfshdH9AdHwW2eO1Xa-5s6tY5eipHh5c0whDu4,316
24
- dissect_cstruct-4.5.dev2.dist-info/licenses/LICENSE,sha256=PhUqiw6jAh2KbBdVRPBq_hfAvfcTBin7nZ3CK7NQbTM,11341
25
- dissect_cstruct-4.5.dev2.dist-info/METADATA,sha256=jJ60UIxIC5oHEK1G3inE5hDUoBhknSdgai5UwoidrI4,8649
26
- dissect_cstruct-4.5.dev2.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
27
- dissect_cstruct-4.5.dev2.dist-info/entry_points.txt,sha256=z53zqZqwD2OLrAkRwrP4wTeiU9CQe7xrMly0T2c0_wQ,71
28
- dissect_cstruct-4.5.dev2.dist-info/top_level.txt,sha256=Mn-CQzEYsAbkxrUI0TnplHuXnGVKzxpDw_po_sXpvv4,8
29
- dissect_cstruct-4.5.dev2.dist-info/RECORD,,
23
+ dissect_cstruct-4.5.dev4.dist-info/licenses/COPYRIGHT,sha256=H-18RXfshdH9AdHwW2eO1Xa-5s6tY5eipHh5c0whDu4,316
24
+ dissect_cstruct-4.5.dev4.dist-info/licenses/LICENSE,sha256=PhUqiw6jAh2KbBdVRPBq_hfAvfcTBin7nZ3CK7NQbTM,11341
25
+ dissect_cstruct-4.5.dev4.dist-info/METADATA,sha256=uqcf_vWsuCBrCP2MJMGkOjjp0DUU_mG2navRbR-WCT0,8649
26
+ dissect_cstruct-4.5.dev4.dist-info/WHEEL,sha256=ooBFpIzZCPdw3uqIQsOo4qqbA4ZRPxHnOH7peeONza0,91
27
+ dissect_cstruct-4.5.dev4.dist-info/entry_points.txt,sha256=z53zqZqwD2OLrAkRwrP4wTeiU9CQe7xrMly0T2c0_wQ,71
28
+ dissect_cstruct-4.5.dev4.dist-info/top_level.txt,sha256=Mn-CQzEYsAbkxrUI0TnplHuXnGVKzxpDw_po_sXpvv4,8
29
+ dissect_cstruct-4.5.dev4.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (78.1.0)
2
+ Generator: setuptools (80.0.1)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5