4747HEADER_REPLY_SERIAL = HeaderField .REPLY_SERIAL .name
4848HEADER_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
6154class 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 }
0 commit comments