refactor "_sanitize" for Python < 2.7