Ensure compatibility with Python 3 by running the Python source code files
through the Automated Python 2 to 3 code translation tool "2to3". For more
information about this tool, see:

https://docs.python.org/3/library/2to3.html
---
 python/pyosaf/saEnumConst.py             |  6 +++---
 python/pyosaf/utils/immoi/__init__.py    |  8 +++----
 python/pyosaf/utils/immoi/implementer.py | 36 ++++++++++++++++----------------
 python/pyosaf/utils/immom/__init__.py    |  6 +++---
 python/pyosaf/utils/immom/ccb.py         | 17 ++++++++-------
 python/pyosaf/utils/immom/iterator.py    |  8 +++----
 python/pyosaf/utils/immom/object.py      |  2 +-
 7 files changed, 42 insertions(+), 41 deletions(-)

diff --git a/python/pyosaf/saEnumConst.py b/python/pyosaf/saEnumConst.py
index 5c3338267..51f1efdeb 100644
--- a/python/pyosaf/saEnumConst.py
+++ b/python/pyosaf/saEnumConst.py
@@ -50,14 +50,14 @@ class Enumeration(object):
 
                i = 0
                for node in enumlist:
-                       if type(node) is tuple:
+                       if isinstance(node, tuple):
                                try:
                                        node, i = node
                                except ValueError:
                                        raise EnumException('%r:' % (node,))
