Make gen_python.py Python 3 compatible

The `gen_python.py` script is modified to generate `docs.py` which can be used by both Python 2 and 3.

Currently, if the script is run by Python 3, the output is slightly different. Python 2 does not allow non-ascii characters to be printed in the `repr()` results, while Python 3 does not have such limitations.

This means that `docs.py` generated by Python 2 can be usable by Python 3, but the reverse is not true. As the current build system is served by Python 2, I think it would be OK to rely on this behavior.