aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiroslav Šedivý <[email protected]>2022-11-20 20:14:25 +0100
committerMiroslav Šedivý <[email protected]>2022-11-20 20:14:25 +0100
commit762861f3447698c6954016cf003758693dcc8bcc (patch)
treea43554b51e631bc62aa622fb0cf422d372303caa /mastodon
parent98760f650bcaafedead3f0b6e2b0c594ab857338 (diff)
downloadmastodon.py-762861f3447698c6954016cf003758693dcc8bcc.tar.gz
refactor: use is for None
Diffstat (limited to 'mastodon')
-rw-r--r--mastodon/Mastodon.py200
-rw-r--r--mastodon/streaming.py14
2 files changed, 107 insertions, 107 deletions
diff --git a/mastodon/Mastodon.py b/mastodon/Mastodon.py
index 70aac20..bbd06be 100644
--- a/mastodon/Mastodon.py
+++ b/mastodon/Mastodon.py
@@ -378,7 +378,7 @@ class Mastodon:
378 If no other `User-Agent` is specified, "mastodonpy" will be used. 378 If no other `User-Agent` is specified, "mastodonpy" will be used.
379 """ 379 """
380 self.api_base_url = None 380 self.api_base_url = None
381 if not api_base_url is None: 381 if api_base_url is not None:
382 self.api_base_url = Mastodon.__protocolize(api_base_url) 382 self.api_base_url = Mastodon.__protocolize(api_base_url)
383 383
384 self.client_id = client_id 384 self.client_id = client_id
@@ -419,7 +419,7 @@ class Mastodon:
419 self.client_secret = secret_file.readline().rstrip() 419 self.client_secret = secret_file.readline().rstrip()
420 420
421 try_base_url = secret_file.readline().rstrip() 421 try_base_url = secret_file.readline().rstrip()
422 if (not try_base_url is None) and len(try_base_url) != 0: 422 if try_base_url is not None and len(try_base_url) != 0:
423 try_base_url = Mastodon.__protocolize(try_base_url) 423 try_base_url = Mastodon.__protocolize(try_base_url)
424 if not (self.api_base_url is None or try_base_url == self.api_base_url): 424 if not (self.api_base_url is None or try_base_url == self.api_base_url):
425 raise MastodonIllegalArgumentError( 425 raise MastodonIllegalArgumentError(
@@ -440,7 +440,7 @@ class Mastodon:
440 self.access_token = token_file.readline().rstrip() 440 self.access_token = token_file.readline().rstrip()
441 441
442 try_base_url = token_file.readline().rstrip() 442 try_base_url = token_file.readline().rstrip()
443 if (not try_base_url is None) and len(try_base_url) != 0: 443 if try_base_url is not None and len(try_base_url) != 0:
444 try_base_url = Mastodon.__protocolize(try_base_url) 444 try_base_url = Mastodon.__protocolize(try_base_url)
445 if not (self.api_base_url is None or try_base_url == self.api_base_url): 445 if not (self.api_base_url is None or try_base_url == self.api_base_url):
446 raise MastodonIllegalArgumentError( 446 raise MastodonIllegalArgumentError(
@@ -457,7 +457,7 @@ class Mastodon:
457 self.version_check_worked = None 457 self.version_check_worked = None
458 458
459 # Versioning 459 # Versioning
460 if mastodon_version == None and self.version_check_mode != 'none': 460 if mastodon_version is None and self.version_check_mode != 'none':
461 self.retrieve_mastodon_version() 461 self.retrieve_mastodon_version()
462 elif self.version_check_mode != 'none': 462 elif self.version_check_mode != 'none':
463 try: 463 try:
@@ -865,13 +865,13 @@ class Mastodon:
865 865
866 Returns a list of `toot dicts`_. 866 Returns a list of `toot dicts`_.
867 """ 867 """
868 if max_id != None: 868 if max_id is not None:
869 max_id = self.__unpack_id(max_id, dateconv=True) 869 max_id = self.__unpack_id(max_id, dateconv=True)
870 870
871 if min_id != None: 871 if min_id is not None:
872 min_id = self.__unpack_id(min_id, dateconv=True) 872 min_id = self.__unpack_id(min_id, dateconv=True)
873 873
874 if since_id != None: 874 if since_id is not None:
875 since_id = self.__unpack_id(since_id, dateconv=True) 875 since_id = self.__unpack_id(since_id, dateconv=True)
876 876
877 params_initial = locals() 877 params_initial = locals()
@@ -950,13 +950,13 @@ class Mastodon:
950 950
951 Returns a list of `conversation dicts`_. 951 Returns a list of `conversation dicts`_.
952 """ 952 """
953 if max_id != None: 953 if max_id is not None:
954 max_id = self.__unpack_id(max_id, dateconv=True) 954 max_id = self.__unpack_id(max_id, dateconv=True)
955 955
956 if min_id != None: 956 if min_id is not None:
957 min_id = self.__unpack_id(min_id, dateconv=True) 957 min_id = self.__unpack_id(min_id, dateconv=True)
958 958
959 if since_id != None: 959 if since_id is not None:
960 since_id = self.__unpack_id(since_id, dateconv=True) 960 since_id = self.__unpack_id(since_id, dateconv=True)
961 961
962 params = self.__generate_params(locals()) 962 params = self.__generate_params(locals())
@@ -1093,8 +1093,8 @@ class Mastodon:
1093 1093
1094 Returns a list of `notification dicts`_. 1094 Returns a list of `notification dicts`_.
1095 """ 1095 """
1096 if not mentions_only is None: 1096 if mentions_only is not None:
1097 if not exclude_types is None: 1097 if exclude_types is not None:
1098 if mentions_only: 1098 if mentions_only:
1099 exclude_types = ["follow", "favourite", 1099 exclude_types = ["follow", "favourite",
1100 "reblog", "poll", "follow_request"] 1100 "reblog", "poll", "follow_request"]
@@ -1103,16 +1103,16 @@ class Mastodon:
1103 'Cannot specify exclude_types when mentions_only is present') 1103 'Cannot specify exclude_types when mentions_only is present')
1104 del mentions_only 1104 del mentions_only
1105 1105
1106 if max_id != None: 1106 if max_id is not None:
1107 max_id = self.__unpack_id(max_id, dateconv=True) 1107 max_id = self.__unpack_id(max_id, dateconv=True)
1108 1108
1109 if min_id != None: 1109 if min_id is not None:
1110 min_id = self.__unpack_id(min_id, dateconv=True) 1110 min_id = self.__unpack_id(min_id, dateconv=True)
1111 1111
1112 if since_id != None: 1112 if since_id is not None:
1113 since_id = self.__unpack_id(since_id, dateconv=True) 1113 since_id = self.__unpack_id(since_id, dateconv=True)
1114 1114
1115 if account_id != None: 1115 if account_id is not None:
1116 account_id = self.__unpack_id(account_id) 1116 account_id = self.__unpack_id(account_id)
1117 1117
1118 if id is None: 1118 if id is None:
@@ -1178,13 +1178,13 @@ class Mastodon:
1178 Returns a list of `toot dicts`_. 1178 Returns a list of `toot dicts`_.
1179 """ 1179 """
1180 id = self.__unpack_id(id) 1180 id = self.__unpack_id(id)
1181 if max_id != None: 1181 if max_id is not None:
1182 max_id = self.__unpack_id(max_id, dateconv=True) 1182 max_id = self.__unpack_id(max_id, dateconv=True)
1183 1183
1184 if min_id != None: 1184 if min_id is not None:
1185 min_id = self.__unpack_id(min_id, dateconv=True) 1185 min_id = self.__unpack_id(min_id, dateconv=True)
1186 1186
1187 if since_id != None: 1187 if since_id is not None:
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'])
@@ -1208,13 +1208,13 @@ class Mastodon:
1208 Returns a list of `user dicts`_. 1208 Returns a list of `user dicts`_.
1209 """ 1209 """
1210 id = self.__unpack_id(id) 1210 id = self.__unpack_id(id)
1211 if max_id != None: 1211 if max_id is not None:
1212 max_id = self.__unpack_id(max_id, dateconv=True) 1212 max_id = self.__unpack_id(max_id, dateconv=True)
1213 1213
1214 if min_id != None: 1214 if min_id is not None:
1215 min_id = self.__unpack_id(min_id, dateconv=True) 1215 min_id = self.__unpack_id(min_id, dateconv=True)
1216 1216
1217 if since_id != None: 1217 if since_id is not None:
1218 since_id = self.__unpack_id(since_id, dateconv=True) 1218 since_id = self.__unpack_id(since_id, dateconv=True)
1219 1219
1220 params = self.__generate_params(locals(), ['id']) 1220 params = self.__generate_params(locals(), ['id'])
@@ -1229,13 +1229,13 @@ class Mastodon:
1229 Returns a list of `user dicts`_. 1229 Returns a list of `user dicts`_.
1230 """ 1230 """
1231 id = self.__unpack_id(id) 1231 id = self.__unpack_id(id)
1232 if max_id != None: 1232 if max_id is not None:
1233 max_id = self.__unpack_id(max_id, dateconv=True) 1233 max_id = self.__unpack_id(max_id, dateconv=True)
1234 1234
1235 if min_id != None: 1235 if min_id is not None:
1236 min_id = self.__unpack_id(min_id, dateconv=True) 1236 min_id = self.__unpack_id(min_id, dateconv=True)
1237 1237
1238 if since_id != None: 1238 if since_id is not None:
1239 since_id = self.__unpack_id(since_id, dateconv=True) 1239 since_id = self.__unpack_id(since_id, dateconv=True)
1240 1240
1241 params = self.__generate_params(locals(), ['id']) 1241 params = self.__generate_params(locals(), ['id'])
@@ -1425,7 +1425,7 @@ class Mastodon:
1425 Internal Helper: Throw a MastodonVersionError if version is < 2.8.0 but parameters 1425 Internal Helper: Throw a MastodonVersionError if version is < 2.8.0 but parameters
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 not account_id is None or not offset is None or not min_id is None or not max_id is None: 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 self.verify_minimum_version("2.8.0", cached=True) == False:
1430 raise MastodonVersionError("Advanced search parameters require Mastodon 2.8.0+") 1430 raise MastodonVersionError("Advanced search parameters require Mastodon 2.8.0+")
1431 1431
@@ -1554,13 +1554,13 @@ class Mastodon:
1554 """ 1554 """
1555 id = self.__unpack_id(id) 1555 id = self.__unpack_id(id)
1556 1556
1557 if max_id != None: 1557 if max_id is not None:
1558 max_id = self.__unpack_id(max_id, dateconv=True) 1558 max_id = self.__unpack_id(max_id, dateconv=True)
1559 1559
1560 if min_id != None: 1560 if min_id is not None:
1561 min_id = self.__unpack_id(min_id, dateconv=True) 1561 min_id = self.__unpack_id(min_id, dateconv=True)
1562 1562
1563 if since_id != None: 1563 if since_id is not None:
1564 since_id = self.__unpack_id(since_id, dateconv=True) 1564 since_id = self.__unpack_id(since_id, dateconv=True)
1565 1565
1566 params = self.__generate_params(locals(), ['id']) 1566 params = self.__generate_params(locals(), ['id'])
@@ -1576,13 +1576,13 @@ class Mastodon:
1576 1576
1577 Returns a list of `user dicts`_. 1577 Returns a list of `user dicts`_.
1578 """ 1578 """
1579 if max_id != None: 1579 if max_id is not None:
1580 max_id = self.__unpack_id(max_id, dateconv=True) 1580 max_id = self.__unpack_id(max_id, dateconv=True)
1581 1581
1582 if min_id != None: 1582 if min_id is not None:
1583 min_id = self.__unpack_id(min_id, dateconv=True) 1583 min_id = self.__unpack_id(min_id, dateconv=True)
1584 1584
1585 if since_id != None: 1585 if since_id is not None:
1586 since_id = self.__unpack_id(since_id, dateconv=True) 1586 since_id = self.__unpack_id(since_id, dateconv=True)
1587 1587
1588 params = self.__generate_params(locals()) 1588 params = self.__generate_params(locals())
@@ -1595,13 +1595,13 @@ class Mastodon:
1595 1595
1596 Returns a list of `user dicts`_. 1596 Returns a list of `user dicts`_.
1597 """ 1597 """
1598 if max_id != None: 1598 if max_id is not None:
1599 max_id = self.__unpack_id(max_id, dateconv=True) 1599 max_id = self.__unpack_id(max_id, dateconv=True)
1600 1600
1601 if min_id != None: 1601 if min_id is not None:
1602 min_id = self.__unpack_id(min_id, dateconv=True) 1602 min_id = self.__unpack_id(min_id, dateconv=True)
1603 1603
1604 if since_id != None: 1604 if since_id is not None:
1605 since_id = self.__unpack_id(since_id, dateconv=True) 1605 since_id = self.__unpack_id(since_id, dateconv=True)
1606 1606
1607 params = self.__generate_params(locals()) 1607 params = self.__generate_params(locals())
@@ -1632,13 +1632,13 @@ class Mastodon:
1632 1632
1633 Returns a list of `toot dicts`_. 1633 Returns a list of `toot dicts`_.
1634 """ 1634 """
1635 if max_id != None: 1635 if max_id is not None:
1636 max_id = self.__unpack_id(max_id, dateconv=True) 1636 max_id = self.__unpack_id(max_id, dateconv=True)
1637 1637
1638 if min_id != None: 1638 if min_id is not None:
1639 min_id = self.__unpack_id(min_id, dateconv=True) 1639 min_id = self.__unpack_id(min_id, dateconv=True)
1640 1640
1641 if since_id != None: 1641 if since_id is not None:
1642 since_id = self.__unpack_id(since_id, dateconv=True) 1642 since_id = self.__unpack_id(since_id, dateconv=True)
1643 1643
1644 params = self.__generate_params(locals()) 1644 params = self.__generate_params(locals())
@@ -1654,13 +1654,13 @@ class Mastodon:
1654 1654
1655 Returns a list of `user dicts`_. 1655 Returns a list of `user dicts`_.
1656 """ 1656 """
1657 if max_id != None: 1657 if max_id is not None:
1658 max_id = self.__unpack_id(max_id, dateconv=True) 1658 max_id = self.__unpack_id(max_id, dateconv=True)
1659 1659
1660 if min_id != None: 1660 if min_id is not None:
1661 min_id = self.__unpack_id(min_id, dateconv=True) 1661 min_id = self.__unpack_id(min_id, dateconv=True)
1662 1662
1663 if since_id != None: 1663 if since_id is not None:
1664 since_id = self.__unpack_id(since_id, dateconv=True) 1664 since_id = self.__unpack_id(since_id, dateconv=True)
1665 1665
1666 params = self.__generate_params(locals()) 1666 params = self.__generate_params(locals())
@@ -1676,13 +1676,13 @@ class Mastodon:
1676 1676
1677 Returns a list of blocked domain URLs (as strings, without protocol specifier). 1677 Returns a list of blocked domain URLs (as strings, without protocol specifier).
1678 """ 1678 """
1679 if max_id != None: 1679 if max_id is not None:
1680 max_id = self.__unpack_id(max_id, dateconv=True) 1680 max_id = self.__unpack_id(max_id, dateconv=True)
1681 1681
1682 if min_id != None: 1682 if min_id is not None:
1683 min_id = self.__unpack_id(min_id, dateconv=True) 1683 min_id = self.__unpack_id(min_id, dateconv=True)
1684 1684
1685 if since_id != None: 1685 if since_id is not None:
1686 since_id = self.__unpack_id(since_id, dateconv=True) 1686 since_id = self.__unpack_id(since_id, dateconv=True)
1687 1687
1688 params = self.__generate_params(locals()) 1688 params = self.__generate_params(locals())
@@ -1782,13 +1782,13 @@ class Mastodon:
1782 1782
1783 Returns a list of `toot dicts`_. 1783 Returns a list of `toot dicts`_.
1784 """ 1784 """
1785 if max_id != None: 1785 if max_id is not None:
1786 max_id = self.__unpack_id(max_id, dateconv=True) 1786 max_id = self.__unpack_id(max_id, dateconv=True)
1787 1787
1788 if min_id != None: 1788 if min_id is not None:
1789 min_id = self.__unpack_id(min_id, dateconv=True) 1789 min_id = self.__unpack_id(min_id, dateconv=True)
1790 1790
1791 if since_id != None: 1791 if since_id is not None:
1792 since_id = self.__unpack_id(since_id, dateconv=True) 1792 since_id = self.__unpack_id(since_id, dateconv=True)
1793 1793
1794 params = self.__generate_params(locals()) 1794 params = self.__generate_params(locals())
@@ -1857,13 +1857,13 @@ class Mastodon:
1857 1857
1858 Returns a `toot dict`_ with the new status. 1858 Returns a `toot dict`_ with the new status.
1859 """ 1859 """
1860 if quote_id != None: 1860 if quote_id is not None:
1861 if self.feature_set != "fedibird": 1861 if self.feature_set != "fedibird":
1862 raise MastodonIllegalArgumentError( 1862 raise MastodonIllegalArgumentError(
1863 'quote_id is only available with feature set fedibird') 1863 'quote_id is only available with feature set fedibird')
1864 quote_id = self.__unpack_id(quote_id) 1864 quote_id = self.__unpack_id(quote_id)
1865 1865
1866 if content_type != None: 1866 if content_type is not None:
1867 if self.feature_set != "pleroma": 1867 if self.feature_set != "pleroma":
1868 raise MastodonIllegalArgumentError( 1868 raise MastodonIllegalArgumentError(
1869 'content_type is only available with feature set pleroma') 1869 'content_type is only available with feature set pleroma')
@@ -1872,23 +1872,23 @@ class Mastodon:
1872 raise MastodonIllegalArgumentError( 1872 raise MastodonIllegalArgumentError(
1873 'Invalid content type specified') 1873 'Invalid content type specified')
1874 1874
1875 if in_reply_to_id != None: 1875 if in_reply_to_id is not None:
1876 in_reply_to_id = self.__unpack_id(in_reply_to_id) 1876 in_reply_to_id = self.__unpack_id(in_reply_to_id)
1877 1877
1878 if scheduled_at != None: 1878 if scheduled_at is not None:
1879 scheduled_at = self.__consistent_isoformat_utc(scheduled_at) 1879 scheduled_at = self.__consistent_isoformat_utc(scheduled_at)
1880 1880
1881 params_initial = locals() 1881 params_initial = locals()
1882 1882
1883 # Validate poll/media exclusivity 1883 # Validate poll/media exclusivity
1884 if not poll is None: 1884 if poll is not None:
1885 if (not media_ids is None) and len(media_ids) != 0: 1885 if media_ids is not None and len(media_ids) != 0:
1886 raise ValueError( 1886 raise ValueError(
1887 'Status can have media or poll attached - not both.') 1887 'Status can have media or poll attached - not both.')
1888 1888
1889 # Validate visibility parameter 1889 # Validate visibility parameter
1890 valid_visibilities = ['private', 'public', 'unlisted', 'direct'] 1890 valid_visibilities = ['private', 'public', 'unlisted', 'direct']
1891 if params_initial['visibility'] == None: 1891 if params_initial['visibility'] is None:
1892 del params_initial['visibility'] 1892 del params_initial['visibility']
1893 else: 1893 else:
1894 params_initial['visibility'] = params_initial['visibility'].lower() 1894 params_initial['visibility'] = params_initial['visibility'].lower()
@@ -1896,14 +1896,14 @@ class Mastodon:
1896 raise ValueError('Invalid visibility value! Acceptable ' 1896 raise ValueError('Invalid visibility value! Acceptable '
1897 'values are %s' % valid_visibilities) 1897 'values are %s' % valid_visibilities)
1898 1898
1899 if params_initial['language'] == None: 1899 if params_initial['language'] is None:
1900 del params_initial['language'] 1900 del params_initial['language']
1901 1901
1902 if params_initial['sensitive'] is False: 1902 if params_initial['sensitive'] is False:
1903 del [params_initial['sensitive']] 1903 del [params_initial['sensitive']]
1904 1904
1905 headers = {} 1905 headers = {}
1906 if idempotency_key != None: 1906 if idempotency_key is not None:
1907 headers['Idempotency-Key'] = idempotency_key 1907 headers['Idempotency-Key'] = idempotency_key
1908 1908
1909 if media_ids is not None: 1909 if media_ids is not None:
@@ -1919,11 +1919,11 @@ class Mastodon:
1919 1919
1920 params_initial["media_ids"] = media_ids_proper 1920 params_initial["media_ids"] = media_ids_proper
1921 1921
1922 if params_initial['content_type'] == None: 1922 if params_initial['content_type'] is None:
1923 del params_initial['content_type'] 1923 del params_initial['content_type']
1924 1924
1925 use_json = False 1925 use_json = False
1926 if not poll is None: 1926 if poll is not None:
1927 use_json = True 1927 use_json = True
1928 1928
1929 params = self.__generate_params(params_initial, ['idempotency_key']) 1929 params = self.__generate_params(params_initial, ['idempotency_key'])
@@ -1975,9 +1975,9 @@ class Mastodon:
1975 mentioned_accounts.values())) + status 1975 mentioned_accounts.values())) + status
1976 1976
1977 # Retain visibility / cw 1977 # Retain visibility / cw
1978 if visibility == None and 'visibility' in to_status: 1978 if visibility is None and 'visibility' in to_status:
1979 visibility = to_status.visibility 1979 visibility = to_status.visibility
1980 if spoiler_text == None and 'spoiler_text' in to_status: 1980 if spoiler_text is None and 'spoiler_text' in to_status:
1981 spoiler_text = to_status.spoiler_text 1981 spoiler_text = to_status.spoiler_text
1982 1982
1983 keyword_args["status"] = status 1983 keyword_args["status"] = status
@@ -2243,7 +2243,7 @@ class Mastodon:
2243 id = self.__unpack_id(id) 2243 id = self.__unpack_id(id)
2244 params = self.__generate_params(locals()) 2244 params = self.__generate_params(locals())
2245 2245
2246 if params["reblogs"] == None: 2246 if params["reblogs"] is None:
2247 del params["reblogs"] 2247 del params["reblogs"]
2248 2248
2249 url = '/api/v1/accounts/{0}/follow'.format(str(id)) 2249 url = '/api/v1/accounts/{0}/follow'.format(str(id))
@@ -2347,7 +2347,7 @@ class Mastodon:
2347 params_initial = collections.OrderedDict(locals()) 2347 params_initial = collections.OrderedDict(locals())
2348 2348
2349 # Convert fields 2349 # Convert fields
2350 if fields != None: 2350 if fields is not None:
2351 if len(fields) > 4: 2351 if len(fields) > 4:
2352 raise MastodonIllegalArgumentError( 2352 raise MastodonIllegalArgumentError(
2353 'A maximum of four fields are allowed.') 2353 'A maximum of four fields are allowed.')
@@ -2366,9 +2366,9 @@ class Mastodon:
2366 2366
2367 # Create file info 2367 # Create file info
2368 files = {} 2368 files = {}
2369 if not avatar is None: 2369 if avatar is not None:
2370 files["avatar"] = self.__load_media_file(avatar, avatar_mime_type) 2370 files["avatar"] = self.__load_media_file(avatar, avatar_mime_type)
2371 if not header is None: 2371 if header is not None:
2372 files["header"] = self.__load_media_file(header, header_mime_type) 2372 files["header"] = self.__load_media_file(header, header_mime_type)
2373 2373
2374 params = self.__generate_params(params_initial) 2374 params = self.__generate_params(params_initial)
@@ -2581,7 +2581,7 @@ class Mastodon:
2581 """ 2581 """
2582 account_id = self.__unpack_id(account_id) 2582 account_id = self.__unpack_id(account_id)
2583 2583
2584 if not status_ids is None: 2584 if status_ids is not None:
2585 if not isinstance(status_ids, list): 2585 if not isinstance(status_ids, list):
2586 status_ids = [status_ids] 2586 status_ids = [status_ids]
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))
@@ -2653,10 +2653,10 @@ class Mastodon:
2653 files = {'file': self.__load_media_file( 2653 files = {'file': self.__load_media_file(
2654 media_file, mime_type, file_name)} 2654 media_file, mime_type, file_name)}
2655 2655
2656 if focus != None: 2656 if focus is not None:
2657 focus = str(focus[0]) + "," + str(focus[1]) 2657 focus = str(focus[0]) + "," + str(focus[1])
2658 2658
2659 if not thumbnail is None: 2659 if thumbnail is not None:
2660 if not self.verify_minimum_version("3.2.0", cached=True): 2660 if not self.verify_minimum_version("3.2.0", cached=True):
2661 raise MastodonVersionError( 2661 raise MastodonVersionError(
2662 'Thumbnail requires version > 3.2.0') 2662 'Thumbnail requires version > 3.2.0')
@@ -2674,7 +2674,7 @@ class Mastodon:
2674 # Wait for processing? 2674 # Wait for processing?
2675 if synchronous: 2675 if synchronous:
2676 if self.verify_minimum_version("3.1.4"): 2676 if self.verify_minimum_version("3.1.4"):
2677 while not "url" in ret_dict or ret_dict.url == None: 2677 while not "url" in ret_dict or ret_dict.url is None:
2678 try: 2678 try:
2679 ret_dict = self.media(ret_dict) 2679 ret_dict = self.media(ret_dict)
2680 time.sleep(1.0) 2680 time.sleep(1.0)
@@ -2697,13 +2697,13 @@ class Mastodon:
2697 """ 2697 """
2698 id = self.__unpack_id(id) 2698 id = self.__unpack_id(id)
2699 2699
2700 if focus != None: 2700 if focus is not None:
2701 focus = str(focus[0]) + "," + str(focus[1]) 2701 focus = str(focus[0]) + "," + str(focus[1])
2702 2702
2703 params = self.__generate_params( 2703 params = self.__generate_params(
2704 locals(), ['id', 'thumbnail', 'thumbnail_mime_type']) 2704 locals(), ['id', 'thumbnail', 'thumbnail_mime_type'])
2705 2705
2706 if not thumbnail is None: 2706 if thumbnail is not None:
2707 if not self.verify_minimum_version("3.2.0", cached=True): 2707 if not self.verify_minimum_version("3.2.0", cached=True):
2708 raise MastodonVersionError( 2708 raise MastodonVersionError(
2709 'Thumbnail requires version > 3.2.0') 2709 'Thumbnail requires version > 3.2.0')
@@ -2809,25 +2809,25 @@ class Mastodon:
2809 'policy': policy 2809 'policy': policy
2810 } 2810 }
2811 2811
2812 if follow_events != None: 2812 if follow_events is not None:
2813 params['data[alerts][follow]'] = follow_events 2813 params['data[alerts][follow]'] = follow_events
2814 2814
2815 if favourite_events != None: 2815 if favourite_events is not None:
2816 params['data[alerts][favourite]'] = favourite_events 2816 params['data[alerts][favourite]'] = favourite_events
2817 2817
2818 if reblog_events != None: 2818 if reblog_events is not None:
2819 params['data[alerts][reblog]'] = reblog_events 2819 params['data[alerts][reblog]'] = reblog_events
2820 2820
2821 if mention_events != None: 2821 if mention_events is not None:
2822 params['data[alerts][mention]'] = mention_events 2822 params['data[alerts][mention]'] = mention_events
2823 2823
2824 if poll_events != None: 2824 if poll_events is not None:
2825 params['data[alerts][poll]'] = poll_events 2825 params['data[alerts][poll]'] = poll_events
2826 2826
2827 if follow_request_events != None: 2827 if follow_request_events is not None:
2828 params['data[alerts][follow_request]'] = follow_request_events 2828 params['data[alerts][follow_request]'] = follow_request_events
2829 2829
2830 if follow_request_events != None: 2830 if follow_request_events is not None:
2831 params['data[alerts][status]'] = status_events 2831 params['data[alerts][status]'] = status_events
2832 2832
2833 # Canonicalize booleans 2833 # Canonicalize booleans
@@ -2847,22 +2847,22 @@ class Mastodon:
2847 """ 2847 """
2848 params = {} 2848 params = {}
2849 2849
2850 if follow_events != None: 2850 if follow_events is not None:
2851 params['data[alerts][follow]'] = follow_events 2851 params['data[alerts][follow]'] = follow_events
2852 2852
2853 if favourite_events != None: 2853 if favourite_events is not None:
2854 params['data[alerts][favourite]'] = favourite_events 2854 params['data[alerts][favourite]'] = favourite_events
2855 2855
2856 if reblog_events != None: 2856 if reblog_events is not None:
2857 params['data[alerts][reblog]'] = reblog_events 2857 params['data[alerts][reblog]'] = reblog_events
2858 2858
2859 if mention_events != None: 2859 if mention_events is not None:
2860 params['data[alerts][mention]'] = mention_events 2860 params['data[alerts][mention]'] = mention_events
2861 2861
2862 if poll_events != None: 2862 if poll_events is not None:
2863 params['data[alerts][poll]'] = poll_events 2863 params['data[alerts][poll]'] = poll_events
2864 2864
2865 if follow_request_events != None: 2865 if follow_request_events is not None:
2866 params['data[alerts][follow_request]'] = follow_request_events 2866 params['data[alerts][follow_request]'] = follow_request_events
2867 2867
2868 # Canonicalize booleans 2868 # Canonicalize booleans
@@ -2941,13 +2941,13 @@ class Mastodon:
2941 2941
2942 Returns a list of `admin account dicts`_. 2942 Returns a list of `admin account dicts`_.
2943 """ 2943 """
2944 if max_id != None: 2944 if max_id is not None:
2945 max_id = self.__unpack_id(max_id, dateconv=True) 2945 max_id = self.__unpack_id(max_id, dateconv=True)
2946 2946
2947 if min_id != None: 2947 if min_id is not None:
2948 min_id = self.__unpack_id(min_id, dateconv=True) 2948 min_id = self.__unpack_id(min_id, dateconv=True)
2949 2949
2950 if since_id != None: 2950 if since_id is not None:
2951 since_id = self.__unpack_id(since_id, dateconv=True) 2951 since_id = self.__unpack_id(since_id, dateconv=True)
2952 2952
2953 params = self.__generate_params( 2953 params = self.__generate_params(
@@ -3077,7 +3077,7 @@ class Mastodon:
3077 send_email_notification = None 3077 send_email_notification = None
3078 3078
3079 id = self.__unpack_id(id) 3079 id = self.__unpack_id(id)
3080 if not report_id is None: 3080 if report_id is not None:
3081 report_id = self.__unpack_id(report_id) 3081 report_id = self.__unpack_id(report_id)
3082 3082
3083 params = self.__generate_params(locals(), ['id', 'action']) 3083 params = self.__generate_params(locals(), ['id', 'action'])
@@ -3097,19 +3097,19 @@ class Mastodon:
3097 3097
3098 Returns a list of `report dicts`_. 3098 Returns a list of `report dicts`_.
3099 """ 3099 """
3100 if max_id != None: 3100 if max_id is not None:
3101 max_id = self.__unpack_id(max_id, dateconv=True) 3101 max_id = self.__unpack_id(max_id, dateconv=True)
3102 3102
3103 if min_id != None: 3103 if min_id is not None:
3104 min_id = self.__unpack_id(min_id, dateconv=True) 3104 min_id = self.__unpack_id(min_id, dateconv=True)
3105 3105
3106 if since_id != None: 3106 if since_id is not None:
3107 since_id = self.__unpack_id(since_id, dateconv=True) 3107 since_id = self.__unpack_id(since_id, dateconv=True)
3108 3108
3109 if not account_id is None: 3109 if account_id is not None:
3110 account_id = self.__unpack_id(account_id) 3110 account_id = self.__unpack_id(account_id)
3111 3111
3112 if not target_account_id is 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 resolved == False:
@@ -3444,7 +3444,7 @@ class Mastodon:
3444 """ 3444 """
3445 Fetch the logged in user's ID, with caching. ID is reset on calls to log_in. 3445 Fetch the logged in user's ID, with caching. ID is reset on calls to log_in.
3446 """ 3446 """
3447 if self.__logged_in_id == None: 3447 if self.__logged_in_id is None:
3448 self.__logged_in_id = self.account_verify_credentials().id 3448 self.__logged_in_id = self.account_verify_credentials().id
3449 return self.__logged_in_id 3449 return self.__logged_in_id
3450 3450
@@ -3467,7 +3467,7 @@ class Mastodon:
3467 "updated_at", "last_status_at", "starts_at", "ends_at", "published_at", "edited_at"] 3467 "updated_at", "last_status_at", "starts_at", "ends_at", "published_at", "edited_at"]
3468 for k, v in json_object.items(): 3468 for k, v in json_object.items():
3469 if k in known_date_fields: 3469 if k in known_date_fields:
3470 if v != None: 3470 if v is not None:
3471 try: 3471 try:
3472 if isinstance(v, int): 3472 if isinstance(v, int):
3473 json_object[k] = datetime.datetime.fromtimestamp(v, pytz.utc) 3473 json_object[k] = datetime.datetime.fromtimestamp(v, pytz.utc)
@@ -3555,9 +3555,9 @@ class Mastodon:
3555 3555
3556 # Generate request headers 3556 # Generate request headers
3557 headers = copy.deepcopy(headers) 3557 headers = copy.deepcopy(headers)
3558 if not self.access_token is None: 3558 if self.access_token is not None:
3559 headers['Authorization'] = 'Bearer ' + self.access_token 3559 headers['Authorization'] = 'Bearer ' + self.access_token
3560 if not access_token_override is None: 3560 if access_token_override is not None:
3561 headers['Authorization'] = 'Bearer ' + access_token_override 3561 headers['Authorization'] = 'Bearer ' + access_token_override
3562 3562
3563 # Add user-agent 3563 # Add user-agent
@@ -3566,7 +3566,7 @@ class Mastodon:
3566 3566
3567 # Determine base URL 3567 # Determine base URL
3568 base_url = self.api_base_url 3568 base_url = self.api_base_url
3569 if not base_url_override is None: 3569 if base_url_override is not None:
3570 base_url = base_url_override 3570 base_url = base_url_override
3571 3571
3572 if self.debug_requests: 3572 if self.debug_requests:
@@ -3626,7 +3626,7 @@ class Mastodon:
3626 ratelimit_intrep = None 3626 ratelimit_intrep = None
3627 3627
3628 try: 3628 try:
3629 if not ratelimit_intrep is None and ratelimit_intrep == response_object.headers['X-RateLimit-Reset']: 3629 if ratelimit_intrep is not None and ratelimit_intrep == response_object.headers['X-RateLimit-Reset']:
3630 self.ratelimit_reset = int( 3630 self.ratelimit_reset = int(
3631 response_object.headers['X-RateLimit-Reset']) 3631 response_object.headers['X-RateLimit-Reset'])
3632 else: 3632 else:
@@ -3871,7 +3871,7 @@ class Mastodon:
3871 3871
3872 def close(self): 3872 def close(self):
3873 self.closed = True 3873 self.closed = True
3874 if not self.connection is None: 3874 if self.connection is not None:
3875 self.connection.close() 3875 self.connection.close()
3876 3876
3877 def is_alive(self): 3877 def is_alive(self):
@@ -3897,7 +3897,7 @@ class Mastodon:
3897 3897
3898 # Run until closed or until error if not autoreconnecting 3898 # Run until closed or until error if not autoreconnecting
3899 while self.running: 3899 while self.running:
3900 if not self.connection is None: 3900 if self.connection is not None:
3901 with closing(self.connection) as r: 3901 with closing(self.connection) as r:
3902 try: 3902 try:
3903 listener.handle_stream(r) 3903 listener.handle_stream(r)
diff --git a/mastodon/streaming.py b/mastodon/streaming.py
index e43d7d6..08f5670 100644
--- a/mastodon/streaming.py
+++ b/mastodon/streaming.py
@@ -213,11 +213,11 @@ class CallbackStreamListener(StreamListener):
213 self.status_update_handler = status_update_handler 213 self.status_update_handler = status_update_handler
214 214
215 def on_update(self, status): 215 def on_update(self, status):
216 if self.update_handler != None: 216 if self.update_handler is not None:
217 self.update_handler(status) 217 self.update_handler(status)
218 218
219 try: 219 try:
220 if self.local_update_handler != None and not "@" in status["account"]["acct"]: 220 if self.local_update_handler is not None and not "@" in status["account"]["acct"]:
221 self.local_update_handler(status) 221 self.local_update_handler(status)
222 except Exception as err: 222 except Exception as err:
223 six.raise_from( 223 six.raise_from(
@@ -226,21 +226,21 @@ class CallbackStreamListener(StreamListener):
226 ) 226 )
227 227
228 def on_delete(self, deleted_id): 228 def on_delete(self, deleted_id):
229 if self.delete_handler != None: 229 if self.delete_handler is not None:
230 self.delete_handler(deleted_id) 230 self.delete_handler(deleted_id)
231 231
232 def on_notification(self, notification): 232 def on_notification(self, notification):
233 if self.notification_handler != None: 233 if self.notification_handler is not None:
234 self.notification_handler(notification) 234 self.notification_handler(notification)
235 235
236 def on_conversation(self, conversation): 236 def on_conversation(self, conversation):
237 if self.conversation_handler != None: 237 if self.conversation_handler is not None:
238 self.conversation_handler(conversation) 238 self.conversation_handler(conversation)
239 239
240 def on_unknown_event(self, name, unknown_event=None): 240 def on_unknown_event(self, name, unknown_event=None):
241 if self.unknown_event_handler != None: 241 if self.unknown_event_handler is not None:
242 self.unknown_event_handler(name, unknown_event) 242 self.unknown_event_handler(name, unknown_event)
243 243
244 def on_status_update(self, status): 244 def on_status_update(self, status):
245 if self.status_update_handler != None: 245 if self.status_update_handler is not None:
246 self.status_update_handler(status) 246 self.status_update_handler(status)
Powered by cgit v1.2.3 (git 2.41.0)