10000 Keep track of last_url requested on an Iterator · drobertduke/github3.py@4cb8624 · GitHub
[go: up one dir, main page]

Skip to content

Commit 4cb8624

Browse files
committed
Keep track of last_url requested on an Iterator
1 parent 71a4eef commit 4cb8624

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

github3/structs.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ def __init__(self, count, url, cls, session, params=None, etag=None,
1515
self.count = count
1616
#: URL the class used to make it's first GET
1717
self.url = url
18+
#: Last URL that was requested
19+
self.last_url = None
1820
self._api = self.url
1921
#: Class for constructing an item to return
2022
self.cls = cls
@@ -43,7 +45,7 @@ def _repr(self):
4345
return '<GitHubIterator [{0}, {1}]>'.format(self.count, self.path)
4446

4547
def __iter__(self):
46-
url, params, cls = self.url, self.params, self.cls
48+
self.last_url, params, cls = self.url, self.params, self.cls
4749
headers = self.headers
4850

4951
if 0 < self.count <= 100 and self.count != -1:
@@ -52,8 +54,9 @@ def __iter__(self):
5254
if 'per_page' not in params and self.count == -1:
5355
params['per_page'] = 100
5456

55-
while (self.count == -1 or self.count > 0) and url:
56-
response = self._get(url, params=params, headers=headers)
57+
while (self.count == -1 or self.count > 0) and self.last_url:
58+
response = self._get(self.last_url, params=params,
59+
headers=headers)
5760
self.last_response = response
5861
self.last_status = response.status_code
5962
if params:
@@ -82,7 +85,7 @@ def __iter__(self):
8285
break
8386

8487
rel_next = response.links.get('next', {})
85-
url = rel_next.get('url', '')
88+
self.last_url = rel_next.get('url', '')
8689

8790
def __next__(self):
8891
if not hasattr(self, '__i__'):

0 commit comments

Comments
 (0)
0