@@ -120,13 +120,13 @@ def send_all(messages, dry_run=False, app=None):
120120    return  _get_messaging_service (app ).send_all (messages , dry_run )
121121
122122def  send_multicast (multicast_message , dry_run = False , app = None ):
123-     """Sends the given mutlicast message to the mutlicast message  tokens via Firebase Cloud Messaging (FCM). 
123+     """Sends the given mutlicast message to all  tokens via Firebase Cloud Messaging (FCM). 
124124
125125    If the ``dry_run`` mode is enabled, the message will not be actually delivered to the 
126126    recipients. Instead FCM performs all the usual validations, and emulates the send operation. 
127127
128128    Args: 
129-         message : An instance of ``messaging.MulticastMessage``. 
129+         multicast_message : An instance of ``messaging.MulticastMessage``. 
130130        dry_run: A boolean indicating whether to run the operation in dry run mode (optional). 
131131        app: An App instance (optional). 
132132
@@ -139,14 +139,14 @@ def send_multicast(multicast_message, dry_run=False, app=None):
139139    """ 
140140    if  not  isinstance (multicast_message , MulticastMessage ):
141141        raise  ValueError ('Message must be an instance of messaging.MulticastMessage class.' )
142-     messages  =  map ( lambda   token :  Message (
142+     messages  =  [ Message (
143143        data = multicast_message .data ,
144144        notification = multicast_message .notification ,
145145        android = multicast_message .android ,
146146        webpush = multicast_message .webpush ,
147147        apns = multicast_message .apns ,
148148        token = token 
149-     ),  multicast_message .tokens ) 
149+     )  for   token   in   multicast_message .tokens ] 
150150    return  _get_messaging_service (app ).send_all (messages , dry_run )
151151
152152def  subscribe_to_topic (tokens , topic , app = None ):
@@ -254,6 +254,7 @@ def __init__(self, code, message, detail=None):
254254
255255
256256class  BatchResponse (object ):
257+     """The response received from a batch request to the FCM API.""" 
257258
258259    def  __init__ (self , responses ):
259260        self ._responses  =  responses 
@@ -277,6 +278,7 @@ def failure_count(self):
277278
278279
279280class  SendResponse (object ):
281+     """The response received from an individual batched request to the FCM API.""" 
280282
281283    def  __init__ (self , resp , exception ):
282284        self ._exception  =  exception 
@@ -361,7 +363,12 @@ def send(self, message, dry_run=False):
361363        data  =  self ._message_data (message , dry_run )
362364        try :
363365            resp  =  self ._client .body (
364-                 'post' , url = self ._fcm_url , headers = self ._fcm_headers , json = data , timeout = self ._timeout )
366+                 'post' ,
367+                 url = self ._fcm_url ,
368+                 headers = self ._fcm_headers ,
369+                 json = data ,
370+                 timeout = self ._timeout 
371+             )
365372        except  requests .exceptions .RequestException  as  error :
366373            if  error .response  is  not None :
367374                self ._handle_fcm_error (error )
@@ -372,12 +379,13 @@ def send(self, message, dry_run=False):
372379            return  resp ['name' ]
373380
374381    def  send_all (self , messages , dry_run = False ):
382+         """Sends the given messages to FCM via the batch API.""" 
375383        if  not  isinstance (messages , list ):
376384            raise  ValueError ('Messages must be an list of messaging.Message instances.' )
377385
378386        responses  =  []
379387
380-         def  batch_callback (request_id , response , error ):
388+         def  batch_callback (_ , response , error ):
381389            exception  =  None 
382390            if  error :
383391                exception  =  self ._parse_batch_error (error )
@@ -388,7 +396,13 @@ def batch_callback(request_id, response, error):
388396        for  message  in  messages :
389397            body  =  json .dumps (self ._message_data (message , dry_run ))
390398            req  =  http .HttpRequest (
391-                 http = self ._transport , postproc = self ._postproc , uri = self ._fcm_url , method = 'POST' , body = body , headers = self ._fcm_headers )
399+                 http = self ._transport ,
400+                 postproc = self ._postproc ,
401+                 uri = self ._fcm_url ,
402+                 method = 'POST' ,
403+                 body = body ,
404+                 headers = self ._fcm_headers 
405+             )
392406            batch .add (req )
393407
394408        try :
@@ -455,7 +469,8 @@ def _handle_fcm_error(self, error):
455469        except  ValueError :
456470            pass 
457471
458-         raise  _MessagingService ._parse_fcm_error (data , error .response .content , error .response .status_code , error )
472+         raise  _MessagingService ._parse_fcm_error (
473+             data , error .response .content , error .response .status_code , error )
459474
460475    def  _handle_iid_error (self , error ):
461476        """Handles errors received from the Instance ID API.""" 
@@ -476,6 +491,7 @@ def _handle_iid_error(self, error):
476491        raise  ApiCallError (code , msg , error )
477492
478493    def  _parse_batch_error (self , error ):
494+         """Parses a googleapiclient.http.HttpError content in to an ApiCallError.""" 
479495        if  error .content  is  None :
480496            msg  =  'Failed to call messaging API: {0}' .format (error )
481497            return  ApiCallError (self .INTERNAL_ERROR , msg , error )
@@ -504,6 +520,7 @@ def _parse_fcm_error(cls, data, content, status_code, error):
504520
505521        msg  =  error_dict .get ('message' )
506522        if  not  msg :
507-             msg  =  'Unexpected HTTP response with status: {0}; body: {1}' .format (status_code , content .decode ())
523+             msg  =  'Unexpected HTTP response with status: {0}; body: {1}' .format (
524+                 status_code , content .decode ())
508525
509526        return  ApiCallError (code , msg , error )
0 commit comments