jaraco/path.py — pull request #74 by gazpachoking (2014-09-18 16:30:32+00:00)
Title: Make paths with invalid encodings work on python 2

On python 3, paths which are not encoded using the declared filesystem encoding are still handled, using python 3's surrogate escaping. There is some support in path.py for emulating this on python 2, but it is currently incomplete. Reading invalid filenames works and returns a unicode object with surrogate escapes, however this cannot be used with any os functions, and if it is a directory, nothing inside the directory can be traversed by path.py (for example with the walk method.) At least in the case of declared filesystem encoding being ascii, the surrogates cannot be encoded back to their original bytes. In order to bring python 2 support in line with python 3, I propose that when passing these paths back to the os functions, they be transparently encoded back to the original bytes. Currently I have implemented this using the `future` library, but I think the appropriate functions to encode and decode filenames with proper surrogate support could be pulled out if this functionality is desired in path.py.