* [PATCH] monitor-ofono: Fix to print non-English characters
@ 2012-07-26 15:57 Philippe Nunes
2012-07-26 15:57 ` [PATCH v2] test-ussd becomes send-ussd This script can be used to handle network initiated USSDs Philippe Nunes
2012-07-27 5:34 ` [PATCH] monitor-ofono: Fix to print non-English characters Denis Kenzior
0 siblings, 2 replies; 4+ messages in thread
From: Philippe Nunes @ 2012-07-26 15:57 UTC (permalink / raw)
To: ofono
[-- Attachment #1: Type: text/plain, Size: 1085 bytes --]
The default encoding for a Python bytestring is ASCII. But the
SMS/USSD text is encoded in UTF-8.
This is why trying to convert non-English characters (Unicode
characters beyond 128) produces the error
"UnicodeEncodeError: 'ascii' codec can't encode character".
---
test/monitor-ofono | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/test/monitor-ofono b/test/monitor-ofono
index 8570c34..dcc5ff5 100755
--- a/test/monitor-ofono
+++ b/test/monitor-ofono
@@ -69,11 +69,11 @@ def event(member, path, interface):
def message(msg, args, member, path, interface):
iface = interface[interface.rfind(".") + 1:]
print "{%s} [%s] %s %s (%s)" % (iface, path, member,
- str(msg), pretty(args))
+ msg, pretty(args))
def ussd(msg, member, path, interface):
iface = interface[interface.rfind(".") + 1:]
- print "{%s} [%s] %s %s" % (iface, path, member, str(msg))
+ print "{%s} [%s] %s %s" % (iface, path, member, msg)
def value(value, member, path, interface):
iface = interface[interface.rfind(".") + 1:]
--
1.7.9.5
^ permalink raw reply related [flat|nested] 4+ messages in thread* [PATCH v2] test-ussd becomes send-ussd This script can be used to handle network initiated USSDs
2012-07-26 15:57 [PATCH] monitor-ofono: Fix to print non-English characters Philippe Nunes
@ 2012-07-26 15:57 ` Philippe Nunes
2012-07-27 5:36 ` Denis Kenzior
2012-07-27 5:34 ` [PATCH] monitor-ofono: Fix to print non-English characters Denis Kenzior
1 sibling, 1 reply; 4+ messages in thread
From: Philippe Nunes @ 2012-07-26 15:57 UTC (permalink / raw)
To: ofono
[-- Attachment #1: Type: text/plain, Size: 4108 bytes --]
---
Makefile.am | 2 +-
test/send-ussd | 57 ++++++++++++++++++++++++++++++++++++++++++
test/test-ussd | 75 --------------------------------------------------------
3 files changed, 58 insertions(+), 76 deletions(-)
create mode 100755 test/send-ussd
delete mode 100755 test/test-ussd
diff --git a/Makefile.am b/Makefile.am
index e012d3f..b35cf1f 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -583,7 +583,7 @@ test_scripts = test/backtrace \
test/test-ss-control-cf \
test/test-ss-control-cs \
test/test-voicecall \
- test/test-ussd \
+ test/send-ussd \
test/cancel-ussd \
test/initiate-ussd \
test/offline-modem \
diff --git a/test/send-ussd b/test/send-ussd
new file mode 100755
index 0000000..fcabd21
--- /dev/null
+++ b/test/send-ussd
@@ -0,0 +1,57 @@
+#!/usr/bin/python
+
+import sys
+import dbus
+
+if (len(sys.argv) < 2):
+ print "Usage: %s [modem] <ussd-string>" % (sys.argv[0])
+ sys.exit(1)
+
+bus = dbus.SystemBus()
+
+manager = dbus.Interface(bus.get_object('org.ofono', '/'),
+ 'org.ofono.Manager')
+
+modems = manager.GetModems()
+
+if (len(sys.argv) == 2):
+ path = modems[0][0]
+ ussdstring = sys.argv[1]
+else:
+ path = sys.argv[1]
+ ussdstring = sys.argv[2]
+
+ussd = dbus.Interface(bus.get_object('org.ofono', path),
+ 'org.ofono.SupplementaryServices')
+
+properties = ussd.GetProperties()
+state = properties["State"]
+
+print "State: %s" % (state)
+
+if state == "idle":
+ result = ussd.Initiate(ussdstring, timeout=100)
+ print result[0] + ": " + result[1]
+elif state == "user-response":
+ print ussd.Respond(ussdstring, timeout=100)
+else:
+ sys.exit(1);
+
+properties = ussd.GetProperties()
+state = properties["State"]
+
+if state == "idle":
+ sys.exit(0)
+
+print "State: %s" % (state)
+
+while state == "user-response":
+ response = raw_input("Enter response: ")
+
+ print ussd.Respond(response, timeout=100)
+
+ properties = ussd.GetProperties()
+ state = properties["State"]
+
+ if state != "idle":
+ print "State: %s" % (state)
diff --git a/test/test-ussd b/test/test-ussd
deleted file mode 100755
index c21f5e3..0000000
--- a/test/test-ussd
+++ /dev/null
@@ -1,75 +0,0 @@
-#!/usr/bin/python
-
-import sys
-import gobject
-import os
-
-import dbus
-import dbus.mainloop.glib
-
-state = None
-
-def ussd_notification_received(content):
- print("Network sent a Notification: " + content)
-
-def ussd_request_received(content):
- print("Network sent a Request: " + content)
- ss.Cancel()
-
-def ussd_property_changed(name, value):
- global state
- if name != "State":
- return
- print("USSD session state is " + value)
- state = str(value)
-
-def stdin_handler(fd, condition):
- s = os.read(fd.fileno(), 160).rstrip()
- if not s:
- ss.Cancel()
- elif state == "user-response":
- print ss.Respond(s, timeout = 100)
- elif state == "idle":
- print ss.Initiate(s, timeout = 100)
- else:
- print "Invalid state", state
- return True
-
-if __name__ == "__main__":
- if (len(sys.argv) < 2):
- print "Usage: %s [modem] <ussd-string>" % (sys.argv[0])
- sys.exit(1)
-
- dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
-
- bus = dbus.SystemBus()
-
- manager = dbus.Interface(bus.get_object('org.ofono', '/'),
- 'org.ofono.Manager')
-
- modems = manager.GetModems()
- modem = modems[0][0]
-
- if (len(sys.argv) == 2):
- ussd = sys.argv[1]
- else:
- modem = sys.argv[1]
- ussd = sys.argv[2]
-
- ss = dbus.Interface(bus.get_object('org.ofono', modem),
- 'org.ofono.SupplementaryServices')
-
- props = ss.GetProperties()
- for p in props:
- ussd_property_changed(p, props[p])
-
- ss.connect_to_signal("NotificationReceived", ussd_notification_received)
- ss.connect_to_signal("RequestReceived", ussd_request_received)
- ss.connect_to_signal("PropertyChanged", ussd_property_changed)
-
- print ss.Initiate(ussd, timeout=100)
-
- gobject.io_add_watch(sys.stdin, gobject.IO_IN, stdin_handler)
-
- mainloop = gobject.MainLoop()
- mainloop.run()
--
1.7.9.5
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH] monitor-ofono: Fix to print non-English characters
2012-07-26 15:57 [PATCH] monitor-ofono: Fix to print non-English characters Philippe Nunes
2012-07-26 15:57 ` [PATCH v2] test-ussd becomes send-ussd This script can be used to handle network initiated USSDs Philippe Nunes
@ 2012-07-27 5:34 ` Denis Kenzior
1 sibling, 0 replies; 4+ messages in thread
From: Denis Kenzior @ 2012-07-27 5:34 UTC (permalink / raw)
To: ofono
[-- Attachment #1: Type: text/plain, Size: 494 bytes --]
Hi Philippe,
On 07/26/2012 10:57 AM, Philippe Nunes wrote:
> The default encoding for a Python bytestring is ASCII. But the
> SMS/USSD text is encoded in UTF-8.
> This is why trying to convert non-English characters (Unicode
> characters beyond 128) produces the error
> "UnicodeEncodeError: 'ascii' codec can't encode character".
> ---
> test/monitor-ofono | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
Patch has been applied, thanks.
Regards,
-Denis
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2012-07-27 5:36 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-07-26 15:57 [PATCH] monitor-ofono: Fix to print non-English characters Philippe Nunes
2012-07-26 15:57 ` [PATCH v2] test-ussd becomes send-ussd This script can be used to handle network initiated USSDs Philippe Nunes
2012-07-27 5:36 ` Denis Kenzior
2012-07-27 5:34 ` [PATCH] monitor-ofono: Fix to print non-English characters Denis Kenzior
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.