Commits

Anonymous committed cd3d325

HandleProxy: no auto-retrieve if in __str__; return locked copy if object is locked

  • Participants
  • Parent commits 58d2875

Comments (0)

Files changed (1)

File python/PropertyProxy.py

 # Author: Wim Lavrijsen (WLavrijsen@lbl.gov)
 # Author: Martin Woudstra (Martin.Woudstra@cern.ch)
 
-import os, sys, weakref
+import os, sys, weakref, copy
 try:
    from GaudiKernel.GaudiHandles import *
 except ImportError:
          # Get default
          try:
             default = obj.__class__.getDefaultProperty( self.descr.__name__ )
+            # if printing, just show the toolhandle. No need to auto-retrieve default configurable instance
+            if obj._isPrinting: return default
             default = self.convertDefaultToBeSet( obj, default )
-            islocked = obj._isLocked
-            obj._isLocked = False       # by-pass potential warnings
-            self.__set__( obj, default )
-            obj._isLocked = islocked
+            # special case if default is auto-retrieved configurable instance
+            if self.isConfig(default):
+               if obj._isLocked:
+                  # return a locked copy to produce error in case of setting any property
+                  # rather then changing the value of the default
+                  default = copy.deepcopy(default)
+                  default.lock()
+                  return default
+               else:
+                  # Set to default configurable instance to allow MyTool.MySubTool.MyProperty = MyValue
+                  self.__set__( obj, default )
+            elif isinstance(default,GaudiHandleArray):
+               if obj._isLocked:
+                  # return a locked copy to produce error in case of setting any property
+                  # rather then changing the value of the default
+                  default = copy.deepcopy(default)
+                  for c in default:
+                     if self.isConfig(c):
+                        c.lock()
+                  return default
+               else:
+                  # Set array to allow to add to default with syntax: MyTool.MyArray.append()
+                  self.__set__( obj, default )
+            else:
+               return default
          except AttributeError,e:
+            import traceback
+            traceback.print_exc()
             # change type of exception to avoid false error message
-            raise RuntimeError(*e.args)
+            raise RuntimeError("AttributeError(%s)" % e.args)
 
       return self.descr.__get__( obj, type )