@@ -28,7 +28,9 @@ def to_bytes_literal(seq: bytes) -> str:
28
28
return 'b"' + "" .join ("\\ x{:02x}" .format (v ) for v in seq ) + '"'
29
29
30
30
31
- def decode_data (data : bytes , * , key_encoding : str = "B" ) -> Dict [Any , Union [bytes , List [bytes ]]]:
31
+ def decode_data (
32
+ data : bytes , * , key_encoding : str = "B"
33
+ ) -> Dict [Any , Union [bytes , List [bytes ]]]:
32
34
"""Helper which decodes length encoded structures into a dictionary with the given key
33
35
encoding."""
34
36
i = 0
@@ -51,7 +53,9 @@ def decode_data(data: bytes, *, key_encoding: str = "B") -> Dict[Any, Union[byte
51
53
return data_dict
52
54
53
55
54
- def compute_length (data_dict : Dict [Any , Union [bytes , List [bytes ]]], * , key_encoding : str = "B" ) -> int :
56
+ def compute_length (
57
+ data_dict : Dict [Any , Union [bytes , List [bytes ]]], * , key_encoding : str = "B"
58
+ ) -> int :
55
59
"""Computes the length of the encoded data dictionary."""
56
60
value_size = 0
57
61
for value in data_dict .values ():
@@ -63,7 +67,9 @@ def compute_length(data_dict: Dict[Any, Union[bytes, List[bytes]]], *, key_encod
63
67
return len (data_dict ) + len (data_dict ) * struct .calcsize (key_encoding ) + value_size
64
68
65
69
66
- def encode_data (data_dict : Dict [Any , Union [bytes , List [bytes ]]], * , key_encoding : str = "B" ) -> bytes :
70
+ def encode_data (
71
+ data_dict : Dict [Any , Union [bytes , List [bytes ]]], * , key_encoding : str = "B"
72
+ ) -> bytes :
67
73
"""Helper which encodes dictionaries into length encoded structures with the given key
68
74
encoding."""
69
75
length = compute_length (data_dict , key_encoding = key_encoding )
@@ -92,7 +98,9 @@ class AdvertisingFlag:
92
98
def __init__ (self , bit_position : int ) -> None :
93
99
self ._bitmask = 1 << bit_position
94
100
95
- def __get__ (self , obj : Optional ["AdvertisingFlags" ], cls : Type ["AdvertisingFlags" ]) -> Union [bool , "AdvertisingFlag" ]:
101
+ def __get__ (
102
+ self , obj : Optional ["AdvertisingFlags" ], cls : Type ["AdvertisingFlags" ]
103
+ ) -> Union [bool , "AdvertisingFlag" ]:
96
104
if obj is None :
97
105
return self
98
106
return (obj .flags & self ._bitmask ) != 0
@@ -115,7 +123,9 @@ class AdvertisingFlags(AdvertisingDataField):
115
123
"""BR/EDR not supported."""
116
124
# BR/EDR flags not included here, since we don't support BR/EDR.
117
125
118
- def __init__ (self , advertisement : "Advertisement" , advertising_data_type : int ) -> None :
126
+ def __init__ (
127
+ self , advertisement : "Advertisement" , advertising_data_type : int
128
+ ) -> None :
119
129
self ._advertisement = advertisement
120
130
self ._adt = advertising_data_type
121
131
self .flags = 0
@@ -146,7 +156,9 @@ class String(AdvertisingDataField):
146
156
def __init__ (self , * , advertising_data_type : int ) -> None :
147
157
self ._adt = advertising_data_type
148
158
149
- def __get__ (self , obj : Optional ["Advertisement" ], cls : Type ["Advertisement" ]) -> Optional [Union [str , "String" ]]:
159
+ def __get__ (
160
+ self , obj : Optional ["Advertisement" ], cls : Type ["Advertisement" ]
161
+ ) -> Optional [Union [str , "String" ]]:
150
162
if obj is None :
151
163
return self
152
164
if self ._adt not in obj .data_dict :
@@ -164,7 +176,9 @@ def __init__(self, struct_format: str, *, advertising_data_type: int) -> None:
164
176
self ._format = struct_format
165
177
self ._adt = advertising_data_type
166
178
167
- def __get__ (self , obj : Optional ["Advertisement" ], cls : Type ["Advertisement" ]) -> Optional [Union [Any , "Struct" ]]:
179
+ def __get__ (
180
+ self , obj : Optional ["Advertisement" ], cls : Type ["Advertisement" ]
181
+ ) -> Optional [Union [Any , "Struct" ]]:
168
182
if obj is None :
169
183
return self
170
184
if self ._adt not in obj .data_dict :
@@ -178,13 +192,17 @@ def __set__(self, obj: "Advertisement", value: Any) -> None:
178
192
class LazyObjectField (AdvertisingDataField ):
179
193
"""Non-data descriptor useful for lazily binding a complex object to an advertisement object."""
180
194
181
- def __init__ (self , cls : Any , attribute_name : str , * , advertising_data_type : int , ** kwargs ) -> None :
195
+ def __init__ (
196
+ self , cls : Any , attribute_name : str , * , advertising_data_type : int , ** kwargs
197
+ ) -> None :
182
198
self ._cls = cls
183
199
self ._attribute_name = attribute_name
184
200
self ._adt = advertising_data_type
185
201
self ._kwargs = kwargs
186
202
187
- def __get__ (self , obj : Optional ["Advertisement" ], cls : Type ["Advertisement" ]) -> Any :
203
+ def __get__ (
204
+ self , obj : Optional ["Advertisement" ], cls : Type ["Advertisement" ]
205
+ ) -> Any :
188
206
if obj is None :
189
207
return self
190
208
# Return None if our object is immutable and the data is not present.
0 commit comments