summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNicholas Piper <nicholas@users.sourceforge.net>2007-01-14 22:44:33 +0000
committerNicholas Piper <nicholas@users.sourceforge.net>2007-01-14 22:44:33 +0000
commit96cce23e4b026d56df80e4f67727e12b1a30567d (patch)
tree1b43210b7186c375c145d6c8eec24c65d886faa4
parent7a6f5f67ecb62f100fce8c86e16c0da5569d4750 (diff)
downloadlibgpod-96cce23e4b026d56df80e4f67727e12b1a30567d.tar.gz
libgpod-96cce23e4b026d56df80e4f67727e12b1a30567d.tar.xz
libgpod-96cce23e4b026d56df80e4f67727e12b1a30567d.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
-rw-r--r--bindings/python/gtkpod.py16
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')