winpnp 0.0.2__py3-none-any.whl → 0.1.0__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.
@@ -4,6 +4,7 @@ from winpnp.properties import kinds
4
4
  from winpnp.properties.pnp_property import PnpPropertyKey
5
5
 
6
6
  from . import (
7
+ bluetooth,
7
8
  dev_query,
8
9
  device,
9
10
  device_class,
@@ -15,6 +15,7 @@ class PnpPropertyType(Generic[T]):
15
15
  """
16
16
 
17
17
  _DERIVED_DATA: ClassVar[dict[int, tuple[str, Callable[[bytes], Any]]]] = {}
18
+ _NAME_TO_ID: ClassVar[dict[str, int]] = {}
18
19
 
19
20
  type_id: int
20
21
  name: Optional[str] = field(compare=False)
@@ -48,6 +49,7 @@ class PnpPropertyType(Generic[T]):
48
49
  )
49
50
 
50
51
  PnpPropertyType._DERIVED_DATA[kind.type_id] = (kind.name, kind._decoder)
52
+ PnpPropertyType._NAME_TO_ID[kind.name] = kind.type_id
51
53
 
52
54
  @staticmethod
53
55
  def register_new(
@@ -62,6 +64,14 @@ class PnpPropertyType(Generic[T]):
62
64
  PnpPropertyType.register(kind)
63
65
  return kind
64
66
 
67
+ @staticmethod
68
+ def from_name(name: str) -> Optional["PnpPropertyType[U]"]:
69
+ type_id = PnpPropertyType._NAME_TO_ID.get(name)
70
+ if type_id is None:
71
+ return None
72
+
73
+ return PnpPropertyType(type_id)
74
+
65
75
  def decode(self, data: bytes) -> T:
66
76
  """
67
77
  Decodes raw bytes to the actual python type that this `PnpPropertyType` represents.
@@ -69,13 +79,16 @@ class PnpPropertyType(Generic[T]):
69
79
  return self._decoder(data)
70
80
 
71
81
 
72
- @dataclass(init=False)
82
+ @dataclass(init=False, frozen=True)
73
83
  class PnpPropertyKey(Generic[T]):
74
84
  """
75
85
  A key that specifies a PnP property. This is an abstraction over the Windows DEVPROPKEY struct. Can be used as key for `__getitem__` of various winpnp classes.
76
86
  """
77
87
 
78
- _NAMES: ClassVar[dict[tuple[UUID, int], str]] = {}
88
+ _DERIVED_DATA: ClassVar[
89
+ dict[tuple[UUID, int], tuple[str, Optional[tuple[PnpPropertyType[Any], ...]]]]
90
+ ] = {}
91
+ _NAME_TO_ID: ClassVar[dict[str, tuple[UUID, int]]] = {}
79
92
 
80
93
  category: UUID
81
94
  property_id: int
@@ -89,15 +102,25 @@ class PnpPropertyKey(Generic[T]):
89
102
  name: Optional[str] = None,
90
103
  allowed_types: Optional[Iterable[PnpPropertyType[T]]] = None,
91
104
  ) -> None:
