i18n: looking for expertise

klappnase klappnase at web.de
Tue Mar 8 13:38:31 EST 2005


"Martin v. Löwis" <martin at v.loewis.de> wrote in message news:<422d6267$0$6247$9b622d9e at news.freenet.de>...

> That's apparently a bug in os.access, which doesn't support Unicode file
> names. As a work around, do
> 
> def access(name, mode, orig=os.access):
>      try:
>         return orig(name, mode)
>      except UnicodeError:
>         return orig(name.encode(sys.getfilesystemencoding(), mode))
> os.access=access
> 
> Apparently, access is used so rarely that nobody has noticed yet (or
> didn't bother to report). os.path.isfile() builds on os.stat(), which
> does support Unicode file names.
> 
> Regards,
> Martin

Ah, thanks!

Now another question arises: you use sys.getfilesystemencoding() to
encode the
file name, which looks like it's the preferred method. However when I
tried to
find out how this works I got a little confused again (from the
library reference):

getfilesystemencoding()

Return the name of the encoding used to convert Unicode filenames into
system file names, or None if the system default encoding is used. The
result value depends on the operating system:
(...)
* On Unix, the encoding is the user's preference according to the
result of nl_langinfo(CODESET), or None if the nl_langinfo(CODESET)
failed.

On my box (mandrake-10.1) sys.getfilesystemencoding() returns
'ISO-8859-15',
however :
>>> locale.nl_langinfo(locale.CODESET)
'ANSI_X3.4-1968'
>>>

Anyway, my app currently runs with python-2.2 and I would like to keep
it that way if possible, so I wonder which is the preferred
replacement for sys.getfilesystemencoding() on versions < 2.3 , or in
particular, will the method I use to determine "sysencoding" I
described in my original post be safe or are there any traps I missed
(it's supposed to run on linux only)?

Thanks and best regards

Michael



More information about the Python-list mailing list