Backport PR #3971 for 1.8.x

Compatibility with Python3, which doesn't have string.lowercase.

backport of #3971