-                       if type(node) is not str:
+                       if not isinstance(node, str):
                                raise EnumException('Enum name not a string: 
%r' % (node,))
-                       if type(i) is not int:
+                       if not isinstance(i, int):
                                raise EnumException('Enum value not integer: 
%r' % (node,))
                        if node in lookup:
                                raise EnumException('Enum name not unique: %r' 
% (node,))
diff --git a/python/pyosaf/utils/immoi/__init__.py 
b/python/pyosaf/utils/immoi/__init__.py
index c70f843e9..02ad89b90 100644
--- a/python/pyosaf/utils/immoi/__init__.py
+++ b/python/pyosaf/utils/immoi/__init__.py
@@ -126,7 +126,7 @@ def create_rt_object(class_name, parent_name, obj):
 
     c_attr_values = []
 
-    for name, (c_attr_type, values) in obj.attrs.iteritems():
+    for name, (c_attr_type, values) in obj.attrs.items():
 
         if values == None:
             values = []
@@ -175,10 +175,10 @@ def update_rt_object(dn, attributes):
     # Create and marshall attribute modifications
     attr_mods = []
 
-    for name, values in attributes.iteritems():
+    for name, values in attributes.items():
 
         if values is None:
-            print "WARNING: Received no values for %s in %s" % (name, dn)
+            print("WARNING: Received no values for %s in %s" % (name, dn))
             continue
 
         if not isinstance(values, list):
@@ -356,7 +356,7 @@ def create_non_existing_imm_object(class_name, parent_name, 
attributes):
 
     obj = ImmObject(class_name=class_name, dn=dn)
 
-    for name, values in attributes.iteritems():
+    for name, values in attributes.items():
         obj.__setattr__(name, values)
 
     obj.__setattr__('SaImmAttrClassName', class_name)
diff --git a/python/pyosaf/utils/immoi/implementer.py 
b/python/pyosaf/utils/immoi/implementer.py
index 865db9ba0..b183905a6 100755
--- a/python/pyosaf/utils/immoi/implementer.py
+++ b/python/pyosaf/utils/immoi/implementer.py
@@ -113,8 +113,8 @@ def _collect_full_transaction(ccb_id):
                 affected_instances = [i for i in all_objects_now if i.dn == dn]
 
                 if len(affected_instances) == 0:
-                    print ('ERROR: Failed to find object %s affected by modify 
'
-                           'operation' % dn)
+                    print(('ERROR: Failed to find object %s affected by modify 
'
+                           'operation' % dn))
                 else:
                     affected_instance = affected_instances[0]
 
@@ -198,8 +198,8 @@ def admin_operation(oi_handle, c_invocation_id, c_name, 
c_operation_id, c_params
     try:
         immoi.report_admin_operation_result(invocation_id, result)
     except SafException as err:
-        print "ERROR: Failed to report that %s::%s returned %s (%s)" % \
-            (name, invocation_id, result, err.msg)
+        print("ERROR: Failed to report that %s::%s returned %s (%s)" % \
+            (name, invocation_id, result, err.msg))
 
 def abort_ccb(oi_handle, ccb_id):
     ''' Callback for aborted CCBs.
@@ -275,7 +275,7 @@ def delete_added(oi_handle, ccb_id, c_name):
                                      eSaImmValueTypeT.SA_IMM_ATTR_SANAMET)
 
     # Create a new CCB in the cache if needed
-    if not ccb_id in CCBS.keys():
+    if not ccb_id in list(CCBS.keys()):
         CCBS[ccb_id] = []
 
     # Cache the operation
@@ -318,7 +318,7 @@ def modify_added(oi_handle, c_ccb_id, c_name, 
c_attr_modification):
             implementer_objection = result
 
     # Create a new CCB in the cache if needed
-    if not ccb_id in CCBS.keys():
+    if not ccb_id in list(CCBS.keys()):
         CCBS[ccb_id] = []
 
     # Store the modifications in the cache
@@ -366,7 +366,7 @@ def create_added(oi_handle, c_ccb_id, c_class_name, 
c_parent, c_attr_values):
             attributes[attribute.attrName] = None
 
     # Create a new CCB in the cache if needed
-    if not ccb_id in CCBS.keys():
+    if not ccb_id in list(CCBS.keys()):
         CCBS[ccb_id] = []
 
     # Cache the create operation
@@ -531,7 +531,7 @@ class Constraints(object):
                 a child
             '''
 
-            for child_classes in self.containments.values():
+            for child_classes in list(self.containments.values()):
                 if class_name in child_classes:
                     return True
 
@@ -785,8 +785,8 @@ class Implementer(object):
                         operation.execute(object_name, parameters)
                         return eSaAisErrorT.SA_AIS_OK
                     except SafException as err:
-                        print "ERROR: Admin operation %s caused exception %s" 
%\
-                            (operation_id, err)
+                        print("ERROR: Admin operation %s caused exception %s" 
%\
+                            (operation_id, err))
                         return err.value
 
         # Scan for AdminOperation-decorated functions in subclasses
@@ -802,8 +802,8 @@ class Implementer(object):
                     function(object_name, parameters)
                     return eSaAisErrorT.SA_AIS_OK
                 except SafException as err:
-                    print "ERROR: Admin operation %s caused exception %s" % \
-                        (operation_id, err)
+                    print("ERROR: Admin operation %s caused exception %s" % \
+                        (operation_id, err))
                     return err.value
 
         # Report that the operation is not supported
@@ -841,8 +841,8 @@ class Implementer(object):
 
                 continue
 
-            print "WARNING: %s is missing in IMM. Not becoming implementer." % 
\
-                class_name
+            print("WARNING: %s is missing in IMM. Not becoming implementer." % 
\
+                class_name)
 
     def get_selection_object(self):
         ''' Returns the selection object '''
@@ -855,8 +855,8 @@ class Implementer(object):
         try:
             immoi.update_rt_object(dn, attributes)
         except SafException as err:
-            print "ERROR: Failed to update runtime attributes of %s: %s" % \
-                (dn, err)
+            print("ERROR: Failed to update runtime attributes of %s: %s" % \
+                (dn, err))
 
     def create(self, obj):
         ''' Creates a runtime object '''
@@ -941,5 +941,5 @@ class Applier(Implementer):
                 immoi.implement_class(class_name)
 
             else:
-                print "WARNING: %s is missing in IMM. Not becoming applier." % 
\
-                    class_name
+                print("WARNING: %s is missing in IMM. Not becoming applier." % 
\
+                    class_name)
diff --git a/python/pyosaf/utils/immom/__init__.py 
b/python/pyosaf/utils/immom/__init__.py
index 578c3df39..9bce20dc2 100644
--- a/python/pyosaf/utils/immom/__init__.py
+++ b/python/pyosaf/utils/immom/__init__.py
@@ -109,7 +109,7 @@ def get(object_name, attr_name_list=None, class_name=None):
     attribs = {}
     attr_list = unmarshalNullArray(attributes)
     for attr in attr_list:
-        attr_range = range(attr.attrValuesNumber)
+        attr_range = list(range(attr.attrValuesNumber))
         attribs[attr.attrName] = [
             attr.attrValueType,
             [unmarshalSaImmValue(
@@ -170,8 +170,8 @@ def admin_op_invoke(dn, op_id, params=None):
         saAis.saAis.SA_TIME_ONE_SECOND * 10)
 
     if retval.value != eSaAisErrorT.SA_AIS_OK:
-        print "saImmOmAdminOperationInvoke_2: %s" % \
-            eSaAisErrorT.whatis(retval.value)
+        print("saImmOmAdminOperationInvoke_2: %s" % \
+            eSaAisErrorT.whatis(retval.value))
         raise SafException(retval.value)
 
     error = saImmOmAdminOwnerFinalize(owner_handle)
diff --git a/python/pyosaf/utils/immom/ccb.py b/python/pyosaf/utils/immom/ccb.py
index d37d4239e..1ed4a98a7 100644
--- a/python/pyosaf/utils/immom/ccb.py
+++ b/python/pyosaf/utils/immom/ccb.py
@@ -31,19 +31,20 @@ from pyosaf import saAis
 
 from pyosaf.utils import immom
 from pyosaf.utils import SafException
+from functools import reduce
 
 def _value_to_ctype_ptr(value_type, value):
     ''' convert a value to a ctypes value ptr '''
     if value_type is eSaImmValueTypeT.SA_IMM_ATTR_SAINT32T:
         ctypeptr = cast(pointer(SaInt32T(value)), c_void_p)
     elif value_type is eSaImmValueTypeT.SA_IMM_ATTR_SAUINT32T:
-        ctypeptr = cast(pointer(SaUint32T(long(value))), c_void_p)
+        ctypeptr = cast(pointer(SaUint32T(int(value))), c_void_p)
     elif value_type is eSaImmValueTypeT.SA_IMM_ATTR_SAINT64T:
-        ctypeptr = cast(pointer(SaInt64T(long(value))), c_void_p)
+        ctypeptr = cast(pointer(SaInt64T(int(value))), c_void_p)
     elif value_type is eSaImmValueTypeT.SA_IMM_ATTR_SAUINT64T:
-        ctypeptr = cast(pointer(SaUint64T(long(value))), c_void_p)
+        ctypeptr = cast(pointer(SaUint64T(int(value))), c_void_p)
     elif value_type is eSaImmValueTypeT.SA_IMM_ATTR_SATIMET:
-        ctypeptr = cast(pointer(SaTimeT(long(value))), c_void_p)
+        ctypeptr = cast(pointer(SaTimeT(int(value))), c_void_p)
     elif value_type is eSaImmValueTypeT.SA_IMM_ATTR_SANAMET:
         ctypeptr = cast(pointer(SaNameT(value)), c_void_p)
     elif value_type is eSaImmValueTypeT.SA_IMM_ATTR_SAFLOATT:
@@ -125,7 +126,7 @@ class Ccb(object):
             parent_name = None
 
         attr_values = []
-        for attr_name, type_values in obj.attrs.iteritems():
+        for attr_name, type_values in obj.attrs.items():
             values = type_values[1]
             attr = SaImmAttrValuesT_2()
             attr.attrName = attr_name
@@ -167,7 +168,7 @@ class Ccb(object):
         try:
             obj = immom.get(object_name)
         except SafException as err:
-            print "failed: %s" % err
+            print("failed: %s" % err)
             return
 
         object_names = [SaNameT(object_name)]
@@ -216,7 +217,7 @@ class Ccb(object):
         try:
             obj = immom.get(object_name)
         except SafException as err:
-            print "failed: %s" % err
+            print("failed: %s" % err)
             return
 
         object_names = [SaNameT(object_name)]
@@ -264,7 +265,7 @@ class Ccb(object):
         try:
             obj = immom.get(object_name)
         except SafException as err:
-            print "failed: %s" % err
+            print("failed: %s" % err)
             return
 
         object_names = [SaNameT(object_name)]
diff --git a/python/pyosaf/utils/immom/iterator.py 
b/python/pyosaf/utils/immom/iterator.py
index d023f96c7..0cda22290 100644
--- a/python/pyosaf/utils/immom/iterator.py
+++ b/python/pyosaf/utils/immom/iterator.py
@@ -81,7 +81,7 @@ class SearchIterator(collections.Iterator):
     def __iter__(self):
         return self
 
-    def next(self):
+    def __next__(self):
         name = SaNameT()
         attributes = pointer(pointer(SaImmAttrValuesT_2()))
         try:
@@ -96,7 +96,7 @@ class SearchIterator(collections.Iterator):
         attribs = {}
         attr_list = unmarshalNullArray(attributes)
         for attr in attr_list:
-            attr_range = range(attr.attrValuesNumber)
+            attr_range = list(range(attr.attrValuesNumber))
             attribs[attr.attrName] = [attr.attrValueType,
                 [unmarshalSaImmValue(
                     attr.attrValues[val],
@@ -122,8 +122,8 @@ def test():
     ''' test function '''
     it = InstanceIterator(sys.argv[1])
     for dn, attr in it:
-        print dn.split("=")[1]
-        print attr, "\n"
+        print(dn.split("=")[1])
+        print(attr, "\n")
 
 if __name__ == '__main__':
     test()
diff --git a/python/pyosaf/utils/immom/object.py 
b/python/pyosaf/utils/immom/object.py
index 971bd0e28..c2924d3c6 100644
--- a/python/pyosaf/utils/immom/object.py
+++ b/python/pyosaf/utils/immom/object.py
@@ -107,7 +107,7 @@ class ImmObject(object):
             value = '%s=%s' % (self.rdn_attribute, value)
 
         value_type = self.get_value_type(key)
-        if type(value) is list:
+        if isinstance(value, list):
             attr_value = (value_type, value)
         else:
             attr_value = (value_type, [value])
-- 
2.13.1


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Opensaf-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/opensaf-devel

Reply via email to