Skip to content

Commit 1dceb01

Browse files
scyclopsjrconlin
authored andcommitted
Use six.text_type instead of six.string_types (#119)
In Python 2, using six.string_types causes the code to attempt to re-encode already encoded data because six.string_types matches Python 2 str and unicode data. Using six.text_type makes sure that the code only attempts to encode unicode data.
1 parent 10e2e16 commit 1dceb01

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

pywebpush/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ def __init__(self, subscription_info, requests_session=None,
152152
for k in ['p256dh', 'auth']:
153153
if keys.get(k) is None:
154154
raise WebPushException("Missing keys value: {}".format(k))
155-
if isinstance(keys[k], six.string_types):
155+
if isinstance(keys[k], six.text_type):
156156
keys[k] = bytes(keys[k].encode('utf8'))
157157
receiver_raw = base64.urlsafe_b64decode(
158158
self._repad(keys['p256dh']))
@@ -206,7 +206,7 @@ def encode(self, data, content_encoding="aes128gcm"):
206206
format=serialization.PublicFormat.UncompressedPoint
207207
)
208208

209-
if isinstance(data, six.string_types):
209+
if isinstance(data, six.text_type):
210210
data = bytes(data.encode('utf8'))
211211
if content_encoding == "aes128gcm":
212212
self.verb("Encrypting to aes128gcm...")

0 commit comments

Comments
 (0)