diff options
author | Nicholas Piper <nicholas@users.sourceforge.net> | 2007-01-14 22:44:33 +0000 |
---|---|---|
committer | Nicholas Piper <nicholas@users.sourceforge.net> | 2007-01-14 22:44:33 +0000 |
commit | a7522495889e8478ad0077143b0ca0223cd5d66a (patch) | |
tree | 1b43210b7186c375c145d6c8eec24c65d886faa4 /bindings | |
parent | afbb612b485982bca823edca91e43997aa810cc6 (diff) | |
download | libgpod-a7522495889e8478ad0077143b0ca0223cd5d66a.tar.gz libgpod-a7522495889e8478ad0077143b0ca0223cd5d66a.tar.xz libgpod-a7522495889e8478ad0077143b0ca0223cd5d66a.zip |
At a suggestion from Todd, attempt to fix writing unicode values. Ideally, the caller will either have not changed the userdata items OR will have populated them with unicode objects.
git-svn-id: https://gtkpod.svn.sf.net/svnroot/gtkpod/libgpod/trunk@1370 f01d2545-417e-4e96-918e-98f8d0dbbcb6
Diffstat (limited to 'bindings')
-rw-r--r-- | bindings/python/gtkpod.py | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/bindings/python/gtkpod.py b/bindings/python/gtkpod.py index 3a1260b..be3ebfc 100644 --- a/bindings/python/gtkpod.py +++ b/bindings/python/gtkpod.py @@ -3,12 +3,15 @@ import sha import os import socket +import types +import locale # This file is originally stolen from pypod-0.5.0 # http://superduper.net/index.py?page=pypod # I hope that's ok, both works are GPL. hostname = socket.gethostname() +defaultencoding = locale.getpreferredencoding() class ParseError(Exception): """Exception for parse errors.""" @@ -42,7 +45,18 @@ def write(filename, db, itunesdb_file): file = open(filename, "w") def write_pair(name, value): - value = unicode(value).encode("utf-8") + if isinstance(value,types.UnicodeType): + # encode as UTF-8 + value = value.encode("utf-8") + elif isinstance(value,types.StringType): + # assume it's in our default locale, so decode + # then re-encode as UTF-8 + value = unicode(value, + defaultencoding).encode("utf-8") + else: + value = str(value) + + file.write("=".join([name, value])) file.write('\n') |