- # Escape literal backslash
- path = re.sub('\\\\', lambda m: '\\134', path)
- # Escape other special chars. Py3's oct() output differs from Py2, this takes
- # care of those differences.
- path = re.sub('([\t\n\r: ])', lambda m: '\\'+oct(ord(m.group(1))).replace('o', '')[-3:], path)
- return path