Make some dependencies optional

This commit is contained in:
Lorenz Diener 2019-05-31 14:12:04 +02:00
pare 739d22e642
commit e692fac905
S'han modificat 3 arxius amb 41 adicions i 8 eliminacions

Veure arxiu

@ -1135,6 +1135,9 @@ displayed.
Mastodon allows an application to have one webpush subscription per user at a time. Mastodon allows an application to have one webpush subscription per user at a time.
All crypto utilities require Mastodon.pys optional "webpush" feature dependencies
(specifically, the "cryptography" and "http_ece" packages).
.. automethod:: Mastodon.push_subscription .. automethod:: Mastodon.push_subscription
.. automethod:: Mastodon.push_subscription_set .. automethod:: Mastodon.push_subscription_set
.. automethod:: Mastodon.push_subscription_update .. automethod:: Mastodon.push_subscription_update

Veure arxiu

@ -20,9 +20,20 @@ import threading
import sys import sys
import six import six
from decorator import decorate from decorator import decorate
from cryptography.hazmat.backends import default_backend
from cryptography.hazmat.primitives.asymmetric import ec IMPL_HAS_CRYPTO = True
import http_ece try:
from cryptography.hazmat.backends import default_backend
from cryptography.hazmat.primitives.asymmetric import ec
except:
IMPL_HAS_CRYPTO = False
IMPL_HAS_ECE = True
try:
import http_ece
except:
IMPL_HAS_ECE = False
import base64 import base64
import json import json
import blurhash import blurhash
@ -2306,6 +2317,9 @@ class Mastodon:
Returns two dicts: One with the private key and shared secret and another with the Returns two dicts: One with the private key and shared secret and another with the
public key and shared secret. public key and shared secret.
""" """
if not IMPL_HAS_CRYPTO:
raise NotImplementedError('To use the crypto tools, please install the webpush feature dependencies.')
push_key_pair = ec.generate_private_key(ec.SECP256R1(), default_backend()) push_key_pair = ec.generate_private_key(ec.SECP256R1(), default_backend())
push_key_priv = push_key_pair.private_numbers().private_value push_key_priv = push_key_pair.private_numbers().private_value
push_key_pub = push_key_pair.public_key().public_numbers().encode_point() push_key_pub = push_key_pair.public_key().public_numbers().encode_point()
@ -2331,6 +2345,9 @@ class Mastodon:
Returns the decoded webpush as a `push notification dict`_. Returns the decoded webpush as a `push notification dict`_.
""" """
if (not IMPL_HAS_ECE) or (not IMPL_HAS_CRYPTO):
raise NotImplementedError('To use the crypto tools, please install the webpush feature dependencies.')
salt = self.__decode_webpush_b64(encryption_header.split("salt=")[1].strip()) salt = self.__decode_webpush_b64(encryption_header.split("salt=")[1].strip())
dhparams = self.__decode_webpush_b64(crypto_key_header.split("dh=")[1].split(";")[0].strip()) dhparams = self.__decode_webpush_b64(crypto_key_header.split("dh=")[1].split(";")[0].strip())
p256ecdsa = self.__decode_webpush_b64(crypto_key_header.split("p256ecdsa=")[1].strip()) p256ecdsa = self.__decode_webpush_b64(crypto_key_header.split("p256ecdsa=")[1].strip())

Veure arxiu

@ -1,12 +1,27 @@
from setuptools import setup from setuptools import setup
test_deps = ['pytest', 'pytest-runner', 'pytest-cov', 'vcrpy', 'pytest-vcr', 'pytest-mock', 'requests-mock'] test_deps = [
'pytest',
'pytest-runner',
'pytest-cov',
'vcrpy',
'pytest-vcr',
'pytest-mock',
'requests-mock'
]
webpush_deps = [
'http_ece>=1.0.5',
'cryptography>=1.6.0',
]
extras = { extras = {
"test": test_deps "test": test_deps,
"webpush": webpush_deps,
} }
setup(name='Mastodon.py', setup(name='Mastodon.py',
version='1.4.2', version='1.4.3',
description='Python wrapper for the Mastodon API', description='Python wrapper for the Mastodon API',
packages=['mastodon'], packages=['mastodon'],
install_requires=[ install_requires=[
@ -16,8 +31,6 @@ setup(name='Mastodon.py',
'pytz', 'pytz',
'python-magic', 'python-magic',
'decorator>=4.0.0', 'decorator>=4.0.0',
'http_ece>=1.0.5',
'cryptography>=1.6.0',
'blurhash>=1.1.3', 'blurhash>=1.1.3',
], ],
tests_require=test_deps, tests_require=test_deps,