copied directly from ansible/lib/ansible/utils/__init__.py, lines 648-649