Support Python 2.x.

* Fix compatibility of StringIO.
* Provide an utility fucntion to handle unicode issue in Python 2.x.