vlc/python | branch: master | Olivier Aubert <[email protected]> | Wed Sep 30 15:51:41 2015 +0200| [3f9a8636ce1b3488b85c797dd2cbc1d1bbb008e1] | committer: Olivier Aubert
Use utf-8 encoding for all strings passed through the libvlc API The libvlc API explicitly uses utf-8 for all strings. Using sys.getfilesystemencoding() on the python side will not produce the appropriate encoding especially on windows. Reported by Tomas Groth <[email protected]> > http://git.videolan.org/gitweb.cgi/vlc/python.git/?a=commit;h=3f9a8636ce1b3488b85c797dd2cbc1d1bbb008e1 --- header.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/header.py b/header.py index f608046..50c4b9e 100755 --- a/header.py +++ b/header.py @@ -50,6 +50,11 @@ from inspect import getargspec build_date = '' # build time stamp and __version__, see generate.py +# The libvlc doc states that filenames are expected to be in UTF8, do +# not rely on sys.getfilesystemencoding() which will be confused, +# esp. on windows. +DEFAULT_ENCODING = 'utf-8' + if sys.version_info[0] > 2: str = str unicode = str @@ -60,7 +65,7 @@ if sys.version_info[0] > 2: """Translate string or bytes to bytes. """ if isinstance(s, str): - return bytes(s, sys.getfilesystemencoding()) + return bytes(s, DEFAULT_ENCODING) else: return s @@ -68,7 +73,7 @@ if sys.version_info[0] > 2: """Translate bytes to string. """ if isinstance(b, bytes): - return b.decode(sys.getfilesystemencoding()) + return b.decode(DEFAULT_ENCODING) else: return b else: @@ -81,7 +86,7 @@ else: """Translate string or bytes to bytes. """ if isinstance(s, unicode): - return s.encode(sys.getfilesystemencoding()) + return s.encode(DEFAULT_ENCODING) else: return s @@ -89,7 +94,7 @@ else: """Translate bytes to unicode string. """ if isinstance(b, str): - return unicode(b, sys.getfilesystemencoding()) + return unicode(b, DEFAULT_ENCODING) else: return b _______________________________________________ vlc-commits mailing list [email protected] https://mailman.videolan.org/listinfo/vlc-commits
