def replace_page_in_query(query, page_number, page_key=DEFAULT_PAGE_KEY):
 getvars = parse_qs(query)
 if (page_number is None):
  getvars.pop(page_key, None)
 else:
  getvars[page_key] = page_number
 return urlencode(getvars, True)

def replace_page_in_query ( query , page_number , page_key = DEFAULT_PAGE_KEY ) : getvars = parse_qs ( query ) if ( page_number is None ) : getvars . pop ( page_key , None ) else : getvars [ page_key ] = page_number return urlencode ( getvars , True )
replaces page_key from query string with page_number .