[Python-Dev] pathlib - current status of discussions

Victor Stinner victor.stinner at gmail.com
Thu Apr 14 12:04:36 EDT 2016


2016-04-14 17:29 GMT+02:00 Ethan Furman <ethan at stoneleaf.us>:
> Interoperability with other systems and/or libraries.  If we use
> surrogateescape to transform str to bytes, and the other side does not, we
> no longer have a workable path.

I guess that you mean a Python library? When you exchange with
external programs or call a C libraries, Python is responsible to
encode Unicode to bytes with os.fsencode(). The external part is not
aware that Python uses surrogateescape, it gets "regular" bytes.

I suggest to consider such Python library as external programs and
libraries: convert Unicode to bytes with os.fsencode(), but also
process paths as Unicode "inside" your application.

It's the basic rule to handle correctly Unicode in an application:
decode inputs as soon as possible, and encode back as late as
possible. Encode/decode at borders.

Victor


More information about the Python-Dev mailing list