Commit e3d23762 authored by Josh Roesslein's avatar Josh Roesslein
Browse files

Fix Cursor pagination mode detection.

parent 01dc7345
......@@ -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
......
......@@ -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
......@@ -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')
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment