The Gaudi Framework  v32r2 (46d42edc)
GaudiKernel.PropertyProxy Namespace Reference

Classes

class  DataObjectHandleBasePropertyProxy
 
class  GaudiHandleArrayPropertyProxy
 
class  GaudiHandlePropertyProxy
 
class  GaudiHandlePropertyProxyBase
 
class  PropertyProxy
 

Functions

def derives_from (derived, base)
 
def _isCompatible (tp, value)
 
def PropertyProxyFactory (descr, doc, default)
 

Variables

list __all__
 
 log = logging.getLogger('PropertyProxy')
 

Function Documentation

◆ _isCompatible()

def GaudiKernel.PropertyProxy._isCompatible (   tp,
  value 
)
private

Definition at line 39 of file PropertyProxy.py.

39 def _isCompatible(tp, value):
40  errmsg = "received an instance of %s, but %s expected" % (type(value), tp)
41 
42  if derives_from(value, 'PropertyReference'):
43  # TODO: implement type checking for references
44  return value # references are valid
45  if (tp is str):
46  if (type(value) is str) or derives_from(value, 'Configurable'):
47  # we can set string properties only from strings or configurables
48  return value
49  elif isinstance(value, DataObjectHandleBase):
50  # Implicitly convert DataObjectHandleBase to str for backward
51  # compatiblity in cases like B.Input (str) = A.Output (handle)
52  return str(value)
53  else:
54  raise ValueError(errmsg)
55  elif (tp in [list, tuple, dict]):
56  if (type(value) is tp):
57  # We need to check that the types match for lists, tuples and
58  # dictionaries (bug #34769).
59  return value
60  else:
61  raise ValueError(errmsg)
62  elif derives_from(tp, 'Configurable'):
63  return value
64  else:
65  # all other types: accept if conversion allowed
66  try:
67  dummy = tp(value)
68  except (TypeError, ValueError):
69  raise ValueError(errmsg)
70 
71  return dummy # in case of e.g. classes with __int__, __iter__, etc. implemented
72 
73 
def derives_from(derived, base)
def _isCompatible(tp, value)

◆ derives_from()

def GaudiKernel.PropertyProxy.derives_from (   derived,
  base 
)
A string version of isinstance().
<derived> is either an object instance, or a type
<base>    is a string containing the name of the base class (or <derived> class)

Definition at line 24 of file PropertyProxy.py.

24 def derives_from(derived, base):
25  """A string version of isinstance().
26  <derived> is either an object instance, or a type
27  <base> is a string containing the name of the base class (or <derived> class)"""
28  if not isinstance(derived, type):
29  derived = type(derived)
30  if derived.__name__ == base:
31  return True
32  for b in derived.__bases__:
33  if derives_from(b, base):
34  return True
35 
36  return False
37 
38 
def derives_from(derived, base)

◆ PropertyProxyFactory()

def GaudiKernel.PropertyProxy.PropertyProxyFactory (   descr,
  doc,
  default 
)

Definition at line 421 of file PropertyProxy.py.

421 def PropertyProxyFactory(descr, doc, default):
422  # print "PropertyProxyFactory( %s, %r )" % (descr.__name__,default)
423 
424  if isinstance(default, GaudiHandleArray):
425  return GaudiHandleArrayPropertyProxy(descr, doc, default)
426 
427  if isinstance(default, GaudiHandle):
428  return GaudiHandlePropertyProxy(descr, doc, default)
429 
430  if isinstance(default, DataObjectHandleBase):
431  return DataObjectHandleBasePropertyProxy(descr, doc, default)
432 
433  return PropertyProxy(descr, doc, default)
def PropertyProxyFactory(descr, doc, default)

Variable Documentation

◆ __all__

list GaudiKernel.PropertyProxy.__all__
private
Initial value:
1 = [
2  'PropertyProxy', 'GaudiHandlePropertyProxy',
3  'GaudiHandleArrayPropertyProxy'
4 ]

Definition at line 6 of file PropertyProxy.py.

◆ log

GaudiKernel.PropertyProxy.log = logging.getLogger('PropertyProxy')

Definition at line 18 of file PropertyProxy.py.