Derived from a patch at https://bitbucket.org/pypy/compatibility/wiki/edit/mysql-python
Merged with modifications from a815269010
a815269010