tests: better handling of encodings in SMS test tool

Python usually uses Unicode, but often the shell encoding
will be in UTF-8, so Python needs some help converting the
message to Unicode.  Use LANG to do that if we can.
This commit is contained in:
Dan Williams
2012-01-18 13:00:50 -06:00
parent 3f4056caab
commit 6789a87a58

View File

@@ -17,13 +17,22 @@
import sys
import dbus
import os
if len(sys.argv) != 3:
print "Usage: %s <number> <message>" % sys.argv[0]
sys.exit(1)
number = sys.argv[1]
message = sys.argv[2]
try:
lang = os.getenv("LANG")
idx = lang.find(".")
if idx != -1:
lang = lang[idx + 1:]
except KeyError:
lang = "utf-8"
message = unicode(sys.argv[2], "utf-8")
bus = dbus.SystemBus()