[d-feet] Make d-feet ready for Python 3



commit 3922f34be22b36af147d3b7bb3c81d5f1444d7a1
Author: Thomas Bechtold <thomasbechtold jpberlin de>
Date:   Wed Nov 7 18:00:36 2012 +0100

    Make d-feet ready for Python 3

 d-feet                           |    2 +-
 dfeet/DFeetApp.py                |   15 ++++++++-------
 dfeet/_ui/addconnectiondialog.py |    3 ++-
 dfeet/_ui/executemethoddialog.py |    2 +-
 dfeet/bus_watch.py               |   14 ++++++++------
 dfeet/dbus_utils.py              |    4 +++-
 dfeet/introspection.py           |    9 +++++----
 dfeet/introspection_helper.py    |   18 +++++++++---------
 dfeet/settings.py                |   20 ++++++++++++++------
 9 files changed, 51 insertions(+), 36 deletions(-)
---
diff --git a/d-feet b/d-feet
index 0756bd9..538e63d 100755
--- a/d-feet
+++ b/d-feet
@@ -40,7 +40,7 @@ else:
                 }
 
 #must set variables before importing Globals because it requires them
-for var, path in ENV_PATHS.iteritems():
+for var, path in ENV_PATHS.items():
     #if it is not already set, set the enviroment variable.
     os.environ.setdefault(var, path)
 
diff --git a/dfeet/DFeetApp.py b/dfeet/DFeetApp.py
index 506cefb..52a866a 100644
--- a/dfeet/DFeetApp.py
+++ b/dfeet/DFeetApp.py
@@ -1,12 +1,13 @@
 # -*- coding: utf-8 -*-
-from gi.repository import Gtk, Gio, GObject
+from __future__ import print_function
 
+from gi.repository import Gtk, Gio, GObject
 
-from bus_watch import BusWatch
-from settings import Settings
-from _ui.uiloader import UILoader
-from _ui.addconnectiondialog import AddConnectionDialog
-from _ui.executemethoddialog import ExecuteMethodDialog
+from dfeet.bus_watch import BusWatch
+from dfeet.settings import Settings
+from dfeet._ui.uiloader import UILoader
+from dfeet._ui.addconnectiondialog import AddConnectionDialog
+from dfeet._ui.executemethoddialog import ExecuteMethodDialog
 
 
 class NotebookTabLabel(Gtk.Box):
@@ -126,7 +127,7 @@ class DFeetApp(Gtk.Application):
                     if (len(self.bus_history) > self.HISTORY_MAX_SIZE):
                         self.bus_history = self.bus_history[0:self.HISTORY_MAX_SIZE]
                 except Exception as e:
-                    print "can not connect to '%s': %s" % (address, str(e))
+                    print("can not connect to '%s': %s" % (address, str(e)))
         dialog.destroy()
 
 
diff --git a/dfeet/_ui/addconnectiondialog.py b/dfeet/_ui/addconnectiondialog.py
index 82ddafc..d42826f 100644
--- a/dfeet/_ui/addconnectiondialog.py
+++ b/dfeet/_ui/addconnectiondialog.py
@@ -1,5 +1,6 @@
+# -*- coding: utf-8 -*-
 from gi.repository import Gtk, Gio
-from uiloader import UILoader
+from dfeet._ui.uiloader import UILoader
 
 class AddConnectionDialog:
 
diff --git a/dfeet/_ui/executemethoddialog.py b/dfeet/_ui/executemethoddialog.py
index c80aab7..790f23c 100644
--- a/dfeet/_ui/executemethoddialog.py
+++ b/dfeet/_ui/executemethoddialog.py
@@ -3,7 +3,7 @@ import time
 from pprint import pformat
 from gi.repository import GLib, Gio
 
-from uiloader import UILoader
+from dfeet._ui.uiloader import UILoader
 
 
 class ExecuteMethodDialog:
diff --git a/dfeet/bus_watch.py b/dfeet/bus_watch.py
index 7a4c248..ccb0f6d 100644
--- a/dfeet/bus_watch.py
+++ b/dfeet/bus_watch.py
@@ -1,8 +1,10 @@
 # -*- coding: utf-8 -*-
+from __future__ import print_function
 
 from gi.repository import GObject, Gtk, Gio
-from _ui.uiloader import UILoader
-from introspection import AddressInfo
+
+from dfeet._ui.uiloader import UILoader
+from dfeet.introspection import AddressInfo
 
 
 class DBusBusName(GObject.GObject):
