[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

Re: Re: Determining "file system encoding" from Python

From: Yasuhito FUTATSUKI <futatuki_at_yf.bsdclub.org>
Date: Tue, 30 Jun 2020 11:08:32 +0900


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).


Yasuhito FUTATSUKI <futatuki_at_yf.bsclub.org>
Received on 2020-06-30 04:13:25 CEST

This is an archived mail posted to the Subversion Users mailing list.

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.