Hi, On 2020/06/29 20:00, Manuel Jacob wrote: > On 2020-06-29 12:11, Manuel Jacob wrote: >> Hi, >> >> In a Python application, I want to convert a path (as native Unix >> bytes) to a file URL (and later probably also other paths between the >> "file system encoding" and UTF-8). There are functions for this in the >> Subversion binding. However, for the sake of being able to deal with >> the familiar Python exceptions, I’d like to do the decoding/encoding >> in Python. For that, I need to find out the encoding that Subversion >> uses for converting UTF-8 to the "file system encoding". >> >> Subversion seems to use the encoding returned by >> apr_os_locale_encoding(), which is however not exposed by the Python >> bindings.
I think it suffice to use sys.getfilesystemencoding() in most case except the case of "C" (but not "C.UTF-8") locale. However, if you want to handle it more presisely how Subversion library routines handle it, you can use svn_utf_* APIs like svn.core.svn_utf_cstring_to_utf8() to convert from "file system encoding" to UTF-8, and svn.core.svn_utf_cstring_from_utf8() vice versa. (Note that Those functions also depend on locale, and cause worse result on "C" locale). Cheers, -- Yasuhito FUTATSUKI <[email protected]>
