From e3d23762361d48f28d764328a3209e2cac643e4f Mon Sep 17 00:00:00 2001 From: Josh Roesslein Date: Tue, 13 Oct 2009 17:19:22 -0500 Subject: [PATCH] Fix Cursor pagination mode detection. --- tweepy/api.py | 1 + tweepy/binder.py | 10 +++++++--- tweepy/cursor.py | 9 +++++---- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/tweepy/api.py b/tweepy/api.py index 591b88c..64a850d 100644 --- a/tweepy/api.py +++ b/tweepy/api.py @@ -946,6 +946,7 @@ class API(object): parser = parse_search_results, allowed_param = ['q', 'lang', 'locale', 'rpp', 'page', 'since_id', 'geocode', 'show_user'], )(self, *args, **kargs) + search.pagination_mode = 'page' """ trends diff --git a/tweepy/binder.py b/tweepy/binder.py index bf00139..0088501 100644 --- a/tweepy/binder.py +++ b/tweepy/binder.py @@ -21,7 +21,7 @@ except ImportError: raise ImportError, "Can't load a json library" -def bind_api(path, parser, allowed_param=None, method='GET', require_auth=False, +def bind_api(path, parser, allowed_param=[], method='GET', require_auth=False, timeout=None, host=None): def _call(api, *args, **kargs): @@ -186,8 +186,12 @@ def bind_api(path, parser, allowed_param=None, method='GET', require_auth=False, return out - # Expose extra data in callable object - _call.allowed_param = allowed_param + + # Set pagination mode + if 'cursor' in allowed_param: + _call.pagination_mode = 'cursor' + elif 'page' in allowed_param: + _call.pagination_mode = 'page' return _call diff --git a/tweepy/cursor.py b/tweepy/cursor.py index 035ce89..1def5fd 100644 --- a/tweepy/cursor.py +++ b/tweepy/cursor.py @@ -8,10 +8,11 @@ class Cursor(object): """Pagination helper class""" def __init__(self, method, *args, **kargs): - if 'cursor' in method.allowed_param: - self.iterator = CursorIterator(method, args, kargs) - elif 'page' in method.allowed_param: - self.iterator = PageIterator(method, args, kargs) + if hasattr(method, 'pagination_mode'): + if method.pagination_mode == 'cursor': + self.iterator = CursorIterator(method, args, kargs) + else: + self.iterator = PageIterator(method, args, kargs) else: raise TweepError('This method does not perform pagination') -- 2.25.1