def generate(self, acenv,config): D=acenv.doDebug if D: acenv.debug("START Mongo:%s with %s",config["command"].split(":").pop(), config) db=acenv.app.storage params=config["params"] collName=params.get("coll",self.DEFAULT_COLL) if type(collName) in (str,unicode): coll=acenv.app.storage[params.get("coll",self.DEFAULT_COLL)] coll=dicttree.get(acenv.app.storage,params.get("coll",self.DEFAULT_COLL)) return self.__getattribute__(config["command"].split(":").pop())(acenv,config)
def getView(self,URLpath,errorOnNotFound=False): #TODO rewrite it: # 1. View.isUpToDate - should posibly update object internally, # when view file is deleted, should raise error # 2. here should be try to FileNotFound error which should refresh cache # 3. then check for mistakes (eg. now some views are not cached) (o, i)=dicttree.get(self.views, URLpath, False) if i==len(URLpath) and type(o) is dict and o.has_key("default"): o=o["default"] #if D: acenv.debug("Executing '%s'/default"%("/".join(URLpath))) #TODO handle an event when file was deleted; probably raises exception if type(o) is View: if self.deploymentMode or o.isUpToDate(): #if D: acenv.info("View '%s' taken from cache"%("/".join(URLpath[:i]))) return (o, URLpath[i:]) #elif D: acenv.info("View %s is not cached","/".join(URLpath)) i=0 viewPath=pjoin(self.viewsPath, *URLpath[:i]) #if D: acenv.debug("Searching from '%s'"%(viewPath)) viewName,inputs=URLpath[:i],URLpath[i:] temp=viewPath # if inputs[1]!="api" # raise Exception(inputs) while len(inputs): temp=pjoin(temp, inputs[0]) if not pisdir(temp): break viewPath=temp viewName.append(inputs.pop(0)) if inputs and pexists(pjoin(viewPath,inputs[0])+".xml"): viewName.append(inputs.pop(0)) elif not inputs and pexists(viewPath+".xml"): pass elif not inputs and pexists(pjoin(viewPath,"default.xml")): viewName.append("default") else: if errorOnNotFound: raise ViewNotFound(viewName) viewName=["notFound"] v=View(viewName, self) dicttree.set(self.views, viewName, v) return (v, inputs)
def test_dicttree_get(self): d = {'x': {'y': 'z', 'a' : {'b': {'c' : {'d': 'e'}}}}, 'w': 't', 'r' : {'o' : 'l', 'g' : {'q': 's'}} } self.assertTrue( dicttree.get(d, ['x', 'y'], False) == ('z', 2)) self.assertTrue( dicttree.get(d, 'x.a.b.c.d'.split('.'), False) == ('e', 5)) self.assertTrue( dicttree.get(d, 'x.a.b.c.d'.split('.')) == 'e') self.assertTrue( dicttree.get(d, ['w'], False) == ('t', 1)) self.assertTrue( dicttree.get(d, 'r.o'.split('.'), False) == ('l', 2)) self.assertTrue( dicttree.get(d, 'r.g.q'.split('.'), False) == ('s', 3)) self.assertTrue( not dicttree.get(d, 'x.y.z'.split('.'))) self.assertTrue( not dicttree.get(d, 'x.b'.split('.'))) self.assertTrue( dicttree.get(d, ['r', 'g']) == {'q': 's'}) self.assertTrue( dicttree.get(d, ['x', 'a', 'b'], False) == ( {'c' : {'d': 'e'}}, 3)) self.assertTrue( dicttree.get(d, ['a'], False) == (d, 0))