@@ -14,7 +16,7 @@ class DBusBusName(GObject.GObject):
         self.__cmdline = ''
 
     def __repr__(self):
-        return u"%s (pid: %s)" % (self.bus_name_unique, self.pid)
+        return "%s (pid: %s)" % (self.bus_name_unique, self.pid)
 
     def __update_cmdline(self):
         if self.pid > 0:
@@ -144,7 +146,7 @@ class BusWatch(object):
                                                   error_handler =  self.__get_unix_process_id_error_cb,
                                                   user_data=bus_name_obj)
         #add bus to liststore
-        return self.liststore_model.append([bus_name_obj, 0, u"%s" % (bus_name_obj.bus_name_unique), bus_name_obj.cmdline])
+        return self.liststore_model.append([bus_name_obj, 0, "%s" % (bus_name_obj.bus_name_unique), bus_name_obj.cmdline])
 
 
     def __liststore_model_remove(self, bus_name_obj):
@@ -189,7 +191,7 @@ class BusWatch(object):
 
 
     def __list_names_error_handler(self, obj, error, userdata):
-        print "error getting bus names: %s" % str(error)
+        print("error getting bus names: %s" % str(error))
 
 
     def __get_unix_process_id_cb(self, obj, pid, bus_name_obj):
@@ -197,7 +199,7 @@ class BusWatch(object):
 
 
     def __get_unix_process_id_error_cb(self, obj, error, bus_name_obj):
-        print "error getting unix process id for %s: %s" % (bus_name_obj.bus_name_unique, str(error))
+        print("error getting unix process id for %s: %s" % (bus_name_obj.bus_name_unique, str(error)))
         bus_name_obj.pid = 0
 
 
diff --git a/dfeet/dbus_utils.py b/dfeet/dbus_utils.py
index 8dcd541..2b5c48b 100644
--- a/dfeet/dbus_utils.py
+++ b/dfeet/dbus_utils.py
@@ -1,4 +1,6 @@
 # -*- coding: utf-8 -*-
+from __future__ import print_function
+
 def convert_complex_type(subsig):
     result = None
     len_consumed = 0
@@ -140,7 +142,7 @@ def type_list_to_string(type_list):
             try:
                 result += dbus_type
             except:
-                print type_list
+                print(type_list)
 
     return result[2:]
 
diff --git a/dfeet/introspection.py b/dfeet/introspection.py
index a30818b..e0dc277 100644
--- a/dfeet/introspection.py
+++ b/dfeet/introspection.py
@@ -1,11 +1,12 @@
 # -*- coding: utf-8 -*-
+from __future__ import print_function
 
 from gi.repository import Gtk, Gio, GLib
-from _ui.executemethoddialog import ExecuteMethodDialog
+from dfeet._ui.executemethoddialog import ExecuteMethodDialog
 
-from _ui.uiloader import UILoader
+from dfeet._ui.uiloader import UILoader
 
-from introspection_helper import DBusNode, DBusInterface, DBusProperty, DBusSignal, DBusMethod
+from dfeet.introspection_helper import DBusNode, DBusInterface, DBusProperty, DBusSignal, DBusMethod
 
 
 class AddressInfo():
@@ -159,7 +160,7 @@ class AddressInfo():
             res = connection.call_finish(result_async)
         except Exception as e:
             #got an exception (eg dbus timeout). show the exception
-            print "Exception: '%s'" % (str(e))
+            print("Exception: '%s'" % (str(e)))
             self.__messagedialog.set_title("DBus Exception")
             self.__messagedialog.set_property("text", "%s : %s" % (self.name, str(e)))
             self.__messagedialog.run()
diff --git a/dfeet/introspection_helper.py b/dfeet/introspection_helper.py
index f45c0ed..9fa74dd 100644
--- a/dfeet/introspection_helper.py
+++ b/dfeet/introspection_helper.py
@@ -1,7 +1,7 @@
 # -*- coding: utf-8 -*-
 
 from gi.repository import GObject, Gio
-import dbus_utils
+from dfeet import dbus_utils
 
 
 def args_signature_markup(arg_signature):
@@ -21,7 +21,7 @@ class DBusNode(GObject.GObject):
         self.__node_info = node_info # Gio.GDBusNodeInfo object
 
     def __repr__(self):
-        return u"Name: %s ; ObjPath: %s ; NodeInfo: %s" % (self.name, self.object_path, self.node_info)
+        return "Name: %s ; ObjPath: %s ; NodeInfo: %s" % (self.name, self.object_path, self.node_info)
 
     @property
     def name(self):
@@ -43,7 +43,7 @@ class DBusInterface(DBusNode):
         self.__iface_info = iface_info # Gio.GDBusInterfaceInfo object
 
     def __repr__(self):
-        return u"iface '%s' on node '%s'" % (self.iface_info.name, self.node_info.path)
+        return "iface '%s' on node '%s'" % (self.iface_info.name, self.node_info.path)
 
     @property
     def iface_info(self):
@@ -59,7 +59,7 @@ class DBusProperty(DBusInterface):
 
     def __repr__(self):
         sig = dbus_utils.sig_to_string(self.property_info.signature)
-        return u"%s %s (%s)" % (sig, self.property_info.name, self.property_info.flags)
+        return "%s %s (%s)" % (sig, self.property_info.name, self.property_info.flags)
 
     @property
     def property_info(self):
@@ -109,7 +109,7 @@ class DBusSignal(DBusInterface):
         self.__signal_info = signal_info #Gio.GDBusSignalInfo object
 
     def __repr__(self):
-        return u"%s" % (self.signal_info.name)
+        return "%s" % (self.signal_info.name)
     
     @property
     def signal_info(self):
@@ -143,7 +143,7 @@ class DBusMethod(DBusInterface):
         self.__method_info = method_info #Gio.GDBusMethodInfo object
 
     def __repr__(self):
-        return u"%s(%s) â %s (%s)" % (self.method_info.name, self.in_args_str, self.out_args_str, DBusInterface.__repr__(self))
+        return "%s(%s) â %s (%s)" % (self.method_info.name, self.in_args_str, self.out_args_str, DBusInterface.__repr__(self))
 
     @property
     def method_info(self):
@@ -151,7 +151,7 @@ class DBusMethod(DBusInterface):
 
     @property
     def markup_str(self):
-        return u"%s %s <b>â</b> %s" % (self.method_info.name, self.in_args_markup_str, self.out_args_markup_str)
+        return "%s %s <b>â</b> %s" % (self.method_info.name, self.in_args_markup_str, self.out_args_markup_str)
 
     @property
     def in_args(self):
@@ -171,7 +171,7 @@ class DBusMethod(DBusInterface):
     
     @property
     def in_args_str(self):
-        result = u''
+        result = ""
         for arg in self.in_args:
             result += "%s %s, " % (arg['signature'], arg['name'])
         
@@ -179,7 +179,7 @@ class DBusMethod(DBusInterface):
 
     @property
     def out_args_str(self):
-        result = u''
+        result = ""
         for arg in self.out_args:
             result += "%s %s, " % (arg['signature'], arg['name'])
         
diff --git a/dfeet/settings.py b/dfeet/settings.py
index 223607f..47c256f 100644
--- a/dfeet/settings.py
+++ b/dfeet/settings.py
@@ -4,8 +4,12 @@
 #
 #   portions taken from the Jokosher project
 #
-
-import ConfigParser
+try:
+    #python2.x
+    import ConfigParser as configparser
+except:
+    #python3
+    import configparser
 import os
 import re
 
@@ -74,6 +78,10 @@ class ConfigTokenizer():
         return self
 
     def next(self):
+        """for python2"""
+        return self.__next__()
+
+    def __next__(self):
         for r in self._parse_order:
             m = r.match(self._consumable)
             if m:
@@ -107,13 +115,13 @@ class Settings:
                         If None, the default $XDG_CONFIG_HOME/d-feet/config will be used.
         """
         if not filename:
-            if os.environ.has_key('XDG_CONFIG_HOME'):
+            if 'XDG_CONFIG_HOME' in list(os.environ.keys()):
                 self.filename = os.path.join(os.environ['XDG_CONFIG_HOME'], 'd-feet', 'config')
             else:
                 self.filename = os.path.join(os.environ['HOME'], '.config', 'd-feet', 'config')
         else:
             self.filename = filename
-        self.config = ConfigParser.ConfigParser()
+        self.config = configparser.ConfigParser()
 
         self.read()
 
@@ -128,7 +136,7 @@ class Settings:
 
     def decode_list(self, s):
         result = []
-        lex = ConfigTokenizer(s);
+        lex = ConfigTokenizer(s)
         for item in lex:
             if item.is_value():
                 result.append(str(item))
@@ -169,7 +177,7 @@ class Settings:
             if self.general[key] == None:
                 self.general[key] = ''
 
-            self.config.set("General", key, self.general[key])
+            self.config.set("General", str(key), str(self.general[key]))
 
         # make sure that the directory that the config file is in exists
         new_file_dir = os.path.split(self.filename)[0]



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]