cli2 3.3.30__tar.gz → 3.3.32__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.
Files changed (45) hide show
  1. {cli2-3.3.30/cli2.egg-info → cli2-3.3.32}/PKG-INFO +1 -1
  2. {cli2-3.3.30 → cli2-3.3.32}/cli2/client.py +30 -9
  3. {cli2-3.3.30 → cli2-3.3.32}/cli2/test_client.py +14 -1
  4. {cli2-3.3.30 → cli2-3.3.32/cli2.egg-info}/PKG-INFO +1 -1
  5. {cli2-3.3.30 → cli2-3.3.32}/setup.py +1 -1
  6. {cli2-3.3.30 → cli2-3.3.32}/MANIFEST.in +0 -0
  7. {cli2-3.3.30 → cli2-3.3.32}/README.rst +0 -0
  8. {cli2-3.3.30 → cli2-3.3.32}/classifiers.txt +0 -0
  9. {cli2-3.3.30 → cli2-3.3.32}/cli2/__init__.py +0 -0
  10. {cli2-3.3.30 → cli2-3.3.32}/cli2/argument.py +0 -0
  11. {cli2-3.3.30 → cli2-3.3.32}/cli2/asyncio.py +0 -0
  12. {cli2-3.3.30 → cli2-3.3.32}/cli2/cli.py +0 -0
  13. {cli2-3.3.30 → cli2-3.3.32}/cli2/colors.py +0 -0
  14. {cli2-3.3.30 → cli2-3.3.32}/cli2/command.py +0 -0
  15. {cli2-3.3.30 → cli2-3.3.32}/cli2/configuration.py +0 -0
  16. {cli2-3.3.30 → cli2-3.3.32}/cli2/decorators.py +0 -0
  17. {cli2-3.3.30 → cli2-3.3.32}/cli2/display.py +0 -0
  18. {cli2-3.3.30 → cli2-3.3.32}/cli2/entry_point.py +0 -0
  19. {cli2-3.3.30 → cli2-3.3.32}/cli2/example_client.py +0 -0
  20. {cli2-3.3.30 → cli2-3.3.32}/cli2/example_client_complex.py +0 -0
  21. {cli2-3.3.30 → cli2-3.3.32}/cli2/example_nesting.py +0 -0
  22. {cli2-3.3.30 → cli2-3.3.32}/cli2/example_obj.py +0 -0
  23. {cli2-3.3.30 → cli2-3.3.32}/cli2/group.py +0 -0
  24. {cli2-3.3.30 → cli2-3.3.32}/cli2/logging.py +0 -0
  25. {cli2-3.3.30 → cli2-3.3.32}/cli2/node.py +0 -0
  26. {cli2-3.3.30 → cli2-3.3.32}/cli2/overrides.py +0 -0
  27. {cli2-3.3.30 → cli2-3.3.32}/cli2/sphinx.py +0 -0
  28. {cli2-3.3.30 → cli2-3.3.32}/cli2/table.py +0 -0
  29. {cli2-3.3.30 → cli2-3.3.32}/cli2/test.py +0 -0
  30. {cli2-3.3.30 → cli2-3.3.32}/cli2/test_cli.py +0 -0
  31. {cli2-3.3.30 → cli2-3.3.32}/cli2/test_command.py +0 -0
  32. {cli2-3.3.30 → cli2-3.3.32}/cli2/test_configuration.py +0 -0
  33. {cli2-3.3.30 → cli2-3.3.32}/cli2/test_decorators.py +0 -0
  34. {cli2-3.3.30 → cli2-3.3.32}/cli2/test_display.py +0 -0
  35. {cli2-3.3.30 → cli2-3.3.32}/cli2/test_entry_point.py +0 -0
  36. {cli2-3.3.30 → cli2-3.3.32}/cli2/test_group.py +0 -0
  37. {cli2-3.3.30 → cli2-3.3.32}/cli2/test_inject.py +0 -0
  38. {cli2-3.3.30 → cli2-3.3.32}/cli2/test_node.py +0 -0
  39. {cli2-3.3.30 → cli2-3.3.32}/cli2/test_table.py +0 -0
  40. {cli2-3.3.30 → cli2-3.3.32}/cli2.egg-info/SOURCES.txt +0 -0
  41. {cli2-3.3.30 → cli2-3.3.32}/cli2.egg-info/dependency_links.txt +0 -0
  42. {cli2-3.3.30 → cli2-3.3.32}/cli2.egg-info/entry_points.txt +0 -0
  43. {cli2-3.3.30 → cli2-3.3.32}/cli2.egg-info/requires.txt +0 -0
  44. {cli2-3.3.30 → cli2-3.3.32}/cli2.egg-info/top_level.txt +0 -0
  45. {cli2-3.3.30 → cli2-3.3.32}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: cli2
