File tree Expand file tree Collapse file tree 1 file changed +12
-1
lines changed
Expand file tree Collapse file tree 1 file changed +12
-1
lines changed Original file line number Diff line number Diff line change 2828from threading import Timer
2929
3030import itertools
31+ from itertools import islice
3132
3233from requests import codes
3334from requests .exceptions import ConnectionError
@@ -337,8 +338,18 @@ def __init__(self,
337338 self .plus_one_paging : bool = self .pager_type in PaginationMockSupport .key_pagers
338339 self .expected_pages : list [list ] = []
339340
341+ # for compatibility with python <= 3.12
342+ def batched (self , iterable , n ):
343+ """Batch data into tuples of length n. The last batch may be shorter."""
344+ it = iter (iterable )
345+ while True :
346+ batch = tuple (islice (it , n ))
347+ if not batch :
348+ break
349+ yield batch
350+
340351 def generator (self ):
341- for page in itertools .batched (range (0 , self .total_items ), self .page_size ):
352+ for page in self .batched (range (0 , self .total_items ), self .page_size ):
342353 rows = [PaginationMockSupport .make_row (self .pager_type , i ) for i in page ]
343354 if self .plus_one_paging :
344355 # Add an n+1 row for key based paging if more pages
You can’t perform that action at this time.
0 commit comments