[1.7.x] Ensured that Paginator.page_range works the same on Python 2 and 3.

This somewhat fixes #23088, refs 23140.

Backport of 2d542bf60cc37c59872c5a20d6af3bf826038739 from master.