[Python-Dev] PEP 383: Non-decodable Bytes in System Character Interfaces
Benjamin Peterson
benjamin at python.org
Tue Apr 28 04:58:34 CEST 2009
2009/4/27 Cameron Simpson <cs at zip.com.au>:
>
> PROPOSAL: add to the PEP the following functions:
>
> os.fsdecode(bytes) -> funny-encoded Unicode
> This is what os.listdir() does to produce the strings it hands out.
> os.fsencode(funny-string) -> bytes
> This is what open(filename,..) does to turn the filename into bytes
> for the POSIX open.
> os.pathencode(your-string) -> funny-encoded-Unicode
> This is what you must do to a de novo string to turn it into a
> string suitable for use by open.
> Importantly, for most strings not hand crafted to have weird
> sequences in them, it is a no-op. But it will recode your puns
> for survival.
>
> and for me, I would like to see:
>
> os.setfilesystemencoding(coding)
>
> Currently os.getfilesystemencoding() returns you the encoding based on
> the current locale, and (I trust) the os.* stuff encodes on that basis.
> setfilesystemencoding() would override that, unless coding==None in what
> case it reverts to the former "use the user's current locale" behaviour.
> (We have locale "C" for what one might otherwise expect None to mean:-)
Time machine! http://docs.python.org/dev/py3k/library/sys.html#sys.setfilesystemencoding
--
Regards,
Benjamin
More information about the Python-Dev
mailing list