Fix xrange for Python 3

Python 3 changed the behaviour of =range= to match the old behaviour of
=xrange=.  While this is all well and good, they removed =xrange= in the
process.  This patch adds code to detect when python 3 is running and to
define and xrange for the code.