From 4a247f0fc1a9e77351e937fa4dcee5547e2759cb Mon Sep 17 00:00:00 2001 From: David D Lowe Date: Thu, 11 May 2017 09:59:40 +0100 Subject: [PATCH 1/4] Make README.rst acceptable to PyPI's website When running a check against README.rst, I got these errors: warning: check: Cannot analyze code. No Pygments lexer found for "commandline". (line 87) warning: check: Cannot analyze code. No Pygments lexer found for "pythonstub". (line 93) I had previously ignored them, because they were just warnings. However, according to this link, usage of non-builtin lexers will cause the RST to not be recognised by PyPI. https://github.com/twolfson/restructuredtext-lint/tree/0.14.2#pypi-issues --- README.md | 27 ++++++++++++++++----------- README.rst | 22 +++++++++++----------- 2 files changed, 27 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index 3d60c2f..a67d5f7 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,8 @@ Source is available on You'll need to run `python virtualenv`. Then -```commandline + +``` bin/pip install -r requirements.txt bin/python setup.py develop ``` @@ -29,6 +30,7 @@ object. This object has a .toJSON() method that will return a JSON object that c and push data. As illustration, a `subscription_info` object may look like: + ```json {"endpoint": "https://updates.push.services.mozilla.com/push/v1/gAA...", "keys": {"auth": "k8J...", "p256dh": "BOr..."}} ``` @@ -44,14 +46,15 @@ In many cases, your code will be sending a single message to many recipients. There's a "One Call" function which will make things easier. -```pythonstub - from pywebpush import webpush +```python +from pywebpush import webpush - webpush(subscription_info, - data, - vapid_private_key="Private Key or File Path[1]", - vapid_claims={"sub": "mailto:YourEmailAddress"}) +webpush(subscription_info, + data, + vapid_private_key="Private Key or File Path[1]", + vapid_claims={"sub": "mailto:YourEmailAddress"}) ``` + This will encode `data`, add the appropriate VAPID auth headers if required and send it to the push server identified in the `subscription_info` block. @@ -74,13 +77,14 @@ pywebpush will attempt to auto-fill from the `endpoint`. a base64 encoded DER formatted private key, or the path to an OpenSSL exported private key file. e.g. the output of: -```commandline + +``` openssl ecparam -name prime256v1 -genkey -noout -out private_key.pem ``` **Example** -```pythonstub +```python from pywebpush import webpush, WebPushException try: @@ -133,7 +137,8 @@ named `encrpypted.data`. This command is meant to be used for debugging purposes **Example** to send from Chrome using the old GCM mode: -```pythonstub + +```python WebPusher(subscription_info).send(data, headers, ttl, gcm_key) ``` @@ -149,7 +154,7 @@ Encode the `data` for future use. On error, returns a `WebPushException` **Example** -```pythonstub +```python encoded_data = WebPush(subscription_info).encode(data) ``` diff --git a/README.rst b/README.rst index 71604aa..6efe037 100644 --- a/README.rst +++ b/README.rst @@ -12,7 +12,7 @@ Installation You'll need to run ``python virtualenv``. Then -.. code:: commandline +:: bin/pip install -r requirements.txt bin/python setup.py develop @@ -43,14 +43,14 @@ Sending Data using ``webpush()`` One Call In many cases, your code will be sending a single message to many recipients. There's a "One Call" function which will make things easier. -.. code:: pythonstub +.. code:: python - from pywebpush import webpush + from pywebpush import webpush - webpush(subscription_info, - data, - vapid_private_key="Private Key or File Path[1]", - vapid_claims={"sub": "mailto:YourEmailAddress"}) + webpush(subscription_info, + data, + vapid_private_key="Private Key or File Path[1]", + vapid_claims={"sub": "mailto:YourEmailAddress"}) This will encode ``data``, add the appropriate VAPID auth headers if required and send it to the push server identified in the @@ -84,13 +84,13 @@ file. e.g. the output of: -.. code:: commandline +:: openssl ecparam -name prime256v1 -genkey -noout -out private_key.pem **Example** -.. code:: pythonstub +.. code:: python from pywebpush import webpush, WebPushException @@ -153,7 +153,7 @@ purposes. to send from Chrome using the old GCM mode: -.. code:: pythonstub +.. code:: python WebPusher(subscription_info).send(data, headers, ttl, gcm_key) @@ -171,7 +171,7 @@ Encode the ``data`` for future use. On error, returns a **Example** -.. code:: pythonstub +.. code:: python encoded_data = WebPush(subscription_info).encode(data) From 8f81f70b17178142602080755e45ca56a3f74802 Mon Sep 17 00:00:00 2001 From: David D Lowe Date: Thu, 11 May 2017 10:01:22 +0100 Subject: [PATCH 2/4] Make convert_readme.sh script check the output --- convert_readme.sh | 6 ++++++ 1 file changed, 6 insertions(+) mode change 100644 => 100755 convert_readme.sh diff --git a/convert_readme.sh b/convert_readme.sh old mode 100644 new mode 100755 index d0bfce9..4043fa9 --- a/convert_readme.sh +++ b/convert_readme.sh @@ -1 +1,7 @@ +#!/bin/sh + +# You will need pandoc to be installed for this to work correctly, as well as the PyPI packages docutils and pygments + +set -e pandoc --from=markdown --to=rst --output README.rst README.md +python setup.py check --restructuredtext --strict --metadata From d8d4a637f43ece7c370eb1e6a7ac0acf533cdcac Mon Sep 17 00:00:00 2001 From: jrconlin Date: Mon, 15 May 2017 09:19:18 -0700 Subject: [PATCH 3/4] This fix addresses an incompatibility with Chrome --- pywebpush/__init__.py | 6 ++---- pywebpush/tests/test_webpush.py | 2 +- requirements.txt | 2 +- setup.py | 2 +- 4 files changed, 5 insertions(+), 7 deletions(-) diff --git a/pywebpush/__init__.py b/pywebpush/__init__.py index 55d4a8f..9bd8d8b 100644 --- a/pywebpush/__init__.py +++ b/pywebpush/__init__.py @@ -249,13 +249,11 @@ class WebPusher: # use ';' instead of ',' to append the headers. # see https://github.com/webpush-wg/webpush-encryption/issues/6 crypto_key += ';' - crypto_key += ( - "keyid=p256dh;dh=" + encoded["crypto_key"].decode('utf8')) + crypto_key += ("dh=" + encoded["crypto_key"].decode('utf8')) headers.update({ 'crypto-key': crypto_key, 'content-encoding': content_encoding, - 'encryption': "keyid=p256dh;salt=" + - encoded['salt'].decode('utf8'), + 'encryption': "salt=" + encoded['salt'].decode('utf8'), }) if gcm_key: endpoint = 'https://android.googleapis.com/gcm/send' diff --git a/pywebpush/tests/test_webpush.py b/pywebpush/tests/test_webpush.py index 71b54e7..5bc7d84 100644 --- a/pywebpush/tests/test_webpush.py +++ b/pywebpush/tests/test_webpush.py @@ -265,7 +265,7 @@ class WebpushTestCase(unittest.TestCase): "-H \"crypto-key: p256ecdsa=", "-H \"content-encoding: aesgcm\"", "-H \"authorization: WebPush ", - "-H \"encryption: keyid=p256dh;salt=", + "-H \"encryption: salt=", "-H \"ttl: 0\"", "-H \"content-length:" ]: diff --git a/requirements.txt b/requirements.txt index e770f36..93b2626 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ cryptography==1.8.1 http-ece==1.0.1 requests==2.13.0 -py-vapid==1.2.1 +py-vapid==1.2.2 diff --git a/setup.py b/setup.py index 66d8dd6..6b4e450 100644 --- a/setup.py +++ b/setup.py @@ -3,7 +3,7 @@ import os from setuptools import find_packages, setup -__version__ = "1.0.0" +__version__ = "1.0.1" def read_from(file): From ccc500464c71208d7211a252616782d779b34a79 Mon Sep 17 00:00:00 2001 From: jrconlin Date: Tue, 23 May 2017 15:02:55 -0700 Subject: [PATCH 4/4] Update py-vapid requirements (now that it's been proofed for gcm) --- requirements.txt | 2 +- setup.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/requirements.txt b/requirements.txt index 93b2626..e5b1ae1 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ cryptography==1.8.1 http-ece==1.0.1 requests==2.13.0 -py-vapid==1.2.2 +py-vapid==1.2.3 diff --git a/setup.py b/setup.py index 6b4e450..2a3e260 100644 --- a/setup.py +++ b/setup.py @@ -3,7 +3,7 @@ import os from setuptools import find_packages, setup -__version__ = "1.0.1" +__version__ = "1.0.2" def read_from(file):