1818
1919
2020class EventGetterSetter (object ):
21-
2221 def CloudEventVersion (self ) -> str :
2322 raise Exception ("not implemented" )
2423
@@ -76,18 +75,13 @@ def SetContentType(self, contentType: str) -> object:
7675
7776
7877class BaseEvent (EventGetterSetter ):
79-
8078 def Properties (self , with_nullable = False ) -> dict :
8179 props = dict ()
8280 for name , value in self .__dict__ .items ():
8381 if str (name ).startswith ("ce__" ):
8482 v = value .get ()
8583 if v is not None or with_nullable :
86- props .update (
87- {
88- str (name ).replace ("ce__" , "" ): value .get ()
89- }
90- )
84+ props .update ({str (name ).replace ("ce__" , "" ): value .get ()})
9185
9286 return props
9387
@@ -119,33 +113,38 @@ def MarshalJSON(self, data_marshaller: typing.Callable) -> typing.IO:
119113 props ["data" ] = data_marshaller (props .get ("data" ))
120114 return io .BytesIO (json .dumps (props ).encode ("utf-8" ))
121115
122- def UnmarshalJSON (self , b : typing .IO ,
123- data_unmarshaller : typing .Callable ):
116+ def UnmarshalJSON (self , b : typing .IO , data_unmarshaller : typing .Callable ):
124117 raw_ce = json .load (b )
125118 for name , value in raw_ce .items ():
126119 if name == "data" :
127120 value = data_unmarshaller (value )
128121 self .Set (name , value )
129122
130- def UnmarshalBinary (self , headers : dict , body : typing .IO ,
131- data_unmarshaller : typing .Callable ):
132- BINARY_MAPPING = {
133- 'content-type' : 'contenttype' ,
123+ def UnmarshalBinary (
124+ self ,
125+ headers : dict ,
126+ body : typing .IO ,
127+ data_unmarshaller : typing .Callable
128+ ):
129+ binary_mapping = {
130+ "content-type" : "contenttype" ,
134131 # TODO(someone): add Distributed Tracing. It's not clear
135132 # if this is one extension or two.
136133 # https://github.com/cloudevents/spec/blob/master/extensions/distributed-tracing.md
137134 }
138135 for header , value in headers .items ():
139136 header = header .lower ()
140- if header in BINARY_MAPPING :
141- self .Set (BINARY_MAPPING [header ], value )
137+ if header in binary_mapping :
138+ self .Set (binary_mapping [header ], value )
142139 elif header .startswith ("ce-" ):
143140 self .Set (header [3 :], value )
144141
145142 self .Set ("data" , data_unmarshaller (body ))
146143
147144 def MarshalBinary (
148- self , data_marshaller : typing .Callable ) -> (dict , object ):
145+ self ,
146+ data_marshaller : typing .Callable
147+ ) -> (dict , object ):
149148 headers = {}
150149 if self .ContentType ():
151150 headers ["content-type" ] = self .ContentType ()
@@ -159,5 +158,4 @@ def MarshalBinary(
159158 headers ["ce-{0}" .format (key )] = value
160159
161160 data , _ = self .Get ("data" )
162- return headers , io .BytesIO (
163- str (data_marshaller (data )).encode ("utf-8" ))
161+ return headers , data_marshaller (data )
0 commit comments