diff options
author | Miroslav Šedivý <[email protected]> | 2022-11-20 20:22:48 +0100 |
---|---|---|
committer | Miroslav Šedivý <[email protected]> | 2022-11-20 20:22:48 +0100 |
commit | f04d57acbc5ef639c0dc70fde800cf5c24d0b967 (patch) | |
tree | 7fd8ad2031c281ac2a7cbc297fb20edd2fa4152e /mastodon | |
parent | 762861f3447698c6954016cf003758693dcc8bcc (diff) | |
download | mastodon.py-f04d57acbc5ef639c0dc70fde800cf5c24d0b967.tar.gz |
refactor: use is for True/False
Diffstat (limited to 'mastodon')
-rw-r--r-- | mastodon/Mastodon.py | 69 |
1 files changed, 33 insertions, 36 deletions
diff --git a/mastodon/Mastodon.py b/mastodon/Mastodon.py index bbd06be..72eb727 100644 --- a/mastodon/Mastodon.py +++ b/mastodon/Mastodon.py | |||
@@ -632,7 +632,7 @@ class Mastodon: | |||
632 | self.__logged_in_id = None | 632 | self.__logged_in_id = None |
633 | 633 | ||
634 | # Retry version check if needed (might be required in limited federation mode) | 634 | # Retry version check if needed (might be required in limited federation mode) |
635 | if self.version_check_worked == False: | 635 | if not self.version_check_worked: |
636 | self.retrieve_mastodon_version() | 636 | self.retrieve_mastodon_version() |
637 | 637 | ||
638 | return response['access_token'] | 638 | return response['access_token'] |
@@ -698,7 +698,7 @@ class Mastodon: | |||
698 | params['client_id'] = self.client_id | 698 | params['client_id'] = self.client_id |
699 | params['client_secret'] = self.client_secret | 699 | params['client_secret'] = self.client_secret |
700 | 700 | ||
701 | if agreement == False: | 701 | if not agreement: |
702 | del params['agreement'] | 702 | del params['agreement'] |
703 | 703 | ||
704 | # Step 1: Get a user-free token via oauth | 704 | # Step 1: Get a user-free token via oauth |
@@ -876,13 +876,13 @@ class Mastodon: | |||
876 | 876 | ||
877 | params_initial = locals() | 877 | params_initial = locals() |
878 | 878 | ||
879 | if local == False: | 879 | if not local: |
880 | del params_initial['local'] | 880 | del params_initial['local'] |
881 | 881 | ||
882 | if remote == False: | 882 | if not remote: |
883 | del params_initial['remote'] | 883 | del params_initial['remote'] |
884 | 884 | ||
885 | if only_media == False: | 885 | if not only_media: |
886 | del params_initial['only_media'] | 886 | del params_initial['only_media'] |
887 | 887 | ||
888 | if timeline == "local": | 888 | if timeline == "local": |
@@ -1188,13 +1188,13 @@ class Mastodon: | |||
1188 | since_id = self.__unpack_id(since_id, dateconv=True) | 1188 | since_id = self.__unpack_id(since_id, dateconv=True) |
1189 | 1189 | ||
1190 | params = self.__generate_params(locals(), ['id']) | 1190 | params = self.__generate_params(locals(), ['id']) |
1191 | if pinned == False: | 1191 | if not pinned: |
1192 | del params["pinned"] | 1192 | del params["pinned"] |
1193 | if only_media == False: | 1193 | if not only_media: |
1194 | del params["only_media"] | 1194 | del params["only_media"] |
1195 | if exclude_replies == False: | 1195 | if not exclude_replies: |
1196 | del params["exclude_replies"] | 1196 | del params["exclude_replies"] |
1197 | if exclude_reblogs == False: | 1197 | if not exclude_reblogs: |
1198 | del params["exclude_reblogs"] | 1198 | del params["exclude_reblogs"] |
1199 | 1199 | ||
1200 | url = '/api/v1/accounts/{0}/statuses'.format(str(id)) | 1200 | url = '/api/v1/accounts/{0}/statuses'.format(str(id)) |
@@ -1359,7 +1359,7 @@ class Mastodon: | |||
1359 | continue | 1359 | continue |
1360 | 1360 | ||
1361 | filter_string = re.escape(keyword_filter["phrase"]) | 1361 | filter_string = re.escape(keyword_filter["phrase"]) |
1362 | if keyword_filter["whole_word"] == True: | 1362 | if keyword_filter["whole_word"]: |
1363 | filter_string = "\\b" + filter_string + "\\b" | 1363 | filter_string = "\\b" + filter_string + "\\b" |
1364 | filter_strings.append(filter_string) | 1364 | filter_strings.append(filter_string) |
1365 | filter_re = re.compile("|".join(filter_strings), flags=re.IGNORECASE) | 1365 | filter_re = re.compile("|".join(filter_strings), flags=re.IGNORECASE) |
@@ -1426,7 +1426,7 @@ class Mastodon: | |||
1426 | for search that are available only starting with 2.8.0 are specified. | 1426 | for search that are available only starting with 2.8.0 are specified. |
1427 | """ | 1427 | """ |
1428 | if any(item is not None for item in (account_id, offset, min_id, max_id)): | 1428 | if any(item is not None for item in (account_id, offset, min_id, max_id)): |
1429 | if self.verify_minimum_version("2.8.0", cached=True) == False: | 1429 | if not self.verify_minimum_version("2.8.0", cached=True): |
1430 | raise MastodonVersionError("Advanced search parameters require Mastodon 2.8.0+") | 1430 | raise MastodonVersionError("Advanced search parameters require Mastodon 2.8.0+") |
1431 | 1431 | ||
1432 | @api_version("1.1.0", "2.8.0", __DICT_VERSION_SEARCHRESULT) | 1432 | @api_version("1.1.0", "2.8.0", __DICT_VERSION_SEARCHRESULT) |
@@ -1455,7 +1455,7 @@ class Mastodon: | |||
1455 | 1455 | ||
1456 | Returns a `search result dict`_, with tags as `hashtag dicts`_. | 1456 | Returns a `search result dict`_, with tags as `hashtag dicts`_. |
1457 | """ | 1457 | """ |
1458 | if self.verify_minimum_version("2.4.1", cached=True) == True: | 1458 | if self.verify_minimum_version("2.4.1", cached=True): |
1459 | return self.search_v2(q, resolve=resolve, result_type=result_type, account_id=account_id, offset=offset, min_id=min_id, max_id=max_id) | 1459 | return self.search_v2(q, resolve=resolve, result_type=result_type, account_id=account_id, offset=offset, min_id=min_id, max_id=max_id) |
1460 | else: | 1460 | else: |
1461 | self.__ensure_search_params_acceptable( | 1461 | self.__ensure_search_params_acceptable( |
@@ -1471,7 +1471,7 @@ class Mastodon: | |||
1471 | Returns a `search result dict`_. | 1471 | Returns a `search result dict`_. |
1472 | """ | 1472 | """ |
1473 | params = self.__generate_params(locals()) | 1473 | params = self.__generate_params(locals()) |
1474 | if resolve == False: | 1474 | if not resolve: |
1475 | del params['resolve'] | 1475 | del params['resolve'] |
1476 | return self.__api_request('GET', '/api/v1/search', params) | 1476 | return self.__api_request('GET', '/api/v1/search', params) |
1477 | 1477 | ||
@@ -1489,10 +1489,10 @@ class Mastodon: | |||
1489 | account_id, offset, min_id, max_id) | 1489 | account_id, offset, min_id, max_id) |
1490 | params = self.__generate_params(locals()) | 1490 | params = self.__generate_params(locals()) |
1491 | 1491 | ||
1492 | if resolve == False: | 1492 | if not resolve: |
1493 | del params["resolve"] | 1493 | del params["resolve"] |
1494 | 1494 | ||
1495 | if exclude_unreviewed == False or not self.verify_minimum_version("3.0.0", cached=True): | 1495 | if not exclude_unreviewed or not self.verify_minimum_version("3.0.0", cached=True): |
1496 | del params["exclude_unreviewed"] | 1496 | del params["exclude_unreviewed"] |
1497 | 1497 | ||
1498 | if "result_type" in params: | 1498 | if "result_type" in params: |
@@ -2587,7 +2587,7 @@ class Mastodon: | |||
2587 | status_ids = list(map(lambda x: self.__unpack_id(x), status_ids)) | 2587 | status_ids = list(map(lambda x: self.__unpack_id(x), status_ids)) |
2588 | 2588 | ||
2589 | params_initial = locals() | 2589 | params_initial = locals() |
2590 | if forward == False: | 2590 | if not forward: |
2591 | del params_initial['forward'] | 2591 | del params_initial['forward'] |
2592 | 2592 | ||
2593 | params = self.__generate_params(params_initial) | 2593 | params = self.__generate_params(params_initial) |
@@ -2953,7 +2953,7 @@ class Mastodon: | |||
2953 | params = self.__generate_params( | 2953 | params = self.__generate_params( |
2954 | locals(), ['remote', 'status', 'staff_only']) | 2954 | locals(), ['remote', 'status', 'staff_only']) |
2955 | 2955 | ||
2956 | if remote == True: | 2956 | if remote: |
2957 | params["remote"] = True | 2957 | params["remote"] = True |
2958 | 2958 | ||
2959 | mod_statuses = ["active", "pending", | 2959 | mod_statuses = ["active", "pending", |
@@ -2961,7 +2961,7 @@ class Mastodon: | |||
2961 | if not status in mod_statuses: | 2961 | if not status in mod_statuses: |
2962 | raise ValueError("Invalid moderation status requested.") | 2962 | raise ValueError("Invalid moderation status requested.") |
2963 | 2963 | ||
2964 | if staff_only == True: | 2964 | if staff_only: |
2965 | params["staff"] = True | 2965 | params["staff"] = True |
2966 | 2966 | ||
2967 | for mod_status in mod_statuses: | 2967 | for mod_status in mod_statuses: |
@@ -3073,7 +3073,7 @@ class Mastodon: | |||
3073 | if action is None: | 3073 | if action is None: |
3074 | action = "none" | 3074 | action = "none" |
3075 | 3075 | ||
3076 | if send_email_notification == False: | 3076 | if not send_email_notification: |
3077 | send_email_notification = None | 3077 | send_email_notification = None |
3078 | 3078 | ||
3079 | id = self.__unpack_id(id) | 3079 | id = self.__unpack_id(id) |
@@ -3112,7 +3112,7 @@ class Mastodon: | |||
3112 | if target_account_id is not None: | 3112 | if target_account_id is not None: |
3113 | target_account_id = self.__unpack_id(target_account_id) | 3113 | target_account_id = self.__unpack_id(target_account_id) |
3114 | 3114 | ||
3115 | if resolved == False: | 3115 | if not resolved: |
3116 | resolved = None | 3116 | resolved = None |
3117 | 3117 | ||
3118 | params = self.__generate_params(locals()) | 3118 | params = self.__generate_params(locals()) |
@@ -3269,12 +3269,12 @@ class Mastodon: | |||
3269 | # Figure out what size to decode to | 3269 | # Figure out what size to decode to |
3270 | decode_components_x, decode_components_y = blurhash.components( | 3270 | decode_components_x, decode_components_y = blurhash.components( |
3271 | media_dict["blurhash"]) | 3271 | media_dict["blurhash"]) |
3272 | if size_per_component == False: | 3272 | if size_per_component: |
3273 | decode_size_x = out_size[0] | ||
3274 | decode_size_y = out_size[1] | ||
3275 | else: | ||
3276 | decode_size_x = decode_components_x * out_size[0] | 3273 | decode_size_x = decode_components_x * out_size[0] |
3277 | decode_size_y = decode_components_y * out_size[1] | 3274 | decode_size_y = decode_components_y * out_size[1] |
3275 | else: | ||
3276 | decode_size_x = out_size[0] | ||
3277 | decode_size_y = out_size[1] | ||
3278 | 3278 | ||
3279 | # Decode | 3279 | # Decode |
3280 | decoded_image = blurhash.decode( | 3280 | decoded_image = blurhash.decode( |
@@ -3584,13 +3584,12 @@ class Mastodon: | |||
3584 | response_object = None | 3584 | response_object = None |
3585 | try: | 3585 | try: |
3586 | kwargs = dict(headers=headers, files=files, timeout=self.request_timeout) | 3586 | kwargs = dict(headers=headers, files=files, timeout=self.request_timeout) |
3587 | if use_json == False: | 3587 | if use_json: |
3588 | if method == 'GET': | ||
3589 | kwargs['params'] = params | ||
3590 | else: | ||
3591 | kwargs['data'] = params | ||
3592 | else: | ||
3593 | kwargs['json'] = params | 3588 | kwargs['json'] = params |
3589 | elif method == 'GET': | ||
3590 | kwargs['params'] = params | ||
3591 | else: | ||
3592 | kwargs['data'] = params | ||
3594 | 3593 | ||
3595 | # Block list with exactly three entries, matching on hashes of the instance API domain | 3594 | # Block list with exactly three entries, matching on hashes of the instance API domain |
3596 | # For more information, have a look at the docs | 3595 | # For more information, have a look at the docs |
@@ -3679,7 +3678,7 @@ class Mastodon: | |||
3679 | request_complete = False | 3678 | request_complete = False |
3680 | continue | 3679 | continue |
3681 | 3680 | ||
3682 | if skip_error_check == False: | 3681 | if not skip_error_check: |
3683 | if response_object.status_code == 404: | 3682 | if response_object.status_code == 404: |
3684 | ex_type = MastodonNotFoundError | 3683 | ex_type = MastodonNotFoundError |
3685 | if not error_msg: | 3684 | if not error_msg: |
@@ -3708,7 +3707,7 @@ class Mastodon: | |||
3708 | if return_response_object: | 3707 | if return_response_object: |
3709 | return response_object | 3708 | return response_object |
3710 | 3709 | ||
3711 | if parse == True: | 3710 | if parse: |
3712 | try: | 3711 | try: |
3713 | response = response_object.json( | 3712 | response = response_object.json( |
3714 | object_hook=self.__json_hooks) | 3713 | object_hook=self.__json_hooks) |
@@ -3968,10 +3967,8 @@ class Mastodon: | |||
3968 | 3967 | ||
3969 | param_keys = list(params.keys()) | 3968 | param_keys = list(params.keys()) |
3970 | for key in param_keys: | 3969 | for key in param_keys: |
3971 | if isinstance(params[key], bool) and params[key] == False: | 3970 | if isinstance(params[key], bool): |
3972 | params[key] = '0' | 3971 | params[key] = '1' if params[key] else '0' |
3973 | if isinstance(params[key], bool) and params[key] == True: | ||
3974 | params[key] = '1' | ||
3975 | 3972 | ||
3976 | for key in param_keys: | 3973 | for key in param_keys: |
3977 | if params[key] is None or key in exclude: | 3974 | if params[key] is None or key in exclude: |