Example #1
0
	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)
Example #2
0
	def test_dicttree_set(self):
		d = {}
		dicttree.set(d, ['a'], 'y')
		dicttree.set(d, ['b', 'c', 'd'], 'x')
		dicttree.set(d, ['b', 'e'], 'z')
		self.assertTrue( d == {'a': 'y', 'b': {'c': {'d': 'x'}, 'e': 'z'}})
		d = {}
		dicttree.set(d, ['a'], {2 : 3}), dicttree.set(d, ['a', 2], 4), dicttree.set(d, ['b'], ['foo', 'bar'])
		self.assertTrue( d == {'a': {2: 4}, 'b': ['foo', 'bar']})
		d = {}
		dicttree.set(d, ['a', 'b', 'c'], 'x'), dicttree.set(d, ['a'], 'y')
		self.assertTrue( d == {'a' : 'y'})
		#TODO this is test for get and set. move to tests
		d={"a":1}
		dicttree.set(d,["a","b","c"],1)
		self.assertTrue(d == {'a': {'b': {'c': 1}}})
		return True