/search.css" rel="stylesheet" type="text/css"/> /search.js">
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

In This Package:

Public Member Functions | Public Attributes | Static Public Attributes | Properties
DybDbi::wrap::Wrap Class Reference

List of all members.

Public Member Functions

def wrap
def __init__
def get_attfn
def __call__
 list of lambda funcs that return (name,val) pairs when applied
def define_listlike
def define_properties
def make__repr__
def define__repr__
def define_create
def define_update
def define_keys
def define_vals
def define_asdict
def define_csv

Public Attributes

 kls
 attfn

Static Public Attributes

tuple wrap = classmethod(wrap)

Properties

 getters = property( lambda self:[g[3:] for g in dir(self.kls) if g.startswith('Get') and len(g)>3 ] )
 setters = property( lambda self:[s[3:] for s in dir(self.kls) if s.startswith('Set') and len(s)>3 ] )
 getset = property( lambda self:list(set(self.getters).intersection(set(self.setters))))
 onlyget = property( lambda self:list(set(self.getters).difference(set(self.setters))))
 skips = property( lambda self:getattr( self.kls, '__skip__',() ))
 isrpt = property( lambda self:self.kls.__name__.startswith("DbiRpt") )
 isdtr = property( lambda self:self.kls.__name__.startswith("G") )
 attrs = property( lambda self:[g for g in self.getters if g not in self.skips])
 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 148 of file wrap.py.


Constructor & Destructor Documentation

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

Definition at line 165 of file wrap.py.

00165                                   {} ):
00166         self.kls = kls
00167         self.attfn = attfn
00168     

Member Function Documentation

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

Definition at line 160 of file wrap.py.

00160                              {}):
00161         w = Wrap(kls,attfn)
00162         return w()
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 177 of file wrap.py.

00178                             :
00179         """Returns function than when applied to an object returns (m,obj.Get<m>() ) where m is the attribute name  """
        return self.attfn.get(m, lambda obj:(m,getattr(obj,'Get%s'%m)()) )
def DybDbi::wrap::Wrap::__call__ (   self)

list of lambda funcs that return (name,val) pairs when applied

Definition at line 184 of file wrap.py.

00185                       :
00186         self.define_properties()
00187         self.define__repr__()
00188         self.define_listlike()
00189         if self.isdtr:
00190             self.define_create()
00191             self.define_asdict()
00192             self.define_update()
00193             self.define_keys()
00194             self.define_vals()
00195             self.define_csv()
00196         return self 

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

Definition at line 197 of file wrap.py.

00198                               :
00199         if self.isrpt:
            RPT(self.kls)           
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 202 of file wrap.py.

00203                                  :
00204         """
00205         Define properties corresponding to Get* and Set* methods 
00206         in the contained kls, providing attribute style access and setting ::
00207 
00208                  g = i.x
00209                  i.x = s
00210    
00211         NB "getters" which take arguments GetWithArg(Int_t naughty) have to be skipped via::
00212 
00213                  cls.__skip__ = ("WithArg",)
00214 
00215         """
00216         for m in filter(lambda m:m not in self.skips,self.getset):
00217             setattr( self.kls, m.lower() , property( getattr(self.kls, 'Get%s' % m ), getattr( self.kls, 'Set%s' % m ) ) ) 
00218         for m in filter(lambda m:m not in self.skips,self.onlyget):
00219             setattr( self.kls, m.lower() , property( getattr(self.kls, 'Get%s' % m )  ) ) 
 
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 220 of file wrap.py.

00221                           :
00222         """
00223         Provide a default `__repr__` function that presents the attribute names and values as a dict 
00224         """
00225         def __repr__(iself):
00226             return "\n".join([ iself.__class__.__name__, "%s" % pprint.pformat( dict( [attf(iself) for attf in self.attfs ]) , indent=4) ])
00227         return __repr__

def DybDbi::wrap::Wrap::define__repr__ (   self)
Assign default repr ... override later if desired 

Definition at line 228 of file wrap.py.

00228                               : 
00229         """
00230         Assign default repr ... override later if desired 
00231         """
00232         if hasattr(self.kls,'AsString'):
00233             self.kls.__repr__ = getattr(self.kls, 'AsString')
00234         else:
00235             self.kls.__repr__ = self.make__repr__()  
00236  
def DybDbi::wrap::Wrap::define_create (   self)

Definition at line 237 of file wrap.py.

00238                             :
        self.kls.Create = classmethod(_create)
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 241 of file wrap.py.

00242                             :
00243         """
00244         Provide dict like updating for DbiTableRow subclasses, eg::
00245 
00246               from DybDbi import GCalibPmtSpec
00247               r = GCalibPmtSpec.Rpt()
00248               z = r[0]
00249               print z.asdict        
00250               print z.keys             
00251               z.update( Status=10 ) 
00252 
00253         """
00254         def _update(iself, **kwargs):
00255             for k,v in kwargs.items():
00256                 Set = getattr(self.kls,'Set%s'%k, None)
00257                 if Set:
00258                     Set( iself, v )   
00259                 else:
00260                     raise AttributeError("no such attribute %s" % k )    
00261         self.kls.update = _update

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

Definition at line 262 of file wrap.py.

00263                           :
00264         def _keys(iself):
00265             return filter(lambda m:m not in self.skips,self.getset)
00266         setattr( self.kls, 'keys' , property( _keys ) )

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

Definition at line 267 of file wrap.py.

00268                           :
00269         def _vals(iself):
00270             return map( lambda _:getattr( self.kls,'Get%s' % _)(iself), filter(lambda m:m not in self.skips,self.getset))
00271         setattr( self.kls, 'vals' , property( _vals ) )

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

Definition at line 272 of file wrap.py.

00273                             :
00274         def _asdict(iself):
00275             d = {}
00276             for m in filter(lambda m:m not in self.skips,self.getset):
00277                 d[m] = getattr( self.kls, 'Get%s' % m )(iself)                 
00278             return d
00279         setattr( self.kls, 'asdict' , property( _asdict ) )
00280 

def DybDbi::wrap::Wrap::define_csv (   self)
Provide csv manipulations as classmethods on the Row classes

Definition at line 281 of file wrap.py.

00282                         :
00283         """
00284         Provide csv manipulations as classmethods on the Row classes
00285         """
00286         import csv_tools 
00287         self.kls.csv_check = classmethod( csv_tools.csv_check )
00288         self.kls.csv_import = classmethod( csv_tools.csv_import )
00289         self.kls.csv_export = classmethod( csv_tools.csv_export )
00290         self.kls.csv_compare = classmethod( csv_tools.csv_compare )
00291 
00292 


Member Data Documentation

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

Definition at line 163 of file wrap.py.

Definition at line 165 of file wrap.py.

Definition at line 165 of file wrap.py.


Property Documentation

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 169 of file wrap.py.

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 170 of file wrap.py.

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

Definition at line 171 of file wrap.py.

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

Definition at line 172 of file wrap.py.

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

Definition at line 173 of file wrap.py.

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

Definition at line 174 of file wrap.py.

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

Definition at line 175 of file wrap.py.

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

Definition at line 180 of file wrap.py.

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

Definition at line 181 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 Fri May 16 2014 09:57:25 for DybDbi by doxygen 1.7.4