Changes to make code both python2.7 and python3 compatible

@jaberg, you don't have to merge this if you don't want (i.e., if we'd rather have a 3to2 conversion on python2 installs), but these changes do get all tests passing on python2.7 and python3.