aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'mastodon')
-rw-r--r--mastodon/Mastodon.py43
1 files changed, 23 insertions, 20 deletions
diff --git a/mastodon/Mastodon.py b/mastodon/Mastodon.py
index 9386882..2adcd74 100644
--- a/mastodon/Mastodon.py
+++ b/mastodon/Mastodon.py
@@ -40,7 +40,6 @@ try:
40except: 40except:
41 IMPL_HAS_ECE = False 41 IMPL_HAS_ECE = False
42 42
43
44IMPL_HAS_BLURHASH = True 43IMPL_HAS_BLURHASH = True
45try: 44try:
46 import blurhash 45 import blurhash
@@ -262,6 +261,7 @@ class Mastodon:
262 __DICT_VERSION_REACTION = "3.1.0" 261 __DICT_VERSION_REACTION = "3.1.0"
263 __DICT_VERSION_ANNOUNCEMENT = bigger_version("3.1.0", __DICT_VERSION_REACTION) 262 __DICT_VERSION_ANNOUNCEMENT = bigger_version("3.1.0", __DICT_VERSION_REACTION)
264 __DICT_VERSION_STATUS_EDIT = "3.5.0" 263 __DICT_VERSION_STATUS_EDIT = "3.5.0"
264 __DICT_VERSION_FAMILIAR_FOLLOWERS = bigger_version("3.5.0", __DICT_VERSION_ACCOUNT)
265 __DICT_VERSION_ADMIN_DOMAIN_BLOCK = "4.0.0" 265 __DICT_VERSION_ADMIN_DOMAIN_BLOCK = "4.0.0"
266 __DICT_VERSION_ADMIN_MEASURE = "3.5.0" 266 __DICT_VERSION_ADMIN_MEASURE = "3.5.0"
267 __DICT_VERSION_ADMIN_DIMENSION = "3.5.0" 267 __DICT_VERSION_ADMIN_DIMENSION = "3.5.0"
@@ -1357,7 +1357,7 @@ class Mastodon:
1357 """ 1357 """
1358 return self.__api_request('GET', '/api/v1/accounts/lookup', self.__generate_params(locals())) 1358 return self.__api_request('GET', '/api/v1/accounts/lookup', self.__generate_params(locals()))
1359 1359
1360 @api_version("3.5.0", "3.5.0", __DICT_VERSION_ACCOUNT) 1360 @api_version("3.5.0", "3.5.0", __DICT_VERSION_FAMILIAR_FOLLOWERS)
1361 def account_familiar_followers(self, id): 1361 def account_familiar_followers(self, id):
1362 """ 1362 """
1363 Find followers for the account given by id (can be a list) that also follow the 1363 Find followers for the account given by id (can be a list) that also follow the
@@ -2457,8 +2457,19 @@ class Mastodon:
2457 Returns a `relationship dict`_ containing the updated relationship to the user. 2457 Returns a `relationship dict`_ containing the updated relationship to the user.
2458 """ 2458 """
2459 id = self.__unpack_id(id) 2459 id = self.__unpack_id(id)
2460 url = '/api/v1/accounts/{0}/unfollow'.format(str(id)) 2460 return self.__api_request('POST', '/api/v1/accounts/{0}/unfollow'.format(str(id)))
2461 return self.__api_request('POST', url) 2461
2462 @api_version("3.5.0", "3.5.0", __DICT_VERSION_RELATIONSHIP)
2463 def account_remove_from_followers(self, id):
2464 """
2465 Remove a user from the logged in users followers (i.e. make them unfollow the logged in
2466 user / "softblock" them).
2467
2468 Returns a `relationship dict`_ reflecting the updated following status.
2469 """
2470 id = self.__unpack_id(id)
2471 return self.__api_request('POST', '/api/v1/accounts/{0}/remove_from_followers'.format(str(id)))
2472
2462 2473
2463 @api_version("1.0.0", "1.4.0", __DICT_VERSION_RELATIONSHIP) 2474 @api_version("1.0.0", "1.4.0", __DICT_VERSION_RELATIONSHIP)
2464 def account_block(self, id): 2475 def account_block(self, id):
@@ -3618,16 +3629,14 @@ class Mastodon:
3618 raise NotImplementedError( 3629 raise NotImplementedError(
3619 'To use the crypto tools, please install the webpush feature dependencies.') 3630 'To use the crypto tools, please install the webpush feature dependencies.')
3620 3631
3621 push_key_pair = ec.generate_private_key( 3632 push_key_pair = ec.generate_private_key(ec.SECP256R1(), default_backend())
3622 ec.SECP256R1(), default_backend())
3623 push_key_priv = push_key_pair.private_numbers().private_value 3633 push_key_priv = push_key_pair.private_numbers().private_value
3624 3634
3625 crypto_ver = cryptography.__version__ 3635 crypto_ver = cryptography.__version__
3626 if len(crypto_ver) < 5: 3636 if len(crypto_ver) < 5:
3627 crypto_ver += ".0" 3637 crypto_ver += ".0"
3628 if bigger_version(crypto_ver, "2.5.0") == crypto_ver: 3638 if bigger_version(crypto_ver, "2.5.0") == crypto_ver:
3629 push_key_pub = push_key_pair.public_key().public_bytes( 3639 push_key_pub = push_key_pair.public_key().public_bytes(serialization.Encoding.X962, serialization.PublicFormat.UncompressedPoint)
3630 serialization.Encoding.X962, serialization.PublicFormat.UncompressedPoint)
3631 else: 3640 else:
3632 push_key_pub = push_key_pair.public_key().public_numbers().encode_point() 3641 push_key_pub = push_key_pair.public_key().public_numbers().encode_point()
3633 push_shared_secret = os.urandom(16) 3642 push_shared_secret = os.urandom(16)
@@ -3657,14 +3666,10 @@ class Mastodon:
3657 raise NotImplementedError( 3666 raise NotImplementedError(
3658 'To use the crypto tools, please install the webpush feature dependencies.') 3667 'To use the crypto tools, please install the webpush feature dependencies.')
3659 3668
3660 salt = self.__decode_webpush_b64( 3669 salt = self.__decode_webpush_b64(encryption_header.split("salt=")[1].strip())
3661 encryption_header.split("salt=")[1].strip()) 3670 dhparams = self.__decode_webpush_b64(crypto_key_header.split("dh=")[1].split(";")[0].strip())
3662 dhparams = self.__decode_webpush_b64( 3671 p256ecdsa = self.__decode_webpush_b64(crypto_key_header.split("p256ecdsa=")[1].strip())
3663 crypto_key_header.split("dh=")[1].split(";")[0].strip()) 3672 dec_key = ec.derive_private_key(decrypt_params['privkey'], ec.SECP256R1(), default_backend())
3664 p256ecdsa = self.__decode_webpush_b64(
3665 crypto_key_header.split("p256ecdsa=")[1].strip())
3666 dec_key = ec.derive_private_key(
3667 decrypt_params['privkey'], ec.SECP256R1(), default_backend())
3668 decrypted = http_ece.decrypt( 3673 decrypted = http_ece.decrypt(
3669 data, 3674 data,
3670 salt=salt, 3675 salt=salt,
@@ -3703,8 +3708,7 @@ class Mastodon:
3703 'To use the blurhash functions, please install the blurhash Python module.') 3708 'To use the blurhash functions, please install the blurhash Python module.')
3704 3709
3705 # Figure out what size to decode to 3710 # Figure out what size to decode to
3706 decode_components_x, decode_components_y = blurhash.components( 3711 decode_components_x, decode_components_y = blurhash.components(media_dict["blurhash"])
3707 media_dict["blurhash"])
3708 if size_per_component: 3712 if size_per_component:
3709 decode_size_x = decode_components_x * out_size[0] 3713 decode_size_x = decode_components_x * out_size[0]
3710 decode_size_y = decode_components_y * out_size[1] 3714 decode_size_y = decode_components_y * out_size[1]
@@ -3713,8 +3717,7 @@ class Mastodon:
3713 decode_size_y = out_size[1] 3717 decode_size_y = out_size[1]
3714 3718
3715 # Decode 3719 # Decode
3716 decoded_image = blurhash.decode( 3720 decoded_image = blurhash.decode(media_dict["blurhash"], decode_size_x, decode_size_y, linear=return_linear)
3717 media_dict["blurhash"], decode_size_x, decode_size_y, linear=return_linear)
3718 3721
3719 # And that's pretty much it. 3722 # And that's pretty much it.
3720 return decoded_image 3723 return decoded_image
Powered by cgit v1.2.3 (git 2.41.0)