PY3:  Python 3 idioms fixes via the 2to3 Python migration script.

The command used was:
2to3 -j 4 -w -f idioms .

This replaces the list sort() method builtin sorted() function and the
builtin type() function with isinstance().
PY3:  Python 3 fixes for the xrange() and range() functions.

The command used was:
2to3 -j 4 -w -f xrange .

In Python 3, the range() function returns and iterator, just like
xrange() in Python 2.  Therefore it needs to be passed through the
list() function to generate a list.  All xrange() calls have also been
replaced by range(), as xrange() does not exist in Python 3.
PY3:  Many Python 3 dictionary fixes via the 2to3 Python script.

The command used was:
2to3 -j 4 -w -f dict .

The keys() dictionary method in Python 3 now returns an iterator object,
so this needs to be passed through the list() builtin function.  The
iteritems() dictionary method no longer exists, so items() needs to be
used instead (sometimes passed through list() when lists rather than
tuples are required).
PY3:  Elimination of the dictionary has_key() method.

The command used was:
2to3 -j 4 -w -f has_key .

This method no longer exists in Python 3.
MAINT: Changes required for tests to pass in Python 2.6
Merge remote-tracking branch 'upstream/master'