Make some more adjustments for python3

The main change here is the reordering of the package or directory
test to avoid a basestring test.