@@ -267,7 +267,7 @@ def write(self, string):
267267 return self ._connection ().write (string )
268268
269269
270- class PayloadAlert (object ):
270+ class PayloadAlert (dict ):
271271 """
272272 Payload for APNS alert.
273273 https://developer.apple.com/library/content/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/PayloadKeyReference.html
@@ -282,46 +282,28 @@ def __init__(self,
282282 launch_image = None ,
283283 title_loc_key = None ,
284284 title_loc_args = None ):
285-
286- self .body = body
287- self .title = title
288- self .subtitle = subtitle
289- self .action_loc_key = action_loc_key
290- self .loc_key = loc_key
291- self .loc_args = loc_args
292- self .launch_image = launch_image
293- self .title_loc_key = title_loc_key
294- self .title_loc_args = title_loc_args
295-
296- self ._dict = {
297- 'body' : self .body ,
298- 'title' : self .title ,
299- 'subtitle' : self .subtitle ,
300- 'action-loc-key' : self .action_loc_key ,
301- 'loc-key' : self .loc_key ,
302- 'loc-args' : self .loc_args ,
303- 'launch-image' : self .launch_image ,
304- 'title-loc-key' : self .title_loc_key ,
305- 'title-loc-args' : self .title_loc_args
306- }
307-
308- def dict (self ):
309- cleared = {
310- key : value
311- for (key , value )
312- in self ._dict .items ()
313- if value is not None
285+ dict_ = {
286+ 'body' : body ,
287+ 'title' : title ,
288+ 'subtitle' : subtitle ,
289+ 'action-loc-key' : action_loc_key ,
290+ 'loc-key' : loc_key ,
291+ 'loc-args' : loc_args ,
292+ 'launch-image' : launch_image ,
293+ 'title-loc-key' : title_loc_key ,
294+ 'title-loc-args' : title_loc_args
314295 }
315- return cleared
316296
317- def __eq__ (self , other ):
318- return self .dict () == other .dict ()
297+ # init dictionary with non None items
298+ super (PayloadAlert , self ).__init__ (
299+ {
300+ key : value for (key , value )
301+ in dict_ .items () if value is not None
302+ }
303+ )
319304
320- def __ne__ (self , other ):
321- return self .dict () != other .dict ()
322-
323- def __repr__ (self ):
324- return 'PayloadAlert(**{})' .format (self .dict ())
305+ def dict (self ):
306+ return self
325307
326308
327309class PayloadTooLargeError (Exception ):
0 commit comments