def paginate(query, org_id, max_pages=maxsize, max_records=maxsize):
page_count = <NUM_LIT:0><EOL>record_count = <NUM_LIT:0><EOL>records = []<EOL>while page_count < max_pages and record_count < max_records:<EOL><INDENT>res = make_call(query, org_id, page_count)<EOL>page_count += <NUM_LIT:1><EOL>if "<STR_LIT>" in res:<EOL><INDENT>records += res["<STR_LIT>"]<EOL><DEDENT>elif "<STR_LIT>" in res:<EOL><INDENT>records += res["<STR_LIT>"]<EOL><DEDENT>record_count = len(records)<EOL>if res.get("<STR_LIT>"):<EOL><INDENT>break<EOL><DEDENT><DEDENT>return records<EOL>
Paginate through all results of a UMAPI query
:param query: a query method from a UMAPI instance (callable as a function)
:param org_id: the organization being queried
:param max_pages: the max number of pages to collect before returning (default all)
:param max_records: the max number of records to collect before returning (default all)
:return: the queried records