Skip to content

Commit c3b85f0

Browse files
committed
fix flake8 errors
1 parent a868ebd commit c3b85f0

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ WebPusher(subscription_info).send(data, headers)
4949
```
5050
to send for Chrome:
5151
```
52-
WebPusher(subscription_info).send(data, gcm_key, headers)
52+
WebPusher(subscription_info).send(data, headers, ttl, gcm_key)
5353
```
5454

5555
You can also simply encode the data to send later by calling

pywebpush/__init__.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import base64
66
import os
7+
78
import json
89
import http_ece
910
import 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

Comments
 (0)