Files
mtusi2026lab7/app/pagination.py
T
kirill_dolda 280c5a3300
Skeleton contracts / contracts (pull_request) Blocked by required conditions
ЛР 7: безопасность, mTLS и OpenBao на оценку 3
2026-12-06 15:19:24 +03:00

20 lines
440 B
Python

def paginate(items: list, limit: int, cursor: str | None):
start = 0
if cursor is not None:
try:
start = int(cursor)
except ValueError:
start = 0
if start < 0:
start = 0
page = items[start : start + limit]
next_index = start + limit
if next_index < len(items):
next_cursor = str(next_index)
else:
next_cursor = None
return page, next_cursor