Backport PR #3971 to 1.7.x

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