def pagination_calc(items_count, page_size, cur_page=<NUM_LIT:1>, nearby=<NUM_LIT:2>):
if type(cur_page) == str:<EOL><INDENT>cur_page = int(cur_page) if cur_page.isdigit() else <NUM_LIT:1><EOL><DEDENT>elif type(cur_page) == int:<EOL><INDENT>if cur_page <= <NUM_LIT:0>:<EOL><INDENT>cur_page = <NUM_LIT:1><EOL><DEDENT><DEDENT>else:<EOL><INDENT>cur_page = <NUM_LIT:1><EOL><DEDENT>page_count = <NUM_LIT:1> if page_size == -<NUM_LIT:1> else int(math.ceil(items_count / page_size))<EOL>items_length = nearby * <NUM_LIT:2> + <NUM_LIT:1><EOL>first_page = None<EOL>last_page = None<EOL>prev_page = cur_page - <NUM_LIT:1> if cur_page != <NUM_LIT:1> else None<EOL>next_page = cur_page + <NUM_LIT:1> if cur_page != page_count else None<EOL>if page_count <= items_length:<EOL><INDENT>items = range(<NUM_LIT:1>, page_count + <NUM_LIT:1>)<EOL><DEDENT>elif cur_page <= nearby:<EOL><INDENT>items = range(<NUM_LIT:1>, items_length + <NUM_LIT:1>)<EOL>last_page = True<EOL><DEDENT>elif cur_page >= page_count - nearby:<EOL><INDENT>items = range(page_count - items_length + <NUM_LIT:1>, page_count + <NUM_LIT:1>)<EOL>first_page = True<EOL><DEDENT>else:<EOL><INDENT>items = range(cur_page - nearby, cur_page + nearby + <NUM_LIT:1>)<EOL>first_page, last_page = True, True<EOL><DEDENT>if first_page:<EOL><INDENT>first_page = <NUM_LIT:1><EOL><DEDENT>if last_page:<EOL><INDENT>last_page = page_count<EOL><DEDENT>return {<EOL>'<STR_LIT>': cur_page,<EOL>'<STR_LIT>': prev_page,<EOL>'<STR_LIT>': next_page,<EOL>'<STR_LIT>': first_page,<EOL>'<STR_LIT>': last_page,<EOL>'<STR_LIT>': list(items),<EOL>'<STR_LIT:info>': {<EOL>'<STR_LIT>': page_size,<EOL>'<STR_LIT>': page_count,<EOL>'<STR_LIT>': items_count,<EOL>}<EOL>}<EOL>
:param nearby:
:param items_count: count of all items
:param page_size: size of one page
:param cur_page: current page number, accept string digit
:return: num of pages, an iterator