Minor tweaks toward Python 3 support

These three modest changes fix syntactical errors encountered in Python 3 and a few import-time errors. Python 2.5 compatibility is maintained.