diff options
author | Lorenz Diener <[email protected]> | 2018-06-04 16:48:20 +0200 |
---|---|---|
committer | Lorenz Diener <[email protected]> | 2018-06-04 16:48:20 +0200 |
commit | 163fd5d3d558eed452c642248cb69dc597a5765f (patch) | |
tree | 3f1e416fd46d86608565e0c87ab2730179b1e3ff /mastodon | |
parent | 093c207292f221a426a04181f6d158cba14bbe8a (diff) | |
download | mastodon.py-163fd5d3d558eed452c642248cb69dc597a5765f.tar.gz |
Move pagination info to attributes
Diffstat (limited to 'mastodon')
-rw-r--r-- | mastodon/Mastodon.py | 15 | ||||
-rw-r--r-- | mastodon/__init__.py | 4 |
2 files changed, 9 insertions, 10 deletions
diff --git a/mastodon/Mastodon.py b/mastodon/Mastodon.py index 2adc82e..e365ce1 100644 --- a/mastodon/Mastodon.py +++ b/mastodon/Mastodon.py | |||
@@ -82,7 +82,7 @@ class AttribAccessDict(dict): | |||
82 | return self[attr] | 82 | return self[attr] |
83 | else: | 83 | else: |
84 | raise AttributeError("Attribute not found: " + str(attr)) | 84 | raise AttributeError("Attribute not found: " + str(attr)) |
85 | 85 | ||
86 | def __setattr__(self, attr, val): | 86 | def __setattr__(self, attr, val): |
87 | if attr in self: | 87 | if attr in self: |
88 | raise AttributeError("Attribute-style access is read only") | 88 | raise AttributeError("Attribute-style access is read only") |
@@ -1480,8 +1480,8 @@ class Mastodon: | |||
1480 | Returns the next page or None if no further data is available. | 1480 | Returns the next page or None if no further data is available. |
1481 | """ | 1481 | """ |
1482 | if isinstance(previous_page, list) and len(previous_page) != 0: | 1482 | if isinstance(previous_page, list) and len(previous_page) != 0: |
1483 | if '_pagination_next' in previous_page[-1]: | 1483 | if hasattr(previous_page[-1], '_pagination_next'): |
1484 | params = copy.deepcopy(previous_page[-1]['_pagination_next']) | 1484 | params = copy.deepcopy(previous_page[-1]._pagination_next) |
1485 | else: | 1485 | else: |
1486 | return None | 1486 | return None |
1487 | else: | 1487 | else: |
@@ -1504,8 +1504,8 @@ class Mastodon: | |||
1504 | Returns the previous page or None if no further data is available. | 1504 | Returns the previous page or None if no further data is available. |
1505 | """ | 1505 | """ |
1506 | if isinstance(next_page, list) and len(next_page) != 0: | 1506 | if isinstance(next_page, list) and len(next_page) != 0: |
1507 | if '_pagination_prev' in next_page[0]: | 1507 | if hasattr(next_page[0], '_pagination_prev'): |
1508 | params = copy.deepcopy(next_page[0]['_pagination_prev']) | 1508 | params = copy.deepcopy(next_page[0]._pagination_prev) |
1509 | else: | 1509 | else: |
1510 | return None | 1510 | return None |
1511 | else: | 1511 | else: |
@@ -1655,7 +1655,6 @@ class Mastodon: | |||
1655 | Internal API request helper. | 1655 | Internal API request helper. |
1656 | """ | 1656 | """ |
1657 | response = None | 1657 | response = None |
1658 | headers = None | ||
1659 | remaining_wait = 0 | 1658 | remaining_wait = 0 |
1660 | # "pace" mode ratelimiting: Assume constant rate of requests, sleep a little less long than it | 1659 | # "pace" mode ratelimiting: Assume constant rate of requests, sleep a little less long than it |
1661 | # would take to not hit the rate limit at that request rate. | 1660 | # would take to not hit the rate limit at that request rate. |
@@ -1804,7 +1803,7 @@ class Mastodon: | |||
1804 | next_params['max_id'] = int(matchgroups.group(1)) | 1803 | next_params['max_id'] = int(matchgroups.group(1)) |
1805 | if "since_id" in next_params: | 1804 | if "since_id" in next_params: |
1806 | del next_params['since_id'] | 1805 | del next_params['since_id'] |
1807 | response[-1]['_pagination_next'] = next_params | 1806 | response[-1]._pagination_next = next_params |
1808 | 1807 | ||
1809 | if url['rel'] == 'prev': | 1808 | if url['rel'] == 'prev': |
1810 | # Be paranoid and extract since_id specifically | 1809 | # Be paranoid and extract since_id specifically |
@@ -1818,7 +1817,7 @@ class Mastodon: | |||
1818 | prev_params['since_id'] = int(matchgroups.group(1)) | 1817 | prev_params['since_id'] = int(matchgroups.group(1)) |
1819 | if "max_id" in prev_params: | 1818 | if "max_id" in prev_params: |
1820 | del prev_params['max_id'] | 1819 | del prev_params['max_id'] |
1821 | response[0]['_pagination_prev'] = prev_params | 1820 | response[0]._pagination_prev = prev_params |
1822 | 1821 | ||
1823 | 1822 | ||
1824 | return response | 1823 | return response |
diff --git a/mastodon/__init__.py b/mastodon/__init__.py index 787d4e8..21de9ae 100644 --- a/mastodon/__init__.py +++ b/mastodon/__init__.py | |||
@@ -1,4 +1,4 @@ | |||
1 | from mastodon.Mastodon import Mastodon, MastodonError, MastodonVersionError, MastodonIllegalArgumentError, MastodonIOError, MastodonFileNotFoundError, MastodonNetworkError, MastodonAPIError, MastodonNotFoundError, MastodonUnauthorizedError, MastodonRatelimitError, MastodonMalformedEventError | 1 | from mastodon.Mastodon import Mastodon, AttribAccessDict, MastodonError, MastodonVersionError, MastodonIllegalArgumentError, MastodonIOError, MastodonFileNotFoundError, MastodonNetworkError, MastodonAPIError, MastodonNotFoundError, MastodonUnauthorizedError, MastodonRatelimitError, MastodonMalformedEventError |
2 | from mastodon.streaming import StreamListener, CallbackStreamListener | 2 | from mastodon.streaming import StreamListener, CallbackStreamListener |
3 | 3 | ||
4 | __all__ = ['Mastodon', 'StreamListener', 'CallbackStreamListener', 'MastodonError', 'MastodonVersionError', 'MastodonIllegalArgumentError', 'MastodonIOError', 'MastodonFileNotFoundError', 'MastodonNetworkError', 'MastodonAPIError', 'MastodonNotFoundError', 'MastodonUnauthorizedError', 'MastodonRatelimitError', 'MastodonMalformedEventError'] | 4 | __all__ = ['Mastodon', 'AttribAccessDict', 'StreamListener', 'CallbackStreamListener', 'MastodonError', 'MastodonVersionError', 'MastodonIllegalArgumentError', 'MastodonIOError', 'MastodonFileNotFoundError', 'MastodonNetworkError', 'MastodonAPIError', 'MastodonNotFoundError', 'MastodonUnauthorizedError', 'MastodonRatelimitError', 'MastodonMalformedEventError'] |