コード例 #1
0
ファイル: mongo.py プロジェクト: adriank/ACR
	def parseAction(self,config):
		s=[]
		fields={}
		pars=config["params"]
		for elem in config["content"]:
			if type(elem) is tuple:
				if elem[0]=="where":
					pars["where"]=makeTree("".join(elem[2]))
				elif elem[0]=="field":
					fields[elem[1]["name"]]=bool(str2obj(elem[1]["show"]))
				else:
					pars[elem[0]]=(elem[1],elem[2])
			elif type(elem) is str:
				s.append(elem.strip())
		try:
			show=pars["show"].split(",")
			pars["fields"]=dict(map(lambda x: (x.strip(), 1), show))
		except KeyError:
			pass
		try:
			hide=pars["hide"].split(",")
			pars["fields"]=dict(map(lambda x: (x.strip(), 0), hide))
		except KeyError:
			pass
		try:
			coll=pars["coll"].split(".")
			if len(coll) is 1:
				coll=coll[0]
			pars["coll"]=coll
		except KeyError:
			raise Error("no coll parameter specified")
		try:
			sort=pars["sort"].split(",")
			directions=pars.get("direction",self.DIRECTION).split(",")
			directions=map(lambda x: pymongo.__dict__.get(x.upper()),directions)
			if len(directions)>=len(sort):
				pars["sort"]=zip(sort,directions)
			else:
				import itertools
				pars["sort"]=list(itertools.izip_longest(sort,directions,fillvalue=directions[-1]))
		except:
			pass
		# if fields:
		# 	pars["fields"]=show or hide
		return {
			"command":config["command"],
			"content":makeTree("".join(s)),
			"params":pars
		}
コード例 #2
0
ファイル: interpreter.py プロジェクト: Giotoc/ACR
	def parseAction(self, config):
		if config["command"] not in ["execute","exec"]:
			raise Exception("Bad command %s" % config["command"])
		return {
			"expression":makeTree("".join(config["content"]).strip())
			#"command":config["command"]
		}
コード例 #3
0
ファイル: user.py プロジェクト: Giotoc/ACR
	def parseAction(self,config):
		if config["command"] not in ["register","logout","login"]:
			raise Error("Bad command %s",config["command"])
		if config["command"] in ["register","login"] and not ("email" in config["params"].keys() or  "password" in config["params"].keys()):
			raise Error("Email or password is not set in %s action."%(config["command"]))
		ret=config["params"].copy()
		if ret.has_key("data"):
			ret["data"]=makeTree(ret["data"])
		ret["command"]=config["command"]
		return ret
コード例 #4
0
ファイル: view.py プロジェクト: adriank/ACR
	def parseConditions(self, a):
		ret=[]
		for i in a:
			attrs=i[1]
			if not attrs:
				attrs={"name":"unnamedCondition"}
			ret.append({
				"name":attrs.get("name","unnamedCondition"),
				"value":makeTree(attrs.get("value","".join(i[2]).strip()))
			})
		return ret
コード例 #5
0
ファイル: default.py プロジェクト: adriank/ACR
 def parseAction(self, config):
     cmd = config.get("command")
     if cmd in EXEC_CMD:
         return {"expr": makeTree("".join(config["content"]).strip()), "command": "exec"}
     s = []
     for elem in config["content"]:
         if type(elem) is tuple:
             html = config["view"].output.get("format", "") == "html5"
             s.append(tree2xml(elem, not html, html=html))
         elif type(elem) is str:
             s.append(elem)
     return {"string": prepareVars("".join(s).strip()), "output": config.get("output", None)}
コード例 #6
0
ファイル: view.py プロジェクト: Giotoc/ACR
def parsePosts(nodes):
    if not nodes:
        return (None, None)
    ret = {}
    postCount = 0
    for i in nodes:
        attrs = i[1]
        typ = typesMap.get(attrs.get("type", "default").lower())()
        if attrs.has_key("default"):
            typ.setDefault(makeTree(attrs["default"]))
        else:
            postCount += 1
        ret[attrs["name"]] = typ
    return (ret, postCount)
コード例 #7
0
ファイル: view.py プロジェクト: Giotoc/ACR
def parseInputs(nodes):
    if not nodes:
        return None
    ret = []
    postCount = 0
    for i in nodes:
        attrs = i[1]
        try:
            typ = typesMap.get(attrs.get("type", "default").lower())()
        except TypeError:
            raise Error("WrongInputTypeName", "Input type '%s' is not supported." % attrs.get("type", "default"))
        if attrs.has_key("default"):
            typ.setDefault(makeTree(attrs["default"]))
        ret.append({"name": attrs["name"], "type": typ})
    return ret
コード例 #8
0
ファイル: view.py プロジェクト: Giotoc/ACR
    def parseActions(self, actions):
        def findAction(actions, name):
            if not name:
                return None
            i = len(actions) - 1
            if i < 0:
                return None
            try:
                while not actions[i]["name"] == name:
                    i -= 1
                return i
            except:
                return None
            else:
                return len(actions)

        ret = self.parent and self.parent.actions[:] or []
        for action in actions:
            # if i[0]=="import":
            # 	self.importAction(i[0])
            # 	continue
            typ = action[0]
            attrs = action[1]
            ns, cmd = NS2Tuple(attrs.get(COMMAND, "default"))
            componentName = self.namespaces.get(ns, "default")
            o = {
                "type": typ,  # NODE, SET...
                # "command":cmd,#command name
                "name": attrs.get("name", "unnamedAction"),
                "component": componentName,
                "config": self.app.getComponent(componentName).parseAction(self.parseAction(action)),
            }
            if attrs.has_key("default"):
                o["default"] = makeTree(attrs["default"])
            if attrs.has_key("path"):
                o["path"] = makeTree(attrs["path"])
            if attrs.has_key("condition"):
                o["condition"] = makeTree(attrs["condition"])
                # positions the action in the list of actions
            before = attrs.get("before")
            after = attrs.get("after")
            # TODO this is nowhere near clearness. Need to write reference on inheritance regarding before/after and then implement it here
            posInParent = None
            if o["type"] == NODE:
                if not o["name"]:
                    raise Error("noNodeNameError", "Nodes must have names set.")
                pos = findAction(ret, o["name"])
                if pos > -1 and ret[pos]["type"] == NODE:
                    # print "WARNING: node %s overwritten"%(o["name"])
                    ret.pop(pos)
            if before:
                if before == "*":
                    ret.insert(0, o)
                else:
                    try:
                        ret.insert(findAction(ret, before), o)
                    except:
                        ret.append(o)
            elif after:
                if after == "*":
                    ret.append(o)
                else:
                    try:
                        ret.insert(findAction(ret, after) + 1, o)
                    except:
                        ret.append(o)
            else:
                ret.append(o)
        return ret