def checkLanguage(self, node): """ Check optional language parameter. """ if node.hasAttribute("language"): value = Lang.getCode(node.getAttribute("language").lower()) if value not in self.wps.languages: raise pywps.InvalidParameterValue("language") else: self.inputs["language"] = value else: self.inputs["language"] = pywps.DEFAULT_LANG
def checkService(self, node): """Check mandatory service name parameter. :param node: :class:`xml.dom.Node`, where to search """ # service name is mandatory for all requests (OWS_1-1-0 p.14 tab.3 + # p.46 tab.26); service must be "WPS" (WPS_1-0-0 p.17 tab.13 + p.32 tab.39) if node.hasAttribute("service"): value=node.getAttribute("service").upper() if value != "WPS": raise pywps.InvalidParameterValue("service") else: self.inputs["service"] = "wps" else: raise pywps.MissingParameterValue("service")
def parseDataInputs(self, inputsNode): """ Parse input data from given node """ parsedDataInputs = [] for inputNode in inputsNode.getElementsByTagNameNS( self.nameSpace, "Input"): # input Identifier try: identifier = inputNode.getElementsByTagNameNS( self.owsNameSpace, "Identifier")[0].firstChild.nodeValue except (IndexError, AttributeError): raise pywps.NoApplicableCode("Identifier for input not set") parsedDataInputs.append({ "identifier": identifier, "value": None, "attributes": {} }) # Title and Abstract are only mandatory and not necessary: # skipping, not supported yet # formchoice try: dataTypeNode = inputNode.getElementsByTagNameNS( self.nameSpace, "Reference")[0] attributes = self.parseReferenceDataInput(dataTypeNode) attributes["identifier"] = identifier parsedDataInputs[-1] = attributes except IndexError, e: dataTypeNode = inputNode.getElementsByTagNameNS( self.nameSpace, "Data")[0] attributes = self.parseDataInput(dataTypeNode) attributes["identifier"] = identifier parsedDataInputs[-1] = attributes try: parsedDataInputs[-1] except KeyError: raise pywps.InvalidParameterValue(identifier)
def parse(self,unparsedInputs, initInputs=None): """ Parse given inputs """ if initInputs: self.inputs = initInputs self.unparsedInputs = unparsedInputs # # Mandatory options # # service & Request are already controlled # version self.checkVersion() # identifier if "identifier" in self.unparsedInputs: self.inputs["identifier"] = [self.unparsedInputs["identifier"]] else: raise pywps.MissingParameterValue("identifier") # # Optional options # # Language self.checkLanguage() # dataInputs try: self.inputs["datainputs"] = self.parseDataInputs( self.unparsedInputs["datainputs"]) except KeyError: self.inputs["datainputs"] = None # ResponseForm self.inputs["responseform"] = {} # ResponseDocument try: self.inputs["responseform"]["responsedocument"] = \ {"outputs": self.parseDataInputs(self.unparsedInputs["responsedocument"])} except KeyError: self.inputs["responseform"]["responsedocument"] = {} # RawDataOutput try: preparsed = self.parseDataInputs(self.unparsedInputs["rawdataoutput"]) self.inputs["responseform"]["rawdataoutput"] = self._parseRawDataOutput(preparsed[0]) except KeyError: self.inputs["responseform"]["rawdataoutput"] = {} # storeExecuteResponse if "storeexecuteresponse" in self.unparsedInputs: if self.unparsedInputs["storeexecuteresponse"].lower() ==\ "true": self.inputs["responseform"]["responsedocument"]["storeexecuteresponse"] = True else: self.inputs["responseform"]["responsedocument"]["storeexecuteresponse"] = False # lineage if "lineage" in self.unparsedInputs: if self.unparsedInputs["lineage"].lower() == "true": self.inputs["responseform"]["responsedocument"]["lineage"]=\ True else: self.inputs["responseform"]["responsedocument"]["lineage"]=\ False # status if "status" in self.unparsedInputs: if self.unparsedInputs["status"].lower() == "true": self.inputs["responseform"]["responsedocument"]["status"]=\ True else: self.inputs["responseform"]["responsedocument"]["status"]=\ False # OGC 05-007r7 page 36, Table 49 # Either responseDocument or rawDataOutput should be specified, not both if len(self.inputs["responseform"]["rawdataoutput"])>0 and \ len(self.inputs["responseform"]["responsedocument"])>0: raise pywps.InvalidParameterValue("responseDocument", "Either responseDocument or rawDataOutput should be specified, but not both") return self.inputs
def parse(self,document, initInputs=None): """ Parse given XML document """ if initInputs: self.inputs = initInputs self.document = document # input DOM firstChild = self.isSoapFirstChild(self.document) # no comments or # white spaces self.nameSpace = firstChild.namespaceURI # document namespace self.nameSpace = pywps.WPS_NAMESPACE self.owsNameSpace = pywps.OWS_NAMESPACE self.xlinkNameSpace = pywps.XLINK_NAMESPACE language = None identifiers = [] identifierNode = None dataInputs = [] # # Mandatory options # # service & Request are already controlled # version self.checkVersion(firstChild) # identifier try: self.inputs["identifier"] = [ firstChild.getElementsByTagNameNS(self.owsNameSpace,"Identifier")[0].firstChild.nodeValue ] except IndexError: raise pywps.MissingParameterValue("Identifier") # # Optional options # # language self.checkLanguage(firstChild) # dataInputs try: inputsNode = firstChild.getElementsByTagNameNS( self.nameSpace,"DataInputs")[0] self.inputs["datainputs"] = self.parseDataInputs(inputsNode) except IndexError: self.inputs["datainputs"] = None # responseForm try: responseFormNode = \ firstChild.getElementsByTagNameNS(self.nameSpace, "ResponseForm")[0] self.inputs["responseform"] = self.parseResponseForm( responseFormNode) except IndexError: self.inputs["responseform"] = {} # OGC 05-007r7 page 36, Table 49 # Either responseDocument or rawDataOutput should be specified, not both if self.inputs.has_key('responseform') and \ (self.inputs["responseform"].has_key("rawdataoutput") and \ self.inputs["responseform"].has_key("responsedocument")) and \ self.inputs["responseform"]["responsedocument"] and \ self.inputs["responseform"]["rawdataoutput"]: raise pywps.InvalidParameterValue("responseDocument", "Either responseDocument or rawDataOutput should be specified, but not both") if not self.inputs["responseform"].has_key("rawdataoutput"): self.inputs["responseform"]["rawdataoutput"] = {} if not self.inputs["responseform"].has_key("responsedocument"): self.inputs["responseform"]["responsedocument"] = {} return self.inputs