Skip to content

Commit c2d61e2

Browse files
committed
reformat with yapf
1 parent 044e462 commit c2d61e2

29 files changed

Lines changed: 112 additions & 64 deletions

dbus_next/_private/constants.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,4 @@ class HeaderField(Enum):
1818
UNIX_FDS = 9
1919

2020

21-
HEADER_NAME_MAP = {
22-
field.value: field.name for field in HeaderField
23-
}
21+
HEADER_NAME_MAP = {field.value: field.name for field in HeaderField}

dbus_next/_private/marshaller.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44

55
class Marshaller:
6+
67
def __init__(self, signature, body):
78
self.signature_tree = SignatureTree._get(signature)
89
self.signature_tree.verify(body)

dbus_next/_private/unmarshaller.py

Lines changed: 30 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,8 @@
4747
HEADER_REPLY_SERIAL = HeaderField.REPLY_SERIAL.name
4848
HEADER_SENDER = HeaderField.SENDER.name
4949

50-
READER_TYPE = Dict[
51-
str,
52-
Tuple[
53-
Optional[Callable[["Unmarshaller", SignatureType], Any]],
54-
Optional[str],
55-
Optional[int],
56-
Optional[Struct],
57-
],
58-
]
50+
READER_TYPE = Dict[str, Tuple[Optional[Callable[["Unmarshaller", SignatureType], Any]],
51+
Optional[str], Optional[int], Optional[Struct], ], ]
5952

6053

6154
class MarshallerStreamEndError(Exception):
@@ -117,17 +110,14 @@ def read_sock(self, length: int) -> bytes:
117110

118111
try:
119112
msg, ancdata, *_ = self.sock.recvmsg(
120-
length, socket.CMSG_LEN(MAX_UNIX_FDS * unix_fd_list.itemsize)
121-
)
113+
length, socket.CMSG_LEN(MAX_UNIX_FDS * unix_fd_list.itemsize))
122114
except BlockingIOError:
123115
raise MarshallerStreamEndError()
124116

125117
for level, type_, data in ancdata:
126118
if not (level == socket.SOL_SOCKET and type_ == socket.SCM_RIGHTS):
127119
continue
128-
unix_fd_list.frombytes(
129-
data[: len(data) - (len(data) % unix_fd_list.itemsize)]
130-
)
120+
unix_fd_list.frombytes(data[:len(data) - (len(data) % unix_fd_list.itemsize)])
131121
self.unix_fds.extend(list(unix_fd_list))
132122

133123
return msg
@@ -187,9 +177,7 @@ def read_struct(self, type_: SignatureType):
187177

188178
def read_dict_entry(self, type_: SignatureType):
189179
self.offset += -self.offset & 7 # align 8
190-
return self.read_argument(type_.children[0]), self.read_argument(
191-
type_.children[1]
192-
)
180+
return self.read_argument(type_.children[0]), self.read_argument(type_.children[1])
193181

194182
def read_array(self, type_: SignatureType):
195183
self.offset += -self.offset & 3 # align 4 for the array
@@ -259,22 +247,14 @@ def _read_header(self):
259247

260248
if endian != LITTLE_ENDIAN and endian != BIG_ENDIAN:
261249
raise InvalidMessageError(
262-
f"Expecting endianness as the first byte, got {endian} from {buffer}"
263-
)
250+
f"Expecting endianness as the first byte, got {endian} from {buffer}")
264251
if protocol_version != PROTOCOL_VERSION:
265-
raise InvalidMessageError(
266-
f"got unknown protocol version: {protocol_version}"
267-
)
252+
raise InvalidMessageError(f"got unknown protocol version: {protocol_version}")
268253

269-
self.body_len, self.serial, self.header_len = UNPACK_LENGTHS[
270-
endian
271-
].unpack_from(buffer, 4)
272-
self.msg_len = (
273-
self.header_len + (-self.header_len & 7) + self.body_len
274-
) # align 8
275-
if (sys.byteorder == "little" and endian == LITTLE_ENDIAN) or (
276-
sys.byteorder == "big" and endian == BIG_ENDIAN
277-
):
254+
self.body_len, self.serial, self.header_len = UNPACK_LENGTHS[endian].unpack_from(buffer, 4)
255+
self.msg_len = (self.header_len + (-self.header_len & 7) + self.body_len) # align 8
256+
if (sys.byteorder == "little" and endian == LITTLE_ENDIAN) or (sys.byteorder == "big"
257+
and endian == BIG_ENDIAN):
278258
self.can_cast = True
279259
self.readers = self._readers_by_type[endian]
280260

