SIGHASH_SINGLE vbuterin/pybitcointools
Just in case someone struggles with the same issue, the code was actually incorrect. Pull request #163 fixes the issue.

Here you can also see an equivalent solution properly commented and cited.