The Gaudi Framework  v30r4 (9b837755)
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

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

Definition at line 37 of file PropertyProxy.py.

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

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

Definition at line 405 of file PropertyProxy.py.

405 def PropertyProxyFactory(descr, doc, default):
406  # print "PropertyProxyFactory( %s, %r )" % (descr.__name__,default)
407 
408  if isinstance(default, GaudiHandleArray):
409  return GaudiHandleArrayPropertyProxy(descr, doc, default)
410 
411  if isinstance(default, GaudiHandle):
412  return GaudiHandlePropertyProxy(descr, doc, default)
413 
414  if isinstance(default, DataObjectHandleBase):
415  return DataObjectHandleBasePropertyProxy(descr, doc, default)
416 
417  return PropertyProxy(descr, doc, default)

Variable Documentation

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

Definition at line 6 of file PropertyProxy.py.

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

Definition at line 16 of file PropertyProxy.py.