def test2Constructor(self): """Test constructor""" ks = CfgKeyStore("MyStore") self.failUnless(ks.name() == "MyStore") self.failUnless(len(ks.keys()) == len(ks._items) + 4) for label in ks.keys(): if label == 'transient': n = 4 # nbr of streamXyz else: n = 0 self.failUnless(len(ks[label]) == n) self.failUnless(len(ks[label].list()) == 0) self.failUnless(hasattr(ks, label)) ks.streamAOD.add({'Klass': 'key1'}) self.failUnless(ks.streamAOD() == ['Klass#key1']) del ks ks = CfgKeyStore("MyStore") self.failUnless(ks.streamAOD() == []) pass
def test2Constructor( self ): """Test constructor""" ks = CfgKeyStore( "MyStore" ) self.failUnless( ks.name() == "MyStore" ) self.failUnless( len(ks.keys()) == len(ks._items)+4 ) for label in ks.keys(): if label == 'transient': n = 4 # nbr of streamXyz else : n = 0 self.failUnless( len(ks[label]) == n ) self.failUnless( len(ks[label].list()) == 0 ) self.failUnless( hasattr(ks, label) ) ks.streamAOD.add( { 'Klass' : 'key1' } ) self.failUnless( ks.streamAOD() == [ 'Klass#key1' ] ) del ks ks = CfgKeyStore( "MyStore" ) self.failUnless( ks.streamAOD() == [] ) pass
class _ObjKeyStore(object): def __init__(self, name="KeyStore"): object.__init__(self) self._store = CfgKeyStore(name) for label in CfgKeyStore.__slots__['Labels']: labelName = "%s%s" % ( str(label)[0].upper(), # capitalize first letter str(label)[1:]) self.__dict__['isIn%s' % labelName] = self.__isInDict(label) self.__dict__['add%s' % labelName] = self.__addToDict(label) self.__dict__['addManyTypes%s' % labelName] = self.__addDictToDict(label) self.__dict__['write%s' % labelName] = self.__writePy(label) self.__dict__['read%s' % labelName] = self.__readPy(label) return # def __isInDict(self, label): # fct = lambda key: self.__all[label].has_key(key) # class __helper: # def __call__(self,key): # return fct(key) # return __helper() def __getitem__(self, k): return self._store[k] def __setitem__(self, k, v): return self._store.__setitem__(k, v) def keys(self): return self._store.keys() def clear(self, label=None): return self._store.clear(label) def __isInDict(self, label): def isIn(d, k, v): return d.has_item("%s#%s" % (k, v)) fct = lambda key, value: isIn(self._store[label], key, value) class __helper: def __call__(self, key, value): return fct(key, value) return __helper() def __addToDict(self, label): def fill(d, k, v): d.add({k: v}) return fct = lambda key, value: fill(self._store[label], key, value) class __helper: def __call__(self, key, value): return fct(key, value) return __helper() def __addDictToDict(self, label): # merge the dictionaries def fill(d, thedict): d.add(thedict) return fct = lambda thedict: fill(self._store[label], thedict) class __helper: def __call__(self, thedict): return fct(thedict) return __helper() def __writePy(self, label): fct = lambda fileName: self._store.write(fileName, label) class __helper: def __call__(self, fileName): return fct(fileName) return __helper() def __readPy(self, label): fct = lambda fileName: self._store.read(fileName, label) class __helper: def __call__(self, fileName): return fct(fileName) return __helper() def isInInput(self, type="", key="*"): flag = self.isInTransient(type, key) or self.isInInputFile(type, key) if not flag: from RecExConfig.RecConfFlags import recConfFlags if recConfFlags.AllowBackNavigation() and self.isInInputBackNav( type, key): flag = True return flag def Print(self): print self._store def __repr__(self): return "%r" % self._store def __str__(self): return "%s" % self._store pass # _ObjKeyStore