92
- self.category = category
93
- self.property_id = property_id
94
- self.name = (
95
- name if name is not None else self._NAMES.get((category, property_id))
105
+ # Intentionally not setting allowed_types from derived data to allow creating a PnpPropertyKey with registered id but without type limitations
106
+ derived_name, _ = self._DERIVED_DATA.get((category, property_id), (None, None))
107
+
108
+ # Using object.__setattr__ because the class is frozen
109
+ object.__setattr__(self, "category", category)
110
+ object.__setattr__(self, "property_id", property_id)
111
+ object.__setattr__(
112
+ self,
113
+ "name",
114
+ name if name is not None else derived_name,
96
115
  )
97
- self.allowed_types = (
98
- {kind.type_id: kind for kind in allowed_types}
99
- if allowed_types is not None
100
- else None
116
+ object.__setattr__(
117
+ self,
118
+ "allowed_types",
119
+ (
120
+ {kind.type_id: kind for kind in allowed_types}
121
+ if allowed_types is not None
122
+ else None
123
+ ),
101
124
  )
102
125
 
103
126
  @staticmethod
@@ -109,12 +132,17 @@ class PnpPropertyKey(Generic[T]):
109
132
  raise ValueError(f"Cannot register {repr(key)} because it is unnamed.")
110
133
 
111
134
  _id = (key.category, key.property_id)
112
- if _id in PnpPropertyKey._NAMES:
135
+ if _id in PnpPropertyKey._DERIVED_DATA:
113
136
  raise ValueError(
114
- f"Cannot register {repr(key)} because its (category, property_id) pair is already registered with name {repr(PnpPropertyKey._NAMES[_id])}"
137
+ f"Cannot register {repr(key)} because its (category, property_id) pair is already registered with name {repr(PnpPropertyKey._DERIVED_DATA[_id][0])}"
115
138
  )
116
139
 
117
- PnpPropertyKey._NAMES[_id] = key.name
140
+ allowed_types = (
141
+ tuple(key.allowed_types.values()) if key.allowed_types is not None else None
142
+ )
143
+
144
+ PnpPropertyKey._DERIVED_DATA[_id] = (key.name, allowed_types)
145
+ PnpPropertyKey._NAME_TO_ID[key.name] = _id
118
146
 
119
147
  @staticmethod
120
148
  def register_new(
@@ -130,6 +158,15 @@ class PnpPropertyKey(Generic[T]):
130
158
  PnpPropertyKey.register(key)
131
159
  return key
132
160
 
161
+ @staticmethod
162
+ def from_name(name: str) -> Optional["PnpPropertyKey[U]"]:
163
+ _id = PnpPropertyKey._NAME_TO_ID.get(name)
164
+ if _id is None:
165
+ return None
166
+
167
+ _, allowed_types = PnpPropertyKey._DERIVED_DATA.get(_id, (None, None))
168
+ return PnpPropertyKey(*_id, name, allowed_types)
169
+
133
170
 
134
171
  @dataclass()
135
172
  class PnpProperty(Generic[T]):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: winpnp
3
- Version: 0.0.2
3
+ Version: 0.1.0
4
4
  Summary: A package for interacting with Windows Plug and Play (PnP) entities
5
5
  Project-URL: Homepage, https://github.com/SuperPudding98/winpnp
6
6
  Project-URL: Issues, https://github.com/SuperPudding98/winpnp/issues
@@ -7,8 +7,8 @@ winpnp/info/setup_class.py,sha256=PaXmW4m2ycSFH6i88Wcxgdhr7y-33LuSDU_9V1iM0ZQ,37
7
7
  winpnp/properties/__init__.py,sha256=oqncCBWwr5EBZm2lHkRmds0fmWZ7G8stC0U_AS87JqY,41
8
8
  winpnp/properties/decoding.py,sha256=0a8kM24Q4AoJ6GvHF0GXitS5OHa5q-VX_TeXtQPF5ek,4149
9
9
  winpnp/properties/kinds.py,sha256=U6v-4kNeQabozUhsx39jQARO11S6sapdXxglcije6Jc,9314
10
- winpnp/properties/pnp_property.py,sha256=nfHAhh4fxqFFDLkO2QIWlHZObVYxPc98cWwx7KFBjeo,4746
11
- winpnp/properties/keys/__init__.py,sha256=UFNASfjn-h9isFvQAeXBeHa9IwIPuKSZPovac6WEyXY,409
10
+ winpnp/properties/pnp_property.py,sha256=5mtElAYkLMcaPOtEHoCHcTB4tjvYO9xIdNSa3QXSHGs,6254
11
+ winpnp/properties/keys/__init__.py,sha256=368jCeJ3XGn7iMr5KfWT7cTyUDNcXRO3bfqktVqBMyg,425
12
12
  winpnp/properties/keys/bluetooth.py,sha256=SRhz3sks6EESA01LCX4O4BQwoIm33_PyUlUSl1izJBw,2140
13
13
  winpnp/properties/keys/dev_query.py,sha256=kwmXcUb7bEbhjXm4yTnL8lWJxcBej0ZUvjMmHB_Fj_0,280
14
14
  winpnp/properties/keys/device.py,sha256=h8pjY7-PwpkY1Up_BhjPrXxygm5UFyMp-tvd_R0DoFY,18384
@@ -17,7 +17,7 @@ winpnp/properties/keys/device_container.py,sha256=1cxKFYiRfFTQ6d_OjL8tr3nIuwuCHV
17
17
  winpnp/properties/keys/device_interface.py,sha256=Fjaj8fJdtYKgcLsnolHBN4LorC1BRbCsV0gkys1VHtk,1333
18
18
  winpnp/properties/keys/device_interface_class.py,sha256=ci80vR0Ue8lba5XBIqg-8VVa5CxvJNzJ9sVi4yr3JlU,462
19
19
  winpnp/properties/keys/driver_package.py,sha256=YXMOA7PjsDEyu92tT7ppUpoY31UCMrRQmUqmrOGQLzU,1076
20
- winpnp-0.0.2.dist-info/METADATA,sha256=3rRzqfyPngnLipvI2xBII8256VPK_5VPk2q6jxmJnos,1930
21
- winpnp-0.0.2.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
22
- winpnp-0.0.2.dist-info/licenses/LICENSE,sha256=kMhLdtRDEv5y1xkgn_gpWXxkNbjNeGdE0rIZoEWsx90,1070
23
- winpnp-0.0.2.dist-info/RECORD,,
20
+ winpnp-0.1.0.dist-info/METADATA,sha256=-qY-dsA9I6ABFYnUbGKz1_lULXFLsXBtrIPgWv_zuyw,1930
21
+ winpnp-0.1.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
22
+ winpnp-0.1.0.dist-info/licenses/LICENSE,sha256=kMhLdtRDEv5y1xkgn_gpWXxkNbjNeGdE0rIZoEWsx90,1070
23
+ winpnp-0.1.0.dist-info/RECORD,,
File without changes