Make build Python3 compatible

Python3 opens files in user default encoding, and it can be non-unicode. In this case opening
utf-8 encoded file might raise an exception.

Use io library (available since 2.6) and explicitly open files in utf-8
Merge pull request #815 from anatol/next

Make build Python3 compatible