From ae3b7ed877596ed6449e8ab782f6e2ae2a060ee8 Mon Sep 17 00:00:00 2001
From: Walter Lampl <Walter.Lampl@cern.ch>
Date: Fri, 1 Jun 2018 15:34:34 +0200
Subject: [PATCH] import and exception fixes for python3 compatiblity in
 AthenaCommon

Former-commit-id: 9952a8c72db58cdebb762785ef9f635f686a8932
---
 Control/AthenaCommon/python/Configurable.py     | 9 ++++-----
 Control/AthenaCommon/python/ConfigurableMeta.py | 6 +++---
 Control/AthenaCommon/python/Logging.py          | 2 +-
 Control/AthenaCommon/python/PropertyProxy.py    | 4 ++--
 4 files changed, 10 insertions(+), 11 deletions(-)

diff --git a/Control/AthenaCommon/python/Configurable.py b/Control/AthenaCommon/python/Configurable.py
index 67af258f09c..f0bd982aafe 100755
--- a/Control/AthenaCommon/python/Configurable.py
+++ b/Control/AthenaCommon/python/Configurable.py
@@ -5,7 +5,7 @@
 # Author: Martin Woudstra (Martin.Woudstra@cern.ch)
 
 import copy, types, os, weakref,sys
-import ConfigurableMeta
+from AthenaCommon import ConfigurableMeta
 
 # Note: load iProperty etc. from GaudiPython only as-needed
 import GaudiKernel.GaudiHandles as GaudiHandles
@@ -118,7 +118,7 @@ class Configurable( object ):
             for n,v in kwargs.items():
                try:
                   setattr( conf, n, v )
-               except AttributeError, originalAttributeError:
+               except AttributeError as originalAttributeError:
                 # rather annoying that we have to be somewhat silent here (the
                 # most common cases are 'name' and user kw args to be supplied
                 # to an overridden __init__)
@@ -191,7 +191,7 @@ class Configurable( object ):
 
     # this is an abstract class
       if klass == Configurable:
-         raise TypeError, "%s is an ABC and can not be instantiated" % str(Configurable)
+         raise TypeError( "%s is an ABC and can not be instantiated" % str(Configurable))
 
     # for using this Configurable as a (Gaudi) sequence
       self.__children = []
@@ -441,8 +441,7 @@ class Configurable( object ):
     # make sure base class init has been called
       if not hasattr(self,'_fInitOk') or not self._fInitOk:
        # could check more, but this is the only explanation
-         raise TypeError, \
-            "Configurable.__init__ not called in %s override" % self.__class__.__name__
+         raise TypeError("Configurable.__init__ not called in %s override" % self.__class__.__name__)
 
     # setup self: this collects all values on the python side
       self.__setupServices()
diff --git a/Control/AthenaCommon/python/ConfigurableMeta.py b/Control/AthenaCommon/python/ConfigurableMeta.py
index cc1039c2c98..e16f4172074 100755
--- a/Control/AthenaCommon/python/ConfigurableMeta.py
+++ b/Control/AthenaCommon/python/ConfigurableMeta.py
@@ -4,7 +4,7 @@
 # Author: Wim Lavrijsen (WLavrijsen@lbl.gov)
 
 import weakref
-import Logging, PropertyProxy
+from AthenaCommon import Logging, PropertyProxy
 
 
 ### data ---------------------------------------------------------------------
@@ -49,13 +49,13 @@ class ConfigurableMeta( type ):
             try:
                f = getattr( newclass, meth ).im_func
             except AttributeError:
-               raise NotImplementedError, "%s is missing in class %s" % (meth,str(newclass))
+               raise NotImplementedError("%s is missing in class %s" % (meth,str(newclass)))
 
           # in addition, verify the number of arguments w/o defaults
             nargcount = f.func_code.co_argcount
             ndefaults = f.func_defaults and len(f.func_defaults) or 0
             if not nargcount - ndefaults <= nArgs <= nargcount:
-               raise TypeError, "%s.%s requires exactly %d arguments" % (newclass,meth,nArgs)
+               raise TypeError("%s.%s requires exactly %d arguments" % (newclass,meth,nArgs))
 
     # cache references of instances by name for duplicate removal
       newclass.configurables = weakref.WeakValueDictionary()
diff --git a/Control/AthenaCommon/python/Logging.py b/Control/AthenaCommon/python/Logging.py
index 4476ce951e9..2db86d2fb55 100755
--- a/Control/AthenaCommon/python/Logging.py
+++ b/Control/AthenaCommon/python/Logging.py
@@ -5,7 +5,7 @@
 
 """Athena Python-side logging."""
 
-import Constants
+from AthenaCommon import Constants
 
 
 ### data _____________________________________________________________________
diff --git a/Control/AthenaCommon/python/PropertyProxy.py b/Control/AthenaCommon/python/PropertyProxy.py
index ea0d644aa55..6323ac1e4c7 100755
--- a/Control/AthenaCommon/python/PropertyProxy.py
+++ b/Control/AthenaCommon/python/PropertyProxy.py
@@ -233,7 +233,7 @@ class GaudiHandlePropertyProxyBase(PropertyProxy):
                   self.__set__( obj, default )
             else:
                return default
-         except AttributeError,e:
+         except AttributeError as e:
             import traceback
             traceback.print_exc()
             # change type of exception to avoid false error message
@@ -308,7 +308,7 @@ class GaudiHandlePropertyProxyBase(PropertyProxy):
             try:
                conf = self.getDefaultConfigurable(typeAndName, self.fullPropertyName(obj))
 #               print self.fullPropertyName(obj) + ": Setting default private configurable (from default handle): %r" % conf 
-            except AttributeError,e:
+            except AttributeError as e:
                # change type of exception to avoid false error message
                raise RuntimeError(*e.args)
             if conf is None:
-- 
GitLab