@@ -34,15 +34,14 @@ def input_serialzer(fonction):
34
34
:param fonction: the function that will be decorated
35
35
:return: The function dispatch_serializer is being returned.
36
36
"""
37
- def dispatch_serializer (self ,* params , ** param2 ):
38
- # Handle positional arguments
39
- serialized = []
40
- for param in params :
41
- serialized .append (self ._dispatch_serializer (param ))
42
- # Handle keyword arguments
43
- for key , value in param2 .items ():
44
- param2 [key ] = self ._dispatch_serializer (value )
45
- return fonction (self ,* serialized , ** param2 )
37
+ def dispatch_serializer (self , * params , ** param2 ):
38
+ # Handle positional arguments using list comprehension
39
+ serialized = [self ._dispatch_serializer (param ) for param in params ]
40
+
41
+ # Handle keyword arguments using dictionary comprehension
42
+ param2 = {key : self ._dispatch_serializer (value ) for key , value in param2 .items ()}
43
+
44
+ return fonction (self , * serialized , ** param2 )
46
45
return dispatch_serializer
47
46
48
47
def input_serialzer_param (position :int ,name :str ):
@@ -55,19 +54,20 @@ def input_serialzer_param(position:int,name:str):
55
54
"""
56
55
def input_serialzer_param (fonction ):
57
56
@wraps (fonction )
58
- def dispatch_serializer (self ,* params , ** param2 ):
59
- # Handle positional arguments
60
- serialized = []
61
- for i ,param in enumerate (params ):
62
- if i == position :
63
- serialized .append (self ._dispatch_serializer (param ))
64
- else :
65
- serialized .append (param )
66
- # Handle keyword arguments
67
- for key , value in param2 .items ():
68
- if key == name :
69
- param2 [key ] = self ._dispatch_serializer (value )
70
- return fonction (self ,* serialized , ** param2 )
57
+ def dispatch_serializer (self , * params , ** param2 ):
58
+ # Handle positional arguments using list comprehension
59
+ serialized = [
60
+ self ._dispatch_serializer (param ) if i == position else param
61
+ for i , param in enumerate (params )
62
+ ]
63
+
64
+ # Handle keyword arguments using dictionary comprehension
65
+ param2 = {
66
+ key : self ._dispatch_serializer (value ) if key == name else value
67
+ for key , value in param2 .items ()
68
+ }
69
+
70
+ return fonction (self , * serialized , ** param2 )
71
71
return dispatch_serializer
72
72
return input_serialzer_param
73
73
@@ -93,15 +93,14 @@ def input_deserialzer(fonction):
93
93
:param fonction: the function that will be decorated
94
94
:return: The function dispatch_deserializer is being returned.
95
95
"""
96
- def dispatch_deserializer (self ,* params , ** param2 ):
97
- # Handle positional arguments
98
- serialized = []
99
- for param in params :
100
- serialized .append (self ._dispatch_deserializer (param ))
101
- # Handle keyword arguments
102
- for key , value in param2 .items ():
103
- param2 [key ] = self ._dispatch_deserializer (value )
104
- return fonction (self ,* serialized , ** param2 )
96
+ def dispatch_deserializer (self , * params , ** param2 ):
97
+ # Handle positional arguments using list comprehension
98
+ serialized = [self ._dispatch_deserializer (param ) for param in params ]
99
+
100
+ # Handle keyword arguments using dictionary comprehension
101
+ param2 = {key : self ._dispatch_deserializer (value ) for key , value in param2 .items ()}
102
+
103
+ return fonction (self , * serialized , ** param2 )
105
104
return dispatch_deserializer
106
105
107
106
def output_serialzer (fonction ):
@@ -236,18 +235,20 @@ def _dispatch_serializer(self,message):
236
235
:param message: The message to be serialized
237
236
:return: The serialized message
238
237
"""
239
- if (message is not None and self ._is_message_instance (message )):
240
- return self ._serialize_message (message )
241
- elif (message is not None and self ._is_pickle_message_instance (message )):
242
- return self ._serialize_pickle_message (message )
243
- elif (message is not None and self ._is_iris_object_instance (message )):
244
- return message
245
- elif (message is None or message == "" ):
238
+ if message is not None :
239
+ if self ._is_message_instance (message ):
240
+ return self ._serialize_message (message )
241
+ elif self ._is_pickle_message_instance (message ):
242
+ return self ._serialize_pickle_message (message )
243
+ elif self ._is_iris_object_instance (message ):
244
+ return message
245
+
246
+ if message == "" or message is None :
246
247
return message
247
- else :
248
- # todo : decorator takes care of all the parameters, so this should never happen
249
- # return message
250
- raise TypeError ("The message must be an instance of a class that is a subclass of Message or IRISObject %Persistent class." )
248
+
249
+ # todo : decorator takes care of all the parameters, so this should never happen
250
+ # return message
251
+ raise TypeError ("The message must be an instance of a class that is a subclass of Message or IRISObject %Persistent class." )
251
252
252
253
def _serialize_message (self ,message ):
253
254
""" Converts a python dataclass message into an iris iop.message.
@@ -291,16 +292,22 @@ def _dispatch_deserializer(self,serial):
291
292
:return: The return value is a tuple of the form (serial, serial_type)
292
293
"""
293
294
if (
294
- (serial is not None and type (serial ).__module__ .find ('iris' ) == 0 )
295
- and
296
- (serial ._IsA ("IOP.Message" ) or serial ._IsA ("Grongier.PEX.Message" ))
297
- ):
295
+ serial is not None
296
+ and type (serial ).__module__ .startswith ('iris' )
297
+ and (
298
+ serial ._IsA ("IOP.Message" )
299
+ or serial ._IsA ("Grongier.PEX.Message" )
300
+ )
301
+ ):
298
302
return self ._deserialize_message (serial )
299
303
elif (
300
- (serial is not None and type (serial ).__module__ .find ('iris' ) == 0 )
301
- and
302
- (serial ._IsA ("IOP.PickleMessage" ) or serial ._IsA ("Grongier.PEX.PickleMessage" ))
303
- ):
304
+ serial is not None
305
+ and type (serial ).__module__ .startswith ('iris' )
306
+ and (
307
+ serial ._IsA ("IOP.PickleMessage" )
308
+ or serial ._IsA ("Grongier.PEX.PickleMessage" )
309
+ )
310
+ ):
304
311
return self ._deserialize_pickle_message (serial )
305
312
else :
306
313
return serial
0 commit comments