44
55import base64
66import os
7+
78import json
89import http_ece
910import pyelliptic
@@ -151,13 +152,13 @@ def encode(self, data):
151152 'body' : encrypted ,
152153 })
153154
154- def send (self , data , gcm_key = None , reg_id = None , headers = {}, ttl = 0 ):
155+ def send (self , data , headers = {}, ttl = 0 , gcm_key = None , reg_id = None ):
155156 """Encode and send the data to the Push Service.
156157
157158 :param data: A serialized block of data (see encode() ).
158- :param gcm_key: API key obtained from the Google Developer Console.
159+ :param gcm_key: API key obtained from the Google Developer Console.
159160 Needed if endpoint is https://android.googleapis.com/gcm/send
160- :param reg_id: registration id of the recipient. If not provided,
161+ :param reg_id: registration id of the recipient. If not provided,
161162 it will be extracted from the endpoint.
162163 :param headers: A dictionary containing any additional HTTP headers.
163164 :param ttl: The Time To Live in seconds for this message if the
@@ -179,12 +180,12 @@ def send(self, data, gcm_key=None, reg_id=None, headers={}, ttl=0):
179180 'encryption' : "keyid=p256dh;salt=" +
180181 encoded ['salt' ].decode ('utf8' ),
181182 })
182-
183- if self .subscription_info ['endpoint' ].startswith ('https://android.googleapis.com/gcm/send' ):
183+ gcm_endpoint = 'https://android.googleapis.com/gcm/send'
184+ if self .subscription_info ['endpoint' ].startswith (gcm_endpoint ):
184185
185186 if not gcm_key :
186- raise WebPushException ("API key not provided for google gcm endpoint" )
187- endpoint = 'https://android.googleapis.com/gcm/send'
187+ raise WebPushException ("API key not provided for gcm endpoint" )
188+ endpoint = gcm_endpoint
188189 reg_ids = []
189190 if not reg_id :
190191 reg_id = self .subscription_info ['endpoint' ].rsplit ('/' , 1 )[- 1 ]
@@ -194,8 +195,8 @@ def send(self, data, gcm_key=None, reg_id=None, headers={}, ttl=0):
194195 data ['raw_data' ] = base64 .b64encode (encoded .get ('body' ))
195196 encoded_data = json .dumps (data )
196197 headers .update ({
197- 'Authorization' : 'key=' + gcm_key ,
198- 'Content-Type' : 'application/json' ,
198+ 'Authorization' : 'key=' + gcm_key ,
199+ 'Content-Type' : 'application/json' ,
199200 })
200201 else :
201202 encoded_data = encoded .get ('body' )
0 commit comments