aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLorenz Diener <[email protected]>2019-05-31 14:12:04 +0200
committerLorenz Diener <[email protected]>2019-05-31 14:12:04 +0200
commite692fac905c6639b5cd9a440d44dccb3b6b843ec (patch)
treeec82c78c7cec502c574d6c6a8190e3333168b2de
parent739d22e642938ae61b4ec83c4b566714d2f7d498 (diff)
downloadmastodon.py-e692fac905c6639b5cd9a440d44dccb3b6b843ec.tar.gz
Make some dependencies optional
-rw-r--r--docs/index.rst3
-rw-r--r--mastodon/Mastodon.py23
-rw-r--r--setup.py23
3 files changed, 41 insertions, 8 deletions
diff --git a/docs/index.rst b/docs/index.rst
index 52bac0f..45d8202 100644
--- a/docs/index.rst
+++ b/docs/index.rst
@@ -1135,6 +1135,9 @@ displayed.
1135 1135
1136Mastodon allows an application to have one webpush subscription per user at a time. 1136Mastodon allows an application to have one webpush subscription per user at a time.
1137 1137
1138All crypto utilities require Mastodon.pys optional "webpush" feature dependencies
1139(specifically, the "cryptography" and "http_ece" packages).
1140
1138.. automethod:: Mastodon.push_subscription 1141.. automethod:: Mastodon.push_subscription
1139.. automethod:: Mastodon.push_subscription_set 1142.. automethod:: Mastodon.push_subscription_set
1140.. automethod:: Mastodon.push_subscription_update 1143.. automethod:: Mastodon.push_subscription_update
diff --git a/mastodon/Mastodon.py b/mastodon/Mastodon.py
index 7b6c801..37ca999 100644
--- a/mastodon/Mastodon.py
+++ b/mastodon/Mastodon.py
@@ -20,9 +20,20 @@ import threading
20import sys 20import sys
21import six 21import six
22from decorator import decorate 22from decorator import decorate
23from cryptography.hazmat.backends import default_backend 23
24from cryptography.hazmat.primitives.asymmetric import ec 24IMPL_HAS_CRYPTO = True
25import http_ece 25try:
26 from cryptography.hazmat.backends import default_backend
27 from cryptography.hazmat.primitives.asymmetric import ec
28except:
29 IMPL_HAS_CRYPTO = False
30
31IMPL_HAS_ECE = True
32try:
33 import http_ece
34except:
35 IMPL_HAS_ECE = False
36
26import base64 37import base64
27import json 38import json
28import blurhash 39import blurhash
@@ -2306,6 +2317,9 @@ class Mastodon:
2306 Returns two dicts: One with the private key and shared secret and another with the 2317 Returns two dicts: One with the private key and shared secret and another with the
2307 public key and shared secret. 2318 public key and shared secret.
2308 """ 2319 """
2320 if not IMPL_HAS_CRYPTO:
2321 raise NotImplementedError('To use the crypto tools, please install the webpush feature dependencies.')
2322
2309 push_key_pair = ec.generate_private_key(ec.SECP256R1(), default_backend()) 2323 push_key_pair = ec.generate_private_key(ec.SECP256R1(), default_backend())
2310 push_key_priv = push_key_pair.private_numbers().private_value 2324 push_key_priv = push_key_pair.private_numbers().private_value
2311 push_key_pub = push_key_pair.public_key().public_numbers().encode_point() 2325 push_key_pub = push_key_pair.public_key().public_numbers().encode_point()
@@ -2331,6 +2345,9 @@ class Mastodon:
2331 2345
2332 Returns the decoded webpush as a `push notification dict`_. 2346 Returns the decoded webpush as a `push notification dict`_.
2333 """ 2347 """
2348 if (not IMPL_HAS_ECE) or (not IMPL_HAS_CRYPTO):
2349 raise NotImplementedError('To use the crypto tools, please install the webpush feature dependencies.')
2350
2334 salt = self.__decode_webpush_b64(encryption_header.split("salt=")[1].strip()) 2351 salt = self.__decode_webpush_b64(encryption_header.split("salt=")[1].strip())
2335 dhparams = self.__decode_webpush_b64(crypto_key_header.split("dh=")[1].split(";")[0].strip()) 2352 dhparams = self.__decode_webpush_b64(crypto_key_header.split("dh=")[1].split(";")[0].strip())
2336 p256ecdsa = self.__decode_webpush_b64(crypto_key_header.split("p256ecdsa=")[1].strip()) 2353 p256ecdsa = self.__decode_webpush_b64(crypto_key_header.split("p256ecdsa=")[1].strip())
diff --git a/setup.py b/setup.py
index 6b8c682..1bc3a17 100644
--- a/setup.py
+++ b/setup.py
@@ -1,12 +1,27 @@
1from setuptools import setup 1from setuptools import setup
2 2
3test_deps = ['pytest', 'pytest-runner', 'pytest-cov', 'vcrpy', 'pytest-vcr', 'pytest-mock', 'requests-mock'] 3test_deps = [
4 'pytest',
5 'pytest-runner',
6 'pytest-cov',
7 'vcrpy',
8 'pytest-vcr',
9 'pytest-mock',
10 'requests-mock'
11]
12
13webpush_deps = [
14 'http_ece>=1.0.5',
15 'cryptography>=1.6.0',
16]
17
4extras = { 18extras = {
5 "test": test_deps 19 "test": test_deps,
20 "webpush": webpush_deps,
6} 21}
7 22
8setup(name='Mastodon.py', 23setup(name='Mastodon.py',
9 version='1.4.2', 24 version='1.4.3',
10 description='Python wrapper for the Mastodon API', 25 description='Python wrapper for the Mastodon API',
11 packages=['mastodon'], 26 packages=['mastodon'],
12 install_requires=[ 27 install_requires=[
@@ -16,8 +31,6 @@ setup(name='Mastodon.py',
16 'pytz', 31 'pytz',
17 'python-magic', 32 'python-magic',
18 'decorator>=4.0.0', 33 'decorator>=4.0.0',
19 'http_ece>=1.0.5',
20 'cryptography>=1.6.0',
21 'blurhash>=1.1.3', 34 'blurhash>=1.1.3',
22 ], 35 ],
23 tests_require=test_deps, 36 tests_require=test_deps,
Powered by cgit v1.2.3 (git 2.41.0)