Python 3 compatibility

Some small changes to support Python 3.3.  I checked changes in 2.7 and they seem to be fine.