Initial port to Python 3.

Tested with Python 3.2 and 3.3.0. Comparison tests are failing.
Fixes for ResourceWarning errors with Python 3.
Merge branch 'python3'