File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2727
2828from threading import Timer
2929
30- import itertools
30+ from itertools import islice
3131
3232from requests import codes
3333from requests .exceptions import ConnectionError
@@ -337,8 +337,18 @@ def __init__(self,
337337 self .plus_one_paging : bool = self .pager_type in PaginationMockSupport .key_pagers
338338 self .expected_pages : list [list ] = []
339339
340+ # for compatibility with python <= 3.12
341+ def batched (self , iterable , n ):
342+ """Batch data into tuples of length n. The last batch may be shorter."""
343+ it = iter (iterable )
344+ while True :
345+ batch = tuple (islice (it , n ))
346+ if not batch :
347+ break
348+ yield batch
349+
340350 def generator (self ):
341- for page in itertools .batched (range (0 , self .total_items ), self .page_size ):
351+ for page in self .batched (range (0 , self .total_items ), self .page_size ):
342352 rows = [PaginationMockSupport .make_row (self .pager_type , i ) for i in page ]
343353 if self .plus_one_paging :
344354 # Add an n+1 row for key based paging if more pages
You can’t perform that action at this time.
0 commit comments