Imported Upstream version 1.38
[platform/upstream/connman.git] / test / test-session
index 2d82fb6..e45d22b 100755 (executable)
@@ -21,7 +21,7 @@ def extract_list(list):
 
 def extract_values(values):
        val = "{"
-       for key in values.keys():
+       for key in list(values.keys()):
                val += " " + key + "="
                if key in ["PrefixLength"]:
                        val += "%s" % (int(values[key]))
@@ -41,26 +41,26 @@ class Notification(dbus.service.Object):
        @dbus.service.method("net.connman.Notification",
                                in_signature='', out_signature='')
        def Release(self):
-               print "Release %s" % (self._object_path)
+               print("Release %s" % (self._object_path))
                session_name = self._object_path.split('/')[-1]
                self.app.release(session_name)
 
        @dbus.service.method("net.connman.Notification",
                                in_signature='a{sv}', out_signature='')
        def Update(self, settings):
-               print "Update called at %s" % (self._object_path)
+               print("Update called at %s" % (self._object_path))
 
                try:
-                       for key in settings.keys():
+                       for key in list(settings.keys()):
                                if key in ["IPv4", "IPv6"]:
                                        val = extract_values(settings[key])
                                elif key in  ["AllowedBearers"]:
                                        val = extract_list(settings[key])
                                else:
                                        val = settings[key]
-                               print "    %s = %s" % (key, val)
+                               print("    %s = %s" % (key, val))
                except:
-                       print "Exception:"
+                       print("Exception:")
                        traceback.print_exc()
 
 class SessionApplication(dbus.service.Object):
@@ -80,15 +80,15 @@ class SessionApplication(dbus.service.Object):
        def connman_name_owner_changed(self, proxy):
                try:
                        if proxy:
-                               print "connman appeared on D-Bus ", str(proxy)
+                               print("connman appeared on D-Bus ", str(proxy))
 
                                bus = dbus.SystemBus()
                                self.manager = dbus.Interface(bus.get_object("net.connman", "/"),
                                                              "net.connman.Manager")
                        else:
-                               print "connman disappeared on D-Bus"
+                               print("connman disappeared on D-Bus")
                                self.manager = None
-                               for s in self.sessions.keys():
+                               for s in list(self.sessions.keys()):
                                        self.sessions[s]['notify'].remove_from_connection()
                                        self.sessions[s]['notify'] = None
 
@@ -127,18 +127,18 @@ class SessionApplication(dbus.service.Object):
                return value
 
        def find_session(self, session_name):
-               if not session_name in self.sessions.keys():
+               if not session_name in list(self.sessions.keys()):
                        return None
                return self.sessions[session_name]
 
        @dbus.service.method("com.example.TestSession",
                                in_signature='', out_signature='')
        def CreateSession(self, session_name):
-               print "Create session"
+               print("Create session")
 
                s = self.find_session(session_name)
                if s and s['session'] :
-                       print "Session %s already created-> drop reqest" % (session_name)
+                       print("Session %s already created-> drop request" % (session_name))
                        return
 
                try:
@@ -149,29 +149,29 @@ class SessionApplication(dbus.service.Object):
                        s['notify_path'] = self._object_path + "/" + session_name
                        s['notify'] = Notification(bus, self, s['notify_path'])
                        s['notify'].add_to_connection(bus, s['notify_path'])
-                       if not 'settings' in s.keys():
+                       if not 'settings' in list(s.keys()):
                                s['settings'] = {};
                        s['session_path'] = self.manager.CreateSession(s['settings'], s['notify_path'])
-                       print "notify path %s" % (s['notify_path'])
-                       print "session path %s" % (s['session_path'])
+                       print("notify path %s" % (s['notify_path']))
+                       print("session path %s" % (s['session_path']))
                        s['session'] = dbus.Interface(bus.get_object("net.connman", s['session_path']),
                                                      "net.connman.Session")
                        self.sessions[session_name] = s
 
-               except dbus.DBusException, e:
+               except dbus.DBusException as e:
                        if e.get_dbus_name() in ['net.connman.Error.Failed']:
-                               print e.get_dbus_message()
+                               print(e.get_dbus_message())
                                return
                        traceback.print_exc()
 
        @dbus.service.method("com.example.TestSession",
                                in_signature='', out_signature='')
        def DestroySession(self, session_name):
-               print "Destroy session"
+               print("Destroy session")
 
                s = self.find_session(session_name)
                if s == None or s['session'] == None:
-                       print "The session is not running -> drop request"
+                       print("The session is not running -> drop request")
                        return
 
                try:
@@ -182,92 +182,92 @@ class SessionApplication(dbus.service.Object):
        @dbus.service.method("com.example.TestSession",
                                in_signature='', out_signature='')
        def Connect(self, session_name):