@@ -317,18 +297,17 @@ def unmarshall(self):
317297
return None
318298
return self.message
319299

320-
_complex_parsers: Dict[
321-
str, Tuple[Callable[["Unmarshaller", SignatureType], Any], None, None, None]
322-
] = {
323-
"b": (read_boolean, None, None, None),
324-
"o": (read_string, None, None, None),
325-
"s": (read_string, None, None, None),
326-
"g": (read_signature, None, None, None),
327-
"a": (read_array, None, None, None),
328-
"(": (read_struct, None, None, None),
329-
"{": (read_dict_entry, None, None, None),
330-
"v": (read_variant, None, None, None),
331-
}
300+
_complex_parsers: Dict[str, Tuple[Callable[["Unmarshaller", SignatureType], Any], None, None,
301+
None]] = {
302+
"b": (read_boolean, None, None, None),
303+
"o": (read_string, None, None, None),
304+
"s": (read_string, None, None, None),
305+
"g": (read_signature, None, None, None),
306+
"a": (read_array, None, None, None),
307+
"(": (read_struct, None, None, None),
308+
"{": (read_dict_entry, None, None, None),
309+
"v": (read_variant, None, None, None),
310+
}
332311

333312
_ctype_by_endian: Dict[int, Dict[str, Tuple[None, str, int, Struct]]] = {
334313
endian: {
@@ -343,6 +322,12 @@ def unmarshall(self):
343322
}
344323

345324
_readers_by_type: Dict[int, READER_TYPE] = {
346-
BIG_ENDIAN: {**_ctype_by_endian[BIG_ENDIAN], **_complex_parsers},
347-
LITTLE_ENDIAN: {**_ctype_by_endian[LITTLE_ENDIAN], **_complex_parsers},
325+
BIG_ENDIAN: {
326+
**_ctype_by_endian[BIG_ENDIAN],
327+
**_complex_parsers
328+
},
329+
LITTLE_ENDIAN: {
330+
**_ctype_by_endian[LITTLE_ENDIAN],
331+
**_complex_parsers
332+
},
348333
}

dbus_next/_private/util.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ def parse_annotation(annotation: str) -> str:
101101
In this case, we must eval the result which we do only when given a string
102102
constant.
103103
'''
104+
104105
def raise_value_error():
105106
raise ValueError(f'service annotations must be a string constant (got {annotation})')
106107

dbus_next/aio/message_bus.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ def _future_set_result(fut, result):
2828

2929

3030
class _MessageWriter:
31+
3132
def __init__(self, bus):
3233
self.messages = Queue()
3334
self.negotiate_unix_fd = bus._negotiate_unix_fd
@@ -114,6 +115,7 @@ class MessageBus(BaseMessageBus):
114115
and receive messages.
115116
:vartype connected: bool
116117
"""
118+
117119
def __init__(self,
118120
bus_address: str = None,
119121
bus_type: BusType = BusType.SESSION,
@@ -346,6 +348,7 @@ def _make_method_handler(self, interface, method):
346348
return super()._make_method_handler(interface, method)
347349

348350
def handler(msg, send_reply):
351+
349352
def done(fut):
350353
with send_reply:
351354
result = fut.result()

dbus_next/aio/proxy_object.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,9 @@ class ProxyInterface(BaseProxyInterface):
7272
If the service returns an error for a DBus call, a :class:`DBusError
7373
<dbus_next.DBusError>` will be raised with information about the error.
7474
"""
75+
7576
def _add_method(self, intr_method):
77+
7678
async def method_fn(*args, flags=MessageFlag.NONE):
7779
input_body, unix_fds = replace_fds_with_idx(intr_method.in_signature, list(args))
7880

@@ -106,6 +108,7 @@ async def method_fn(*args, flags=MessageFlag.NONE):
106108
setattr(self, method_name, method_fn)
107109

108110
def _add_property(self, intr_property):
111+
109112
async def property_getter():
110113
msg = await self.bus.call(
111114
Message(destination=self.bus_name,
@@ -151,6 +154,7 @@ class ProxyObject(BaseProxyObject):
151154
152155
For more information, see the :class:`BaseProxyObject <dbus_next.proxy_object.BaseProxyObject>`.
153156
"""
157+
154158
def __init__(self, bus_name: str, path: str, introspection: Union[intr.Node, str, ET.Element],
155159
bus: BaseMessageBus):
156160
super().__init__(bus_name, path, introspection, bus, ProxyInterface)

dbus_next/auth.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ class Authenticator:
3535
3636
:seealso: https://dbus.freedesktop.org/doc/dbus-specification.html#auth-protocol
3737
"""
38+
3839
def _authentication_start(self, negotiate_unix_fd=False):
3940
raise NotImplementedError(
4041
'authentication_start() must be implemented in the inheriting class')
@@ -53,6 +54,7 @@ class AuthExternal(Authenticator):
5354
5455
:sealso: https://dbus.freedesktop.org/doc/dbus-specification.html#auth-protocol
5556
"""
57+
5658
def __init__(self):
5759
self.negotiate_unix_fd = False
5860
self.negotiating_fds = False
@@ -84,6 +86,7 @@ class AuthAnnonymous(Authenticator):
8486
8587
:sealso: https://dbus.freedesktop.org/doc/dbus-specification.html#auth-protocol
8688
"""
89+
8790
def _authentication_start(self, negotiate_unix_fd=False) -> str:
8891
if negotiate_unix_fd:
8992
raise AuthError(

dbus_next/errors.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,21 +31,25 @@ class SignalDisabledError(Exception):
3131

3232

3333
class InvalidBusNameError(TypeError):
34+
3435
def __init__(self, name):
3536
super().__init__(f'invalid bus name: {name}')
3637

3738

3839
class InvalidObjectPathError(TypeError):
40+
3941
def __init__(self, path):
4042
super().__init__(f'invalid object path: {path}')
4143

4244

4345
class InvalidInterfaceNameError(TypeError):
46+
4447
def __init__(self, name):
4548
super().__init__(f'invalid interface name: {name}')
4649

4750

4851
class InvalidMemberNameError(TypeError):
52+
4953
def __init__(self, member):
5054
super().__init__(f'invalid member name: {member}')
5155

@@ -56,6 +60,7 @@ def __init__(self, member):
5660

5761

5862
class DBusError(Exception):
63+
5964
def __init__(self, type_, text, reply=None):
6065
super().__init__(text)
6166

dbus_next/glib/message_bus.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ class _GLibSource:
2424

2525

2626
class _MessageSource(_GLibSource):
27+
2728
def __init__(self, bus):
2829
self.unmarshaller = None
2930
self.bus = bus
@@ -54,6 +55,7 @@ def dispatch(self, callback, user_data):
5455

5556

5657
class _MessageWritableSource(_GLibSource):
58+
5759
def __init__(self, bus):
5860
self.bus = bus
5961
self.buf = b''
@@ -99,6 +101,7 @@ def dispatch(self, callback, user_data):
99101

100102

101103
class _AuthLineSource(_GLibSource):
104+
102105
def __init__(self, stream):
103106
self.stream = stream
104107
self.buf = b''
@@ -146,6 +149,7 @@ class MessageBus(BaseMessageBus):
146149
be :class:`None` until the message bus connects.
147150
:vartype unique_name: str
148151
"""
152+
149153
def __init__(self,
150154
bus_address: str = None,
151155
bus_type: BusType = BusType.SESSION,
@@ -174,6 +178,7 @@ def connect(self, connect_notify: Callable[['MessageBus', Optional[Exception]],
174178
:class:`AuthError <dbus_next.AuthError>` on authorization errors.
175179
:type callback: :class:`Callable`
176180
"""
181+
177182
def authenticate_notify(exc):
178183
if exc is not None:
179184
if connect_notify is not None:

dbus_next/glib/proxy_object.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ def set_callback(error: Exception)
108108
:class:`DBusError <dbus_next.DBusError>` will be raised with information
109109
about the error.
110110
"""
111+
111112
def _add_method(self, intr_method):
112113
in_len = len(intr_method.in_args)
113114
out_len = len(intr_method.out_args)
@@ -176,7 +177,9 @@ def callback(body, err):
176177
setattr(self, method_name_sync, method_fn_sync)
177178

178179
def _add_property(self, intr_property):
180+
179181
def property_getter(callback):
182+
180183
def call_notify(msg, err):
181184
if err:
182185
callback(None, err)
@@ -226,6 +229,7 @@ def callback(value, err):
226229
return property_value
227230

228231
def property_setter(value, callback):
232+
229233
def call_notify(msg, err):
230234
if err:
231235
callback(None, err)
@@ -275,6 +279,7 @@ class ProxyObject(BaseProxyObject):
275279
276280
For more information, see the :class:`BaseProxyObject <dbus_next.proxy_object.BaseProxyObject>`.
277281
"""
282+
278283
def __init__(self, bus_name: str, path: str, introspection: Union[intr.Node, str, ET.Element],
279284
bus: BaseMessageBus):
280285
super().__init__(bus_name, path, introspection, bus, ProxyInterface)

0 commit comments

Comments
 (0)