Update of /cvsroot/gtkpod/libgpod/bindings/python
In directory sc8-pr-cvs2.sourceforge.net:/tmp/cvs-serv9047/bindings/python
Modified Files:
gtkpod.py
Log Message:
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.
Index: gtkpod.py
===================================================================
RCS file: /cvsroot/gtkpod/libgpod/bindings/python/gtkpod.py,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- gtkpod.py 14 Jan 2007 22:25:25 -0000 1.5
+++ gtkpod.py 14 Jan 2007 22:44:33 -0000 1.6
@@ -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 @@
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')
-------------------------------------------------------------------------
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
_______________________________________________
gtkpod-cvs2 mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/gtkpod-cvs2