-               print "Connect session"
+               print("Connect session")
 
                s = self.find_session(session_name)
                if s == None or s['session'] == None:
-                       print "The session is not running -> drop request"
+                       print("The session is not running -> drop request")
                        return
 
                try:
                        s['session'].Connect()
-               except dbus.DBusException, e:
+               except dbus.DBusException as e:
                        if e.get_dbus_name() in ['net.connman.Error.Failed']:
-                               print e.get_dbus_message()
+                               print(e.get_dbus_message())
                                return
                        traceback.print_exc()
 
        @dbus.service.method("com.example.TestSession",
                                in_signature='', out_signature='')
        def Disconnect(self, session_name):
-               print "Disconnect session"
+               print("Disconnect session")
 
                s = self.find_session(session_name)
                if s == None or s['session'] == None:
-                       print "The session is not running -> drop request"
+                       print("The session is not running -> drop request")
                        return
 
                try:
                        s['session'].Disconnect()
-               except dbus.DBusException, e:
+               except dbus.DBusException as e:
                        if e.get_dbus_name() in ['net.connman.Error.Failed']:
-                               print e.get_dbus_message()
+                               print(e.get_dbus_message())
                                return
                        traceback.print_exc()
 
        @dbus.service.method("com.example.TestSession",
                                in_signature='', out_signature='')
        def Change(self, session_name, key, value):
-               print "Update session settings"
+               print("Update session settings")
 
                s = self.find_session(session_name)
                if s == None or s['session'] == None:
-                       print "The session is not running -> drop request"
+                       print("The session is not running -> drop request")
                        return
 
                try:
                        val = self.type_convert(key, value)
                        s['session'].Change(key, val)
-               except dbus.DBusException, e:
+               except dbus.DBusException as e:
                        if e.get_dbus_name() in ['net.connman.Error.Failed']:
-                               print e.get_dbus_message()
+                               print(e.get_dbus_message())
                                return
                        traceback.print_exc()
 
        @dbus.service.method("com.example.TestSession",
                                in_signature='', out_signature='')
        def Configure(self, session_name, key, value):
-               print "Configure session settings"
+               print("Configure session settings")
                s = self.find_session(session_name)
                if s == None:
                        s = {}
                        s['notify_path'] = None
                        s['notify'] = None
-                       if not 'settings' in s.keys():
+                       if not 'settings' in list(s.keys()):
                                s['settings'] = {};
                        s['session_path'] = None
                        s['session'] = None
                        self.sessions[session_name] = s
                if s and s['session']:
-                       print "The session is running, use change -> drop request"
+                       print("The session is running, use change -> drop request")
                        return
                val = self.type_convert(key, value)
                s['settings'][key] = val
 
 def main():
        if len(sys.argv) < 2:
-               print "Usage: %s <command>" % (sys.argv[0])
-               print ""
-               print "  enable"
-               print "  disable"
-               print "  create <app_path> <session_name>"
-               print "  destroy <app_path> <session_name>"
-               print "  connect <app_path> <session_name>"
-               print "  disconnect <app_path> <session_name>"
-               print "  change <app_path> <session_name> <key> <value>"
-               print "  configure <app_path> <session_name> <key> <value>"
-               print ""
-               print "  run <app_path>"
+               print("Usage: %s <command>" % (sys.argv[0]))
+               print("")
+               print("  enable")
+               print("  disable")
+               print("  create <app_path> <session_name>")
+               print("  destroy <app_path> <session_name>")
+               print("  connect <app_path> <session_name>")
+               print("  disconnect <app_path> <session_name>")
+               print("  change <app_path> <session_name> <key> <value>")
+               print("  configure <app_path> <session_name> <key> <value>")
+               print("")
+               print("  run <app_path>")
                sys.exit(1)
 
        dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
@@ -287,7 +287,7 @@ def main():
                return
 
        if (len(sys.argv) < 3):
-               print "Need test application path"
+               print("Need test application path")
                sys.exit(1)
 
        app_path = sys.argv[2]
@@ -321,20 +321,20 @@ def main():
 
        elif sys.argv[1] == "change":
                if len(sys.argv) < 5:
-                       print "Arguments missing"
+                       print("Arguments missing")
                        sys.exit(1)
 
                app.Change(sys.argv[3], sys.argv[4], sys.argv[5:])
 
        elif sys.argv[1] == "configure":
                if len(sys.argv) < 5:
-                       print "Arguments missing"
+                       print("Arguments missing")
                        sys.exit(1)
 
                app.Configure(sys.argv[3], sys.argv[4], sys.argv[5:])
 
        else:
-               print "Unknown command '%s'" % sys.argv[1]
+               print("Unknown command '%s'" % sys.argv[1])
                sys.exit(1)
 
 if __name__ == '__main__':