Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Zahra Rajabi
tweepy
Commits
2f4781c0
Commit
2f4781c0
authored
Sep 28, 2009
by
Josh Roesslein
Browse files
Implemented "cursor" based Cursor iterator.
parent
caec131b
Changes
1
Hide whitespace changes
Inline
Side-by-side
tweepy/cursor.py
View file @
2f4781c0
...
...
@@ -2,6 +2,8 @@
# Copyright 2009 Joshua Roesslein
# See LICENSE
from
.
error
import
TweepError
class
Cursor
(
object
):
"""Pagination helper class"""
...
...
@@ -48,11 +50,29 @@ class BaseIterator(object):
class
CursorIterator
(
BaseIterator
):
def
__init__
(
self
,
method
,
args
,
kargs
):
BaseIterator
.
__init__
(
self
,
method
,
args
,
kargs
)
self
.
next_cursor
=
-
1
self
.
prev_cursor
=
0
self
.
count
=
0
def
next
(
self
):
return
if
self
.
next_cursor
==
0
or
(
self
.
limit
and
self
.
count
==
self
.
limit
):
raise
StopIteration
data
,
self
.
next_cursor
,
self
.
prev_cursor
=
self
.
method
(
cursor
=
self
.
next_cursor
,
*
self
.
args
,
**
self
.
kargs
)
self
.
count
+=
1
return
data
def
prev
(
self
):
return
if
self
.
prev_cursor
==
0
:
raise
TweepError
(
'Can not page back more, at first page'
)
data
,
self
.
next_cursor
,
self
.
prev_cursor
=
self
.
method
(
cursor
=
self
.
prev_cursor
,
*
self
.
args
,
**
self
.
kargs
)
self
.
count
-=
1
return
data
class
PageIterator
(
BaseIterator
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment