The Gaudi Framework  v31r0 (aeb156f0)
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 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)
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)
def GaudiKernel.PropertyProxy.PropertyProxyFactory (   descr,
  doc,
  default 
)

Definition at line 419 of file PropertyProxy.py.

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

Variable Documentation

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

Definition at line 6 of file PropertyProxy.py.

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

Definition at line 18 of file PropertyProxy.py.