On Friday 01 December 2006 17:26, Hans Meine wrote: > I wonder if there should be an additional filename_to_unicode function > which uses sys.getfilesystemencoding() instead of strutils.ENCODING? > > def path_to_unicode(s): ..which I forgot to attach as patch, and also I wanted to post this link:
http://kofoto.rosdahl.net/trac/wiki/UnicodeInPython ..which gives an answer similar to "..it depends". ;-) -- Ciao, / / .o. /--/ ..o / / ANS ooo
Index: base/src/strutils.py
===================================================================
--- base/src/strutils.py (revision 2055)
+++ base/src/strutils.py (working copy)
@@ -89,6 +89,25 @@
return s.decode(ENCODING, "replace")
+def path_to_unicode(s):
+ """
+ Attempts to convert a local filesystem path to a unicode string.
+ First it tries to decode the string based on
+ sys.getfilesystemencoding(). If that fails, it uses
+ str_to_unicode() as a fallback (which in turn tries the
+ locale's preferred encoding, UTF-8, and latin-1 in order).
+ """
+ if not type(s) == str:
+ return s
+
+ try:
+ return s.decode(sys.getfilesystemencoding())
+ except UnicodeDecodeError:
+ pass
+
+ return str_to_unicode(s)
+
+
def unicode_to_str(s):
"""
Attempts to convert a unicode string of unknown character set to a
pgpR5D3vKxMgD.pgp
Description: PGP signature
------------------------------------------------------------------------- Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys - and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________ Freevo-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/freevo-devel
