Fix many Python 3.4 issues

When running all tests, I found that they are converting to python3 automagically.
But running separate test file will raise an exception.
I fixed many issues I found in tests, and also some errors in `lib` package.

There are also many issues in `examples`, `sandbox` etc, so if it's needed, I can fix them too, what do you think?