3
- Version: 3.3.30
3
+ Version: 3.3.32
4
4
  Summary: image:: https://yourlabs.io/oss/cli2/badges/master/pipeline.svg
5
5
  Home-page: https://yourlabs.io/oss/cli2
6
6
  Author: James Pic
@@ -75,9 +75,18 @@ class Paginator:
75
75
  .. py:attribute:: model
76
76
 
77
77
  :py:class:`Model` class or ``dict`` by default.
78
+
79
+ .. py:attribute:: postfilter
80
+
81
+ Callback called for every item after filtering.
82
+
83
+ .. py:attribute:: prefilter
84
+
85
+ Callback called for every item before filtering.
78
86
  """
79
87
 
80
- def __init__(self, client, url, params=None, model=None, expressions=None):
88
+ def __init__(self, client, url, params=None, model=None, expressions=None,
89
+ prefilter=None, postfilter=None):
81
90
  """
82
91
  Initialize a paginator object with a client on a URL with parameters.
83
92
 
@@ -93,6 +102,8 @@ class Paginator:
93
102
  self.page_start = 1
94
103
  self.per_page = None
95
104
  self.initialized = False
105
+ self.prefilter = prefilter
106
+ self.postfilter = postfilter
96
107
  self.expressions = []
97
108
  for expression in (expressions or []):
98
109
  if not isinstance(expression, Expression):
@@ -266,10 +277,13 @@ class Paginator:
266
277
  await self.initialize(response)
267
278
  return response
268
279
 
269
- async def __aiter__(self, callback=None):
280
+ async def __aiter__(self, prefilter=None, postfilter=None):
270
281
  """
271
282
  Asynchronous iterator.
272
283
  """
284
+ prefilter = prefilter or self.prefilter
285
+ postfilter = postfilter or self.postfilter
286
+
273
287
  if self._reverse and not self.total_pages:
274
288
  first_page_response = await self.page_response(1)
275
289
  page = self.total_pages
@@ -278,16 +292,24 @@ class Paginator:
278
292
 
279
293
  python_filter = self.python_filter()
280
294
 
295
+ async def yielder(items):
296
+ for item in items:
297
+ if prefilter:
298
+ await async_resolve(prefilter(item))
299
+ if not python_filter or python_filter.matches(item):
300
+ if postfilter:
301
+ await async_resolve(postfilter(item))
302
+ yield item
303
+
281
304
  while items := await self.page_items(page):
282
- if items == 'continue':
305
+ if not items:
283
306
  continue
284
307
 
285
308
  if self._reverse:
286
309
  items = reversed(items)
287
310
 
288
- for item in items:
289
- if not python_filter or python_filter.matches(item):
290
- yield item
311
+ async for item in yielder(items):
312
+ yield item
291
313
 
292
314
  if self._reverse:
293
315
  page -= 1
@@ -296,9 +318,8 @@ class Paginator:
296
318
  if page == 1:
297
319
  # use cached first page response
298
320
  items = self.response_items(first_page_response)
299
- for item in reversed(items):
300
- if not python_filter or python_filter.matches(item):
301
- yield item
321
+ async for item in yielder(reversed(items)):
322
+ yield item
302
323
  break
303
324
  else:
304
325
  if page == self.total_pages:
@@ -347,7 +347,20 @@ 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
- assert await client.paginate('/').list() == [dict(a=1), dict(a=2)]
350
+ paginator = client.paginate('/')
351
+
352
+ def prefilter(item):
353
+ item['b'] = item['a']
354
+
355
+ def postfilter(item):
356
+ item['c'] = item['b']
357
+
358
+ paginator.prefilter = prefilter
359
+ paginator.postfilter = postfilter
360
+ assert await paginator.list() == [
361
+ dict(a=1, b=1, c=1),
362
+ dict(a=2, b=2, c=2)
363
+ ]
351
364
 
352
365
 
353
366
  @pytest.mark.asyncio
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: cli2
3
- Version: 3.3.30
3
+ Version: 3.3.32
4
4
  Summary: image:: https://yourlabs.io/oss/cli2/badges/master/pipeline.svg
5
5
  Home-page: https://yourlabs.io/oss/cli2
6
6
  Author: James Pic
@@ -3,7 +3,7 @@ from setuptools import setup
3
3
 
4
4
  setup(
5
5
  name='cli2',
6
- version='3.3.30',
6
+ version='3.3.32',
7
7
  setup_requires='setupmeta',
8
8
  install_requires=[
9
9
  'docstring_parser',
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