Fix bug related to python3

In python3 the xrange function has been removed, and range returns an iterator
like xrange did. I added six to the requirements and used its xrange utility
to fill in for the missing function.

I also added a test that will exercise that code path in the future.