cli2 3.3.30__tar.gz → 3.3.31__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {cli2-3.3.30/cli2.egg-info → cli2-3.3.31}/PKG-INFO +1 -1
- {cli2-3.3.30 → cli2-3.3.31}/cli2/client.py +13 -1
- {cli2-3.3.30 → cli2-3.3.31}/cli2/test_client.py +7 -1
- {cli2-3.3.30 → cli2-3.3.31/cli2.egg-info}/PKG-INFO +1 -1
- {cli2-3.3.30 → cli2-3.3.31}/setup.py +1 -1
- {cli2-3.3.30 → cli2-3.3.31}/MANIFEST.in +0 -0
- {cli2-3.3.30 → cli2-3.3.31}/README.rst +0 -0
- {cli2-3.3.30 → cli2-3.3.31}/classifiers.txt +0 -0
- {cli2-3.3.30 → cli2-3.3.31}/cli2/__init__.py +0 -0
- {cli2-3.3.30 → cli2-3.3.31}/cli2/argument.py +0 -0
- {cli2-3.3.30 → cli2-3.3.31}/cli2/asyncio.py +0 -0
- {cli2-3.3.30 → cli2-3.3.31}/cli2/cli.py +0 -0
- {cli2-3.3.30 → cli2-3.3.31}/cli2/colors.py +0 -0
- {cli2-3.3.30 → cli2-3.3.31}/cli2/command.py +0 -0
- {cli2-3.3.30 → cli2-3.3.31}/cli2/configuration.py +0 -0
- {cli2-3.3.30 → cli2-3.3.31}/cli2/decorators.py +0 -0
- {cli2-3.3.30 → cli2-3.3.31}/cli2/display.py +0 -0
- {cli2-3.3.30 → cli2-3.3.31}/cli2/entry_point.py +0 -0
- {cli2-3.3.30 → cli2-3.3.31}/cli2/example_client.py +0 -0
- {cli2-3.3.30 → cli2-3.3.31}/cli2/example_client_complex.py +0 -0
- {cli2-3.3.30 → cli2-3.3.31}/cli2/example_nesting.py +0 -0
- {cli2-3.3.30 → cli2-3.3.31}/cli2/example_obj.py +0 -0
- {cli2-3.3.30 → cli2-3.3.31}/cli2/group.py +0 -0
- {cli2-3.3.30 → cli2-3.3.31}/cli2/logging.py +0 -0
- {cli2-3.3.30 → cli2-3.3.31}/cli2/node.py +0 -0
- {cli2-3.3.30 → cli2-3.3.31}/cli2/overrides.py +0 -0
- {cli2-3.3.30 → cli2-3.3.31}/cli2/sphinx.py +0 -0
- {cli2-3.3.30 → cli2-3.3.31}/cli2/table.py +0 -0
- {cli2-3.3.30 → cli2-3.3.31}/cli2/test.py +0 -0
- {cli2-3.3.30 → cli2-3.3.31}/cli2/test_cli.py +0 -0
- {cli2-3.3.30 → cli2-3.3.31}/cli2/test_command.py +0 -0
- {cli2-3.3.30 → cli2-3.3.31}/cli2/test_configuration.py +0 -0
- {cli2-3.3.30 → cli2-3.3.31}/cli2/test_decorators.py +0 -0
- {cli2-3.3.30 → cli2-3.3.31}/cli2/test_display.py +0 -0
- {cli2-3.3.30 → cli2-3.3.31}/cli2/test_entry_point.py +0 -0
- {cli2-3.3.30 → cli2-3.3.31}/cli2/test_group.py +0 -0
- {cli2-3.3.30 → cli2-3.3.31}/cli2/test_inject.py +0 -0
- {cli2-3.3.30 → cli2-3.3.31}/cli2/test_node.py +0 -0
- {cli2-3.3.30 → cli2-3.3.31}/cli2/test_table.py +0 -0
- {cli2-3.3.30 → cli2-3.3.31}/cli2.egg-info/SOURCES.txt +0 -0
- {cli2-3.3.30 → cli2-3.3.31}/cli2.egg-info/dependency_links.txt +0 -0
- {cli2-3.3.30 → cli2-3.3.31}/cli2.egg-info/entry_points.txt +0 -0
- {cli2-3.3.30 → cli2-3.3.31}/cli2.egg-info/requires.txt +0 -0
- {cli2-3.3.30 → cli2-3.3.31}/cli2.egg-info/top_level.txt +0 -0
- {cli2-3.3.30 → cli2-3.3.31}/setup.cfg +0 -0
|
@@ -75,9 +75,14 @@ class Paginator:
|
|
|
75
75
|
.. py:attribute:: model
|
|
76
76
|
|
|
77
77
|
:py:class:`Model` class or ``dict`` by default.
|
|
78
|
+
|
|
79
|
+
.. py:attribute:: callback
|
|
80
|
+
|
|
81
|
+
Callback called for every item.
|
|
78
82
|
"""
|
|
79
83
|
|
|
80
|
-
def __init__(self, client, url, params=None, model=None, expressions=None
|
|
84
|
+
def __init__(self, client, url, params=None, model=None, expressions=None,
|
|
85
|
+
callback=None):
|
|
81
86
|
"""
|
|
82
87
|
Initialize a paginator object with a client on a URL with parameters.
|
|
83
88
|
|
|
@@ -93,6 +98,7 @@ class Paginator:
|
|
|
93
98
|
self.page_start = 1
|
|
94
99
|
self.per_page = None
|
|
95
100
|
self.initialized = False
|
|
101
|
+
self.callback = callback
|
|
96
102
|
self.expressions = []
|
|
97
103
|
for expression in (expressions or []):
|
|
98
104
|
if not isinstance(expression, Expression):
|
|
@@ -270,6 +276,8 @@ class Paginator:
|
|
|
270
276
|
"""
|
|
271
277
|
Asynchronous iterator.
|
|
272
278
|
"""
|
|
279
|
+
callback = callback or self.callback
|
|
280
|
+
|
|
273
281
|
if self._reverse and not self.total_pages:
|
|
274
282
|
first_page_response = await self.page_response(1)
|
|
275
283
|
page = self.total_pages
|
|
@@ -287,6 +295,8 @@ class Paginator:
|
|
|
287
295
|
|
|
288
296
|
for item in items:
|
|
289
297
|
if not python_filter or python_filter.matches(item):
|
|
298
|
+
if callback:
|
|
299
|
+
callback(item)
|
|
290
300
|
yield item
|
|
291
301
|
|
|
292
302
|
if self._reverse:
|
|
@@ -298,6 +308,8 @@ class Paginator:
|
|
|
298
308
|
items = self.response_items(first_page_response)
|
|
299
309
|
for item in reversed(items):
|
|
300
310
|
if not python_filter or python_filter.matches(item):
|
|
311
|
+
if callback:
|
|
312
|
+
callback(item)
|
|
301
313
|
yield item
|
|
302
314
|
break
|
|
303
315
|
else:
|
|
@@ -347,7 +347,13 @@ async def test_pagination(httpx_mock):
|
|
|
347
347
|
httpx_mock.add_response(url='http://lol/?page=2', json=[dict(a=2)])
|
|
348
348
|
httpx_mock.add_response(url='http://lol/?page=3', json=[])
|
|
349
349
|
client = Client(base_url='http://lol')
|
|
350
|
-
|
|
350
|
+
paginator = client.paginate('/')
|
|
351
|
+
paginator.callback = mock.Mock()
|
|
352
|
+
assert await paginator.list() == [dict(a=1), dict(a=2)]
|
|
353
|
+
assert paginator.callback.call_args_list == [
|
|
354
|
+
mock.call({'a': 1}),
|
|
355
|
+
mock.call({'a': 2})
|
|
356
|
+
]
|
|
351
357
|
|
|
352
358
|
|
|
353
359
|
@pytest.mark.asyncio
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|