44
55import base64
66import os
7+
78import json
89import http_ece
910import pyelliptic
@@ -143,13 +144,13 @@ def encode(self, data):
143144 'body' : encrypted ,
144145 })
145146
146- def send (self , data , gcm_key = None , reg_id = None , headers = {}, ttl = 0 ):
147+ def send (self , data , headers = {}, ttl = 0 , gcm_key = None , reg_id = None ):
147148 """Encode and send the data to the Push Service.
148149
149150 :param data: A serialized block of data (see encode() ).
150- :param gcm_key: API key obtained from the Google Developer Console.
151+ :param gcm_key: API key obtained from the Google Developer Console.
151152 Needed if endpoint is https://android.googleapis.com/gcm/send
152- :param reg_id: registration id of the recipient. If not provided,
153+ :param reg_id: registration id of the recipient. If not provided,
153154 it will be extracted from the endpoint.
154155 :param headers: A dictionary containing any additional HTTP headers.
155156 :param ttl: The Time To Live in seconds for this message if the
@@ -170,12 +171,12 @@ def send(self, data, gcm_key=None, reg_id=None, headers={}, ttl=0):
170171 'content-encoding' : 'aesgcm' ,
171172 'encryption' : "keyid=p256dh;salt=" + encoded ['salt' ],
172173 })
173-
174- if self .subscription_info ['endpoint' ].startswith ('https://android.googleapis.com/gcm/send' ):
174+ gcm_endpoint = 'https://android.googleapis.com/gcm/send'
175+ if self .subscription_info ['endpoint' ].startswith (gcm_endpoint ):
175176
176177 if not gcm_key :
177- raise WebPushException ("API key not provided for google gcm endpoint" )
178- endpoint = 'https://android.googleapis.com/gcm/send'
178+ raise WebPushException ("API key not provided for gcm endpoint" )
179+ endpoint = gcm_endpoint
179180 reg_ids = []
180181 if not reg_id :
181182 reg_id = self .subscription_info ['endpoint' ].rsplit ('/' , 1 )[- 1 ]
@@ -185,8 +186,8 @@ def send(self, data, gcm_key=None, reg_id=None, headers={}, ttl=0):
185186 data ['raw_data' ] = base64 .b64encode (encoded .get ('body' ))
186187 encoded_data = json .dumps (data )
187188 headers .update ({
188- 'Authorization' : 'key=' + gcm_key ,
189- 'Content-Type' : 'application/json' ,
189+ 'Authorization' : 'key=' + gcm_key ,
190+ 'Content-Type' : 'application/json' ,
190191 })
191192 else :
192193 encoded_data = encoded .get ('body' )
0 commit comments