Port obmc to python3.5

Change-Id: I1ed6c6bd914635485a697369048a8be9e5919fc6
Signed-off-by: Balaji B Rao <balajibapu@gmail.com>
diff --git a/obmc/dbuslib/bindings.py b/obmc/dbuslib/bindings.py
index 3eea6a5..8a04447 100644
--- a/obmc/dbuslib/bindings.py
+++ b/obmc/dbuslib/bindings.py
@@ -187,7 +187,7 @@
         obj = self.objects.pop(object_path, None)
         obj.remove_from_connection()
         if self._export:
-            self.InterfacesRemoved(object_path, obj.properties.keys())
+            self.InterfacesRemoved(object_path, list(obj.properties.keys()))
 
     def get(self, object_path, default=None):
         return self.objects.get(object_path, default)
@@ -197,7 +197,7 @@
         in_signature='', out_signature='a{oa{sa{sv}}}')
     def GetManagedObjects(self):
         data = {}
-        for objpath in self.objects.keys():
+        for objpath in list(self.objects.keys()):
             data[objpath] = self.objects[objpath].properties
         return data
 
diff --git a/obmc/dbuslib/introspection.py b/obmc/dbuslib/introspection.py
index 9ec9c05..5288bcb 100644
--- a/obmc/dbuslib/introspection.py
+++ b/obmc/dbuslib/introspection.py
@@ -104,7 +104,7 @@
 
     def _discover_flat(self, path, parser):
         items = {}
-        interfaces = parser.get_interfaces().keys()
+        interfaces = list(parser.get_interfaces().keys())
         if interfaces:
             items[path] = {}
             items[path]['interfaces'] = interfaces
diff --git a/obmc/dbuslib/propertycacher.py b/obmc/dbuslib/propertycacher.py
index 7888b46..ebbe92a 100644
--- a/obmc/dbuslib/propertycacher.py
+++ b/obmc/dbuslib/propertycacher.py
@@ -15,7 +15,7 @@
 # permissions and limitations under the License.
 
 import os
-import cPickle
+import pickle
 import json
 
 CACHE_PATH = '/var/cache/obmc/'
@@ -28,7 +28,7 @@
 
 
 def save(obj_path, iface_name, properties):
-    print "Caching: "+obj_path
+    print("Caching: "+obj_path)
     filename = getCacheFilename(obj_path, iface_name)
     parent = os.path.dirname(filename)
     try:
@@ -39,11 +39,11 @@
                 ## use json module to convert dbus datatypes
                 props = json.dumps(properties[iface_name])
                 prop_obj = json.loads(props)
-                cPickle.dump(prop_obj, output)
+                pickle.dump(prop_obj, output)
             except Exception as e:
-                print "ERROR: "+str(e)
+                print("ERROR: "+str(e))
     except:
-        print "ERROR opening cache file: "+filename
+        print("ERROR opening cache file: "+filename)
 
 
 def load(obj_path, iface_name, properties):
@@ -52,14 +52,14 @@
     if (os.path.isfile(filename)):
         if iface_name in properties:
             properties[iface_name] = {}
-        print "Loading from cache: "+filename
+        print("Loading from cache: "+filename)
         try:
             p = open(filename, 'rb')
-            data = cPickle.load(p)
-            for prop in data.keys():
+            data = pickle.load(p)
+            for prop in list(data.keys()):
                 properties[iface_name][prop] = data[prop]
 
         except Exception as e:
-            print "ERROR: Loading cache file: " + str(e)
+            print("ERROR: Loading cache file: " + str(e))
         finally:
             p.close()
diff --git a/obmc/sensors.py b/obmc/sensors.py
index fba7a91..3fd76b2 100644
--- a/obmc/sensors.py
+++ b/obmc/sensors.py
@@ -91,7 +91,7 @@
     @dbus.service.method(
         SensorValue.IFACE_NAME, in_signature='v', out_signature='')
     def setValue(self, value):
-        print "Setting boot count to " + str(value)
+        print("Setting boot count to " + str(value))
         SensorValue.setValue(self, value)
 
 
@@ -121,7 +121,7 @@
     @dbus.service.method(
         SensorValue.IFACE_NAME, in_signature='v', out_signature='')
     def setValue(self, value):
-        print "Setting Power Supply Derating is not allowed"
+        print("Setting Power Supply Derating is not allowed")
 
 
 class TurboAllowedSensor(VirtualSensor):
diff --git a/obmc/utils/dtree.py b/obmc/utils/dtree.py
index 59d03da..07530d4 100644
--- a/obmc/utils/dtree.py
+++ b/obmc/utils/dtree.py
@@ -27,13 +27,13 @@
 
     if(isinstance(obj, dict)):
         nodes = []
