| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

In This Package:

DybDbi::wrap::Wrap Class Reference

List of all members.

Public Member Functions

def wrap
def __init__
def get_attfn
def __call__
def define_listlike
def define_properties
def make__repr__
def define__repr__
def define_create
def define_update
def define_keys
def define_asdict
def define_csv

Public Attributes

 kls
 attfn

Static Public Attributes

tuple wrap = classmethod(wrap)
tuple getters = property( lambda self:[g[3:] for g in dir(self.kls) if g.startswith('Get') and len(g)>3 ] )
tuple setters = property( lambda self:[s[3:] for s in dir(self.kls) if s.startswith('Set') and len(s)>3 ] )
tuple getset = property( lambda self:list(set(self.getters).intersection(set(self.setters))))
tuple onlyget = property( lambda self:list(set(self.getters).difference(set(self.setters))))
tuple skips = property( lambda self:getattr( self.kls, '__skip__',() ))
tuple isrpt = property( lambda self:self.kls.__name__.startswith("DbiRpt") )
tuple isdtr = property( lambda self:self.kls.__name__.startswith("G") )
tuple attrs = property( lambda self:[g for g in self.getters if g not in self.skips])
tuple attfs = property(lambda self:map(lambda m:self.get_attfn(m),self.attrs))

Detailed Description

Control center for application of generic class manipulations based on the names of 
methods in contained kls. The manipulations do not require the classes to be imported into this scope.

Wrapping is applied to:

* all `genDbi` generated `DbiTableRow` subclasses and corresponding templated `DbiRpt` and `DbiWrt` (readers and writers)
* a selection of other Dbi classes that are useful interactively 


Definition at line 79 of file wrap.py.


Member Function Documentation

def DybDbi::wrap::Wrap::wrap (   cls,
  kls,
  attfn = {} 
)

Definition at line 81 of file wrap.py.

def DybDbi::wrap::Wrap::__init__ (   self,
  kls,
  attfn = {} 
)

Definition at line 86 of file wrap.py.

00091                              {}):

def DybDbi::wrap::Wrap::get_attfn (   self,
  m 
)

Returns function than when applied to an object returns (m,obj.Get<m>() ) where m is the attribute name  

Definition at line 98 of file wrap.py.

00100                                    :[g[3:] for g in dir(self.kls) if g.startswith('Get') and len(g)>3 ] )

def DybDbi::wrap::Wrap::__call__ (   self  ) 

Definition at line 105 of file wrap.py.

00105                                  :self.kls.__name__.startswith("DbiRpt") )
00106     isdtr = property( lambda self:self.kls.__name__.startswith("G") )
00107 
00108     def get_attfn( self, m ):
00109         """Returns function than when applied to an object returns (m,obj.Get<m>() ) where m is the attribute name  """
00110         return self.attfn.get(m, lambda obj:(m,getattr(obj,'Get%s'%m)()) )
00111     attrs = property( lambda self:[g for g in self.getters if g not in self.skips]) 
00112     attfs = property(lambda self:map(lambda m:self.get_attfn(m),self.attrs))      ## list of lambda funcs that return (name,val) pairs when applied
00113 
00114   
00115     def __call__(self):
00116         self.define_properties()

def DybDbi::wrap::Wrap::define_listlike (   self  ) 

Definition at line 117 of file wrap.py.

00119                      :
00120             self.define_create()
            self.define_asdict()

def DybDbi::wrap::Wrap::define_properties (   self  ) 

Define properties corresponding to Get* and Set* methods 
in the contained kls, providing attribute style access and setting ::

 g = i.x
 i.x = s
   
NB "getters" which take arguments GetWithArg(Int_t naughty) have to be skipped via::

 cls.__skip__ = ("WithArg",)

Definition at line 122 of file wrap.py.

00127                               :
00128         if self.isrpt:
00129             RPT(self.kls)           
00130     define_listlike.__doc__ = RPT.__doc__
00131 
00132     def define_properties( self ):
00133         """
00134         Define properties corresponding to Get* and Set* methods 
00135         in the contained kls, providing attribute style access and setting ::
00136 
00137                  g = i.x
00138                  i.x = s
00139    
        NB "getters" which take arguments GetWithArg(Int_t naughty) have to be skipped via::

def DybDbi::wrap::Wrap::make__repr__ (   self  ) 

Provide a default `__repr__` function that presents the attribute names and values as a dict 

Definition at line 140 of file wrap.py.

00145                                 :m not in self.skips,self.getset):
00146             setattr( self.kls, m.lower() , property( getattr(self.kls, 'Get%s' % m ), getattr( self.kls, 'Set%s' % m ) ) ) 
00147         for m in filter(lambda m:m not in self.skips,self.onlyget):

def DybDbi::wrap::Wrap::define__repr__ (   self  ) 

Definition at line 148 of file wrap.py.

00150                           :
00151         """
00152         Provide a default `__repr__` function that presents the attribute names and values as a dict 
00153         """
00154         def __repr__(iself):
00155             return "\n".join([ iself.__class__.__name__, "%s" % pprint.pformat( dict( [attf(iself) for attf in self.attfs ]) , indent=4) ])
00156         return __repr__

def DybDbi::wrap::Wrap::define_create (   self  ) 

Definition at line 157 of file wrap.py.

00158                               : 
00159         """

def DybDbi::wrap::Wrap::define_update (   self  ) 

Provide dict like updating for DbiTableRow subclasses, eg::

      from DybDbi import GCalibPmtSpec
      r = GCalibPmtSpec.Rpt()
      z = r[0]
      print z.asdict        
      print z.keys             
      z.update( Status=10 ) 

Definition at line 161 of file wrap.py.

00162                                        :
00163             self.kls.__repr__ = getattr(self.kls, 'AsString')
00164         else:
00165             self.kls.__repr__ = self.make__repr__()  
00166  
00167     def define_create( self):
00168         self.kls.Create = classmethod(_create)
00169     define_create.__doc__ = _create.__doc__
00170 
00171     def define_update( self):
00172         """
00173         Provide dict like updating for DbiTableRow subclasses, eg::
00174 
00175               from DybDbi import GCalibPmtSpec
00176               r = GCalibPmtSpec.Rpt()
00177               z = r[0]
00178               print z.asdict        
00179               print z.keys             
00180               z.update( Status=10 ) 
00181 
        """

def DybDbi::wrap::Wrap::define_keys (   self  ) 

Definition at line 182 of file wrap.py.

00183                                     :
00184             for k,v in kwargs.items():
00185                 Set = getattr(self.kls,'Set%s'%k, None)
00186                 if Set:
                    Set( iself, v )   

def DybDbi::wrap::Wrap::define_asdict (   self  ) 

Definition at line 187 of file wrap.py.

00188                     :
00189                     raise AttributeError("no such attribute %s" % k )    
00190         self.kls.update = _update
00191 
00192     def define_keys( self):
00193         def _keys(iself):
00194             return filter(lambda m:m not in self.skips,self.getset)
00195         setattr( self.kls, 'keys' , property( _keys ) )

def DybDbi::wrap::Wrap::define_csv (   self  ) 

Provide csv manipulations as classmethods on the Row classes

Definition at line 196 of file wrap.py.

00197                             :
00198         def _asdict(iself):
00199             d = {}
00200             for m in filter(lambda m:m not in self.skips,self.getset):
00201                 d[m] = getattr( self.kls, 'Get%s' % m )(iself)                 
00202             return d
00203         setattr( self.kls, 'asdict' , property( _asdict ) )
00204 
00205 
00206     def define_csv(self):
00207         """
        Provide csv manipulations as classmethods on the Row classes


Member Data Documentation

tuple DybDbi::wrap::Wrap::wrap = classmethod(wrap) [static]

Definition at line 84 of file wrap.py.

tuple DybDbi::wrap::Wrap::getters = property( lambda self:[g[3:] for g in dir(self.kls) if g.startswith('Get') and len(g)>3 ] ) [static]

Definition at line 90 of file wrap.py.

tuple DybDbi::wrap::Wrap::setters = property( lambda self:[s[3:] for s in dir(self.kls) if s.startswith('Set') and len(s)>3 ] ) [static]

Definition at line 91 of file wrap.py.

tuple DybDbi::wrap::Wrap::getset = property( lambda self:list(set(self.getters).intersection(set(self.setters)))) [static]

Definition at line 92 of file wrap.py.

tuple DybDbi::wrap::Wrap::onlyget = property( lambda self:list(set(self.getters).difference(set(self.setters)))) [static]

Definition at line 93 of file wrap.py.

tuple DybDbi::wrap::Wrap::skips = property( lambda self:getattr( self.kls, '__skip__',() )) [static]

Definition at line 94 of file wrap.py.

tuple DybDbi::wrap::Wrap::isrpt = property( lambda self:self.kls.__name__.startswith("DbiRpt") ) [static]

Definition at line 95 of file wrap.py.

tuple DybDbi::wrap::Wrap::isdtr = property( lambda self:self.kls.__name__.startswith("G") ) [static]

Definition at line 96 of file wrap.py.

tuple DybDbi::wrap::Wrap::attrs = property( lambda self:[g for g in self.getters if g not in self.skips]) [static]

Definition at line 101 of file wrap.py.

tuple DybDbi::wrap::Wrap::attfs = property(lambda self:map(lambda m:self.get_attfn(m),self.attrs)) [static]

Definition at line 102 of file wrap.py.

DybDbi::wrap::Wrap::kls

Definition at line 87 of file wrap.py.

DybDbi::wrap::Wrap::attfn

Definition at line 88 of file wrap.py.


The documentation for this class was generated from the following file:
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

Generated on Mon Apr 11 20:17:17 2011 for DybDbi by doxygen 1.4.7