Backported for Python 2 compatibility.