-        for k, v in obj.iteritems():
+        for k, v in obj.items():
             if(isinstance(v, dict)):
                 nodes.append((k, v))
                 continue
-            if(isinstance(v, basestring) and v.lower() == 'true'):
+            if(isinstance(v, str) and v.lower() == 'true'):
                 fd.write('%s%s' % (tab, k))
-            elif(isinstance(v, basestring) and v.lower() == 'false'):
+            elif(isinstance(v, str) and v.lower() == 'false'):
                 continue
             else:
                 fd.write('%s%s = ' % (tab, k))
@@ -51,7 +51,7 @@
         else:
             fd.write("<%d>" % obj)
 
-    if(isinstance(obj, basestring)):
+    if(isinstance(obj, str)):
         fd.write("\"%s\"" % obj)
 
     if(isinstance(obj, list)):
diff --git a/obmc/utils/pathtree.py b/obmc/utils/pathtree.py
index a13c6cb..190e3b4 100644
--- a/obmc/utils/pathtree.py
+++ b/obmc/utils/pathtree.py
@@ -20,7 +20,7 @@
         self.path_tree = path_tree
         self.path = []
         self.itlist = []
-        self.subtree = ['/'] + filter(bool, subtree.split('/'))
+        self.subtree = ['/'] + list(filter(bool, subtree.split('/')))
         self.depth = depth
         d = path_tree.root
         for k in self.subtree:
@@ -28,15 +28,15 @@
                 d = d[k]['children']
             except KeyError:
                 raise KeyError(subtree)
-        self.it = d.iteritems()
+        self.it = iter(d.items())
 
     def __iter__(self):
         return self
 
     def __next__(self):
-        return super(PathTreeItemIterator, self).next()
+        return next(super(PathTreeItemIterator, self))
 
-    def next(self):
+    def __next__(self):
         key, value = self._next()
         path = self.subtree[0] + '/'.join(self.subtree[1:] + self.path)
         return path, value.get('data')
@@ -44,13 +44,13 @@
     def _next(self):
         try:
             while True:
-                x = self.it.next()
+                x = next(self.it)
                 depth_exceeded = len(self.path) + 1 > self.depth
                 if self.depth and depth_exceeded:
                     continue
                 self.itlist.append(self.it)
                 self.path.append(x[0])
-                self.it = x[1]['children'].iteritems()
+                self.it = iter(x[1]['children'].items())
                 break
 
         except StopIteration:
@@ -68,7 +68,7 @@
     def __init__(self, path_tree, subtree, depth):
         super(PathTreeKeyIterator, self).__init__(path_tree, subtree, depth)
 
-    def next(self):
+    def __next__(self):
         return super(PathTreeKeyIterator, self).next()[0]
 
 
@@ -92,7 +92,7 @@
 
     def _get_node(self, key):
         kids = 'children'
-        elements = ['/'] + filter(bool, key.split('/'))
+        elements = ['/'] + list(filter(bool, key.split('/')))
         d = self.root
         for k in elements[:-1]:
             try:
@@ -106,14 +106,14 @@
         return self
 
     def __missing__(self, key):
-        for x in self.iterkeys():
+        for x in self.keys():
             if key == x:
                 return False
         return True
 
     def __delitem__(self, key):
         kids = 'children'
-        elements = ['/'] + filter(bool, key.split('/'))
+        elements = ['/'] + list(filter(bool, key.split('/')))
         d = self.root
         for k in elements[:-1]:
             try:
@@ -126,7 +126,7 @@
 
     def __setitem__(self, key, value):
         kids = 'children'
-        elements = ['/'] + filter(bool, key.split('/'))
+        elements = ['/'] + list(filter(bool, key.split('/')))
         d = self.root
         for k in elements[:-1]:
             d = d.setdefault(k, {kids: {}})[kids]
@@ -152,7 +152,7 @@
         return x
 
     def get_children(self, key):
-        return [x for x in self._get_node(key)['children'].iterkeys()]
+        return [x for x in self._get_node(key)['children'].keys()]
 
     def demote(self, key):
         n = self._get_node(key)
@@ -174,12 +174,12 @@
 
     def iterkeys(self, subtree='/', depth=None):
         if not self.root:
-            return {}.iterkeys()
+            return iter({}.keys())
         return PathTreeKeyIterator(self, subtree, depth)
 
     def iteritems(self, subtree='/', depth=None):
         if not self.root:
-            return {}.iteritems()
+            return iter({}.items())
         return PathTreeItemIterator(self, subtree, depth)
 
     def dumpd(self, subtree='/'):
@@ -187,7 +187,7 @@
         d = result
 
         for k, v in self.iteritems(subtree):
-            elements = ['/'] + filter(bool, k.split('/'))
+            elements = ['/'] + list(filter(bool, k.split('/')))
             d = result
             for k in elements:
                 d = d.setdefault(k, {})