def __init__(self,wps,processes=None): """ Arguments: self wps - parent WPS instance """ Request.__init__(self,wps,processes) # # HEAD # self.templateProcessor.set("encoding", config.getConfigValue("wps","encoding")) self.templateProcessor.set("lang", self.wps.inputs["language"]) # # Processes # self.templateProcessor.set("Processes",self.processesDescription()) self.response = self.templateProcessor.__str__() return
def __init__(self, wps): """ Arguments: self wps - parent WPS instance """ Request.__init__(self, wps) # # global variables # serverName = "".join( map(lambda x: x.capitalize(), config.getConfigValue("wps", "title").split())) # self.templateProcessor.set("name",name) # self.templateProcessor.set("address",config.getConfigValue("wps","serveraddress")) serverURL = config.getConfigValue("wps", "serveraddress") # Generating a describeProcess for all processes wps2 = pywps.Pywps() wps2.inputs = { 'identifier': ['all'], 'version': '1.0.0', 'request': 'describeprocess', 'language': 'eng', 'service': 'wps' } requestDescribeProcess = DescribeProcess(wps2) describeProcessXML = requestDescribeProcess.response # Transforming the describeProcessXML into WSDL document describeProcess2WSDLXSL = open( pywps.XSLT.__path__[0] + "/describeProcess2WSDL.xsl", "r") transformerXSLT = etree.XSLT(etree.parse(describeProcess2WSDLXSL)) # Recall: serverName/serverURL parameters are XPath structures, # therefore we need '' in the string: 'http://foo/dummy' to be used by # XSLT WSDLTree = transformerXSLT(etree.parse( StringIO.StringIO(describeProcessXML)), serverName="'" + serverName + "'", serverURL="'" + serverURL + "'") # Concerting to String from tree WSDL = etree.tostring(WSDLTree) # Attention: It's not possible to set the tns namespace to the server's URL # with XSLT, since it is in the root element. The XML contains a REPLACEME string that # will be replaced only once (so the process is very efficient) WSDL = re.sub(r'REPLACEME', serverURL, WSDL, 1) self.response = WSDL return
def test29LanguageTranslation(self): """Test if title,abstract of process and I/O is translated""" self._setFromEnv() pywps.config.setConfigValue("wps","lang","en-CA,pt-PT") from pywps.Wps import Request wps=pywps.Pywps(pywps.METHOD_GET) wps.inputs={'request': 'getCapabilities', 'version': '1.0.0', 'service': 'wps'} request=Request(wps) returnerProcess=request.getProcess("returner") #process related returnerProcess.lang.strings["pt-PT"]["Return process"]="Processo de retorno" returnerProcess.lang.strings["pt-PT"]["This is demonstration process of PyWPS, returns the same file, it gets on input, as the output."]="Este eh um processo de demonstracao de PyWPS, retorna o mesmo ficheiro, o que ele recebe como entrada sai como saida" #inputs: data-->ComplexInput, text--: literal returnerProcess.lang.strings["pt-PT"]["Input vector data"]="Dados vectoriais de entrada" returnerProcess.lang.strings["pt-PT"]["Some width"]="Alguma largura" returnerProcess.inputs["data"].abstract="Complex data abstract dummy" returnerProcess.inputs["text"].abstract="Literal abstract dummy" returnerProcess.lang.strings["pt-PT"]["Complex data abstract dummy"]="Resumo teste de dados complexos" returnerProcess.lang.strings["pt-PT"]["Literal abstract dummy"]="Resumo teste de sequencia de caracteres" #outputs: output-->complexOutput, text-->literal data returnerProcess.lang.strings["pt-PT"]["Output vector data"]="Dados vectoriais de saida" returnerProcess.lang.strings["pt-PT"]["Output literal data"]="Sequencia de caracteres de saida" returnerProcess.outputs["output"].abstract="Complex output data abstract dummy" returnerProcess.outputs["text"].abstract="Literal output data abstract dummy" returnerProcess.lang.strings["pt-PT"]["Complex output data abstract dummy"]="Resumo teste de dados de saida complexos" returnerProcess.lang.strings["pt-PT"]["Literal output data abstract dummy"]="Resumo teste de sequencia de caracteres de saida" ptTranslations=[] for key in returnerProcess.lang.strings["pt-PT"].keys(): ptTranslations.append(returnerProcess.lang.strings["pt-PT"][key]) resultWPS=wps.performRequest(wps.parseRequest("service=wps&version=1.0.0&request=describeProcess&identifier=returner&language=pt-PT"),processes=[returnerProcess]) wpsTree=etree.fromstring(resultWPS) #print wps.performRequest(wps.parseRequest("service=wps&version=1.0.0&request=describeProcess&identifier=returner&language=pt-PT"),processes=[returnerProcess]) self.assertTrue(wpsTree.xpath("//ProcessDescription/ows:Title/text()",namespaces=wpsTree.nsmap)[0] in ptTranslations) self.assertTrue(wpsTree.xpath("//ProcessDescription/ows:Abstract/text()",namespaces=wpsTree.nsmap)[0] in ptTranslations) inputTitles=wpsTree.xpath("//DataInputs/Input/ows:Title/text()",namespaces=wpsTree.nsmap) inputAbstracts=wpsTree.xpath("//DataInputs/Input/ows:Abstract/text()",namespaces=wpsTree.nsmap) self.assertTrue((set(inputTitles) <= set(ptTranslations)) and len(inputTitles)!=0) self.assertTrue((set(inputAbstracts) <= set(ptTranslations)) and len(inputAbstracts)!=0) outputTitles=wpsTree.xpath("//ProcessOutputs/Output/ows:Title/text()",namespaces=wpsTree.nsmap) outputAbstracts=wpsTree.xpath("//DataInputs/Input/ows:Abstract/text()",namespaces=wpsTree.nsmap) self.assertTrue((set(outputTitles) <= set(ptTranslations)) and len(outputTitles)!=0)
def __init__(self,wps): """ Arguments: self wps - parent WPS instance """ Request.__init__(self,wps) # # global variables # serverName = "".join(map(lambda x: x.capitalize(),config.getConfigValue("wps","title").split())) #self.templateProcessor.set("name",name) #self.templateProcessor.set("address",config.getConfigValue("wps","serveraddress")) serverURL=config.getConfigValue("wps","serveraddress") #Generating a describeProcess for all processes wps2=pywps.Pywps() wps2.inputs={'identifier': ['all'], 'version': '1.0.0', 'request': 'describeprocess', 'language': 'eng', 'service': 'wps'} requestDescribeProcess=DescribeProcess(wps2) describeProcessXML=requestDescribeProcess.response #Transforming the describeProcessXML into WSDL document describeProcess2WSDLXSL=open(pywps.XSLT.__path__[0]+"/describeProcess2WSDL.xsl","r") transformerXSLT=etree.XSLT(etree.parse(describeProcess2WSDLXSL)) #Recall: serverName/serverURL parameters are XPath structures, therefore we need '' in the string: 'http://foo/dummy' to be used by XSLT WSDLTree=transformerXSLT(etree.parse(StringIO.StringIO(describeProcessXML)),serverName="'"+serverName+"'",serverURL="'"+serverURL+"'") #Concerting to String from tree WSDL=etree.tostring(WSDLTree) #Attention: It's not possible to set the tns namespace to the server's URL #with XSLT, since it is in the root element. The XML contains a REPLACEME string that #will be replaced only once (so the process is very efficient) WSDL=re.sub(r'REPLACEME',serverURL,WSDL,1) self.response=WSDL return
def __init__(self,wps): """ Arguments: self wps - parent WPS instance """ Request.__init__(self,wps) # # global variables # name = "".join(map(lambda x: x.capitalize(),config.getConfigValue("wps","title").split())) self.templateProcessor.set("name",name) self.templateProcessor.set("address",config.getConfigValue("wps","serveraddress")) # # Processes # #self.templateProcessor.set("Processes",self.processesDescription()) self.response = self.templateProcessor.__str__() return
def __init__(self, wps, processes=None): """ Arguments: self wps - parent WPS instance """ Request.__init__(self, wps, processes) # # HEAD # self.templateProcessor.set("encoding", config.getConfigValue("wps", "encoding")) self.templateProcessor.set("lang", self.wps.inputs["language"]) # # Processes # self.templateProcessor.set("Processes", self.processesDescription()) self.response = self.templateProcessor.__str__() return
def __init__(self,wps, processes=None): Request.__init__(self,wps,processes) self.wps = wps self.process = None # initialization self.statusTime = time.localtime() self.pid = os.getpid() self.status = None self.id = self.makeSessionId() self.outputFileName = os.path.join(config.getConfigValue("server","outputPath"),self.id+".xml") self.statusLocation = config.getConfigValue("server","outputUrl")+"/"+self.id+".xml" # rawDataOutput if len(self.wps.inputs["responseform"]["rawdataoutput"])>0: self.rawDataOutput = self.wps.inputs["responseform"]["rawdataoutput"].keys()[0] # is status required self.statusRequired = False if self.wps.inputs["responseform"]["responsedocument"].has_key("status"): if self.wps.inputs["responseform"]["responsedocument"]["status"]: self.statusRequired = True # is store response required ? self.storeRequired = False if self.wps.inputs["responseform"]["responsedocument"].has_key("storeexecuteresponse"): if self.wps.inputs["responseform"]["responsedocument"]["storeexecuteresponse"]: try: self.outputFile = open(self.outputFileName,"w") except Exception, e: traceback.print_exc(file=pywps.logFile) self.cleanEnv() raise pywps.NoApplicableCode(e.__str__()) self.storeRequired = True
def SOAPtoWPS(tree): # NOTE: # The etree output of ComplexData will not contain the OWS/WPS/XSI namespace since this name space is defined in the head of the WPS:Execute # The XSI is not necessary in the WPS:Execute, therefore it was deleted and its now inside the ComplexInput (if necessary) # An input shouldn't have elements in with OWS/WPS namespace, nevertheless a hack was implemented that allows for their presence. # The solution is a tiny hack the XSL file, the WPS/OWS namespace are different from the ComplexInput, something like this: http://REPLACEME/wps/1.0.0 # When etree is printed the REPLACEME is subtituted by www.opengis.net, creating the correct namespaces for the DOM parsing. # The replace is done using module re and set that it has to do only 2 # replaces in the beggining. Therefore the replace is independe of the # since of XML content global process from pywps import processes processID = tree.tag.split("_", 1)[-1] wps2 = pywps.Pywps() wps2.inputs = { 'request': 'getCapabilities', 'version': '1.0.0', 'service': 'wps' } from pywps.Wps import Request request = Request(wps2) try: process = [ process for process in request.processes if process.identifier in [processID] ][0] except IndexError: # #If the server url is incorrect the process request will not be found in the WPS process list raise pywps.NoApplicableCode( "The requested process is not part of the instance. Check pywps conf file and WSDL. WSDL has to point to the correct wrapper, please check location attribute in address element of WSDL document" ) XSLTDocIO = open(pywps.XSLT.__path__[0] + "/SOAP2WPS.xsl", "r") XSLTDoc = etree.parse(XSLTDocIO) transformer = etree.XSLT(XSLTDoc) WPSTree = transformer(tree) etree.cleanup_namespaces(WPSTree) XMLOut = etree.tostring(WPSTree) XMLOut = re.sub(r'REPLACEME', "www.opengis.net", XMLOut, 2) return XMLOut
def test29LanguageTranslation(self): """Test if title,abstract of process and I/O is translated""" self._setFromEnv() pywps.config.setConfigValue("wps", "lang", "en-CA,pt-PT") from pywps.Wps import Request wps = pywps.Pywps(pywps.METHOD_GET) wps.inputs = {'request': 'getCapabilities', 'version': '1.0.0', 'service': 'wps'} request = Request(wps) returnerProcess = request.getProcess("returner") # process related returnerProcess.lang.strings[ "pt-PT"]["Return process"] = "Processo de retorno" returnerProcess.lang.strings[ "pt-PT"]["This is demonstration process of PyWPS, returns the same file, it gets on input, as the output."] = "Este eh um processo de demonstracao de PyWPS, retorna o mesmo ficheiro, o que ele recebe como entrada sai como saida" # inputs: data-->ComplexInput, text--: literal returnerProcess.lang.strings[ "pt-PT"]["Input vector data"] = "Dados vectoriais de entrada" returnerProcess.lang.strings["pt-PT"]["Some width"] = "Alguma largura" returnerProcess.inputs["data"].abstract = "Complex data abstract dummy" returnerProcess.inputs["text"].abstract = "Literal abstract dummy" returnerProcess.lang.strings[ "pt-PT"]["Complex data abstract dummy"] = "Resumo teste de dados complexos" returnerProcess.lang.strings[ "pt-PT"]["Literal abstract dummy"] = "Resumo teste de sequencia de caracteres" # outputs: output-->complexOutput, text-->literal data returnerProcess.lang.strings[ "pt-PT"]["Output vector data"] = "Dados vectoriais de saida" returnerProcess.lang.strings[ "pt-PT"]["Output literal data"] = "Sequencia de caracteres de saida" returnerProcess.outputs[ "output"].abstract = "Complex output data abstract dummy" returnerProcess.outputs[ "text"].abstract = "Literal output data abstract dummy" returnerProcess.lang.strings[ "pt-PT"]["Complex output data abstract dummy"] = "Resumo teste de dados de saida complexos" returnerProcess.lang.strings[ "pt-PT"]["Literal output data abstract dummy"] = "Resumo teste de sequencia de caracteres de saida" ptTranslations = [] for key in returnerProcess.lang.strings["pt-PT"].keys(): ptTranslations.append(returnerProcess.lang.strings["pt-PT"][key]) resultWPS = wps.performRequest(wps.parseRequest( "service=wps&version=1.0.0&request=describeProcess&identifier=returner&language=pt-PT"), processes=[returnerProcess]) wpsTree = etree.fromstring(resultWPS) # print # wps.performRequest(wps.parseRequest("service=wps&version=1.0.0&request=describeProcess&identifier=returner&language=pt-PT"),processes=[returnerProcess]) self.assertTrue(wpsTree.xpath("//ProcessDescription/ows:Title/text()", namespaces=wpsTree.nsmap)[0] in ptTranslations) self.assertTrue(wpsTree.xpath("//ProcessDescription/ows:Abstract/text()", namespaces=wpsTree.nsmap)[0] in ptTranslations) inputTitles = wpsTree.xpath( "//DataInputs/Input/ows:Title/text()", namespaces=wpsTree.nsmap) inputAbstracts = wpsTree.xpath( "//DataInputs/Input/ows:Abstract/text()", namespaces=wpsTree.nsmap) self.assertTrue((set(inputTitles) <= set(ptTranslations)) and len(inputTitles) != 0) self.assertTrue((set(inputAbstracts) <= set( ptTranslations)) and len(inputAbstracts) != 0) outputTitles = wpsTree.xpath( "//ProcessOutputs/Output/ows:Title/text()", namespaces=wpsTree.nsmap) outputAbstracts = wpsTree.xpath( "//DataInputs/Input/ows:Abstract/text()", namespaces=wpsTree.nsmap) self.assertTrue((set(outputTitles) <= set( ptTranslations)) and len(outputTitles) != 0)
def __init__(self, wps, processes=None): """ """ Request.__init__(self, wps, processes) # # ServiceIdentification # self.templateProcessor.set("encoding", config.getConfigValue("wps", "encoding")) self.templateProcessor.set("lang", self.wps.inputs["language"]) self.templateProcessor.set("servertitle", config.getConfigValue("wps", "title")) self.templateProcessor.set("serverabstract", config.getConfigValue("wps", "abstract")) keywordList = [] for keyword in config.getConfigValue("wps", "keywords").split(','): keywordList.append({'keyword': keyword.strip()}) self.templateProcessor.set("Keywords", keywordList) self.templateProcessor.set("Versions", [{'version': config.getConfigValue("wps", "version")}]) self.templateProcessor.set("fees", config.getConfigValue("wps", "fees")) self.templateProcessor.set("constraints", config.getConfigValue("wps", "constraints")) self.templateProcessor.set("url", config.getConfigValue("wps", "serveraddress")) # # ServiceProvider # self.templateProcessor.set("providername", config.getConfigValue("provider", "providerName")) self.templateProcessor.set("individualname", config.getConfigValue("provider", "individualName")) self.templateProcessor.set("positionname", config.getConfigValue("provider", "positionName")) self.templateProcessor.set("providersite", config.getConfigValue("provider", "providerSite")) # phone if config.getConfigValue("provider", "phoneVoice") or \ config.getConfigValue("provider", "phoneFacsimile"): self.templateProcessor.set("phone", 1) if config.getConfigValue("provider", "phoneVoice"): self.templateProcessor.set("phonevoice", config.getConfigValue("provider", "phoneVoice")) if config.getConfigValue("provider", "phoneFacsimile"): self.templateProcessor.set("phonefacsimile", config.getConfigValue("provider", "phoneFacsimile")) else: self.templateProcessor.set("phone", 0) # address if config.getConfigValue("provider", "deliveryPoint") or \ config.getConfigValue("provider", "city") or \ config.getConfigValue("provider", "administrativeArea") or \ config.getConfigValue("provider", "postalCode") or \ config.getConfigValue("provider", "country") or \ config.getConfigValue("provider", "electronicMailAddress"): self.templateProcessor.set("address", 1) if config.getConfigValue("provider", "deliveryPoint"): self.templateProcessor.set("deliverypoint", config.getConfigValue("provider", "deliveryPoint")) if config.getConfigValue("provider", "city"): self.templateProcessor.set("city", config.getConfigValue("provider", "city")) if config.getConfigValue("provider", "administrativeArea"): self.templateProcessor.set("administrativearea", config.getConfigValue("provider", "administrativeArea")) if config.getConfigValue("provider", "postalCode"): self.templateProcessor.set("postalcode", config.getConfigValue("provider", "postalCode")) if config.getConfigValue("provider", "country"): self.templateProcessor.set("country", config.getConfigValue("provider", "country")) if config.getConfigValue("provider", "electronicMailAddress"): self.templateProcessor.set("electronicmailaddress", config.getConfigValue("provider", "electronicMailAddress")) else: self.templateProcessor.set("address", 0) # other ContactInfo if config.getConfigValue("provider", "role"): self.templateProcessor.set("role", config.getConfigValue("provider", "role")) if config.getConfigValue("provider", "hoursofservice"): self.templateProcessor.set("hoursofservice", config.getConfigValue("provider", "hoursofservice")) if config.getConfigValue("provider", "contactinstructions"): self.templateProcessor.set("contactinstructions", config.getConfigValue("provider", "contactinstructions")) # OperationsMetadata self.templateProcessor.set("Operations", [{"operation": "GetCapabilities", "url": config.getConfigValue("wps", "serveraddress")}, {"operation": "DescribeProcess", "url": config.getConfigValue("wps", "serveraddress")}, {"operation": "Execute", "url": config.getConfigValue("wps", "serveraddress")}]) # Processes processesData = [] for process in self.getProcesses("all"): processData = {} if type(process) == types.InstanceType: process.lang.setCode(self.wps.inputs["language"]) processData["processok"] = 1 processData["identifier"] = process.identifier processData["processversion"] = process.version processData["title"] = process.i18n(process.title) if process.abstract: processData["abstract"] = process.i18n(process.abstract) if process.metadata: processData["Metadata"] = self.formatMetadata(process) if process.profile: profiles = [] if type(process.profile) == types.ListType: for profile in process.profile: profiles.append({"profile": profile}) else: profiles.append({"profile": process.profile}) processData["Profiles"] = profiles if process.wsdl: processData["wsdl"] = process.wsdl else: processData["processok"] = 0 processData["process"] = repr(process) processesData.append(processData) self.templateProcessor.set("Processes", processesData) # Language self.templateProcessor.set("defaultlanguage", pywps.DEFAULT_LANG) languages = [] for lang in self.wps.languages: languages.append({"language": lang}) self.templateProcessor.set("Languages", languages) self.response = self.templateProcessor.__str__() return
def __init__(self,wps,processes=None): """ """ Request.__init__(self,wps,processes) # # ServiceIdentification # self.templateProcessor.set("encoding", config.getConfigValue("wps","encoding")) self.templateProcessor.set("lang", self.wps.inputs["language"]) self.templateProcessor.set("servertitle", config.getConfigValue("wps","title")) self.templateProcessor.set("serverabstract", config.getConfigValue("wps","abstract")) keywordList=[] for keyword in config.getConfigValue("wps","keywords").split(','): keywordList.append({'keyword':keyword.strip()}) self.templateProcessor.set("Keywords",keywordList) self.templateProcessor.set("Versions", [{'version': config.getConfigValue("wps","version")}]) self.templateProcessor.set("fees", config.getConfigValue("wps","fees")) self.templateProcessor.set("constraints", config.getConfigValue("wps","constraints")) self.templateProcessor.set("url", config.getConfigValue("wps","serveraddress")) # # ServiceProvider # self.templateProcessor.set("providername", config.getConfigValue("provider","providerName")) self.templateProcessor.set("individualname", config.getConfigValue("provider","individualName")) self.templateProcessor.set("positionname", config.getConfigValue("provider","positionName")) self.templateProcessor.set("providersite", config.getConfigValue("provider","providerSite")) # phone if config.getConfigValue("provider","phoneVoice") or \ config.getConfigValue("provider","phoneFacsimile"): self.templateProcessor.set("phone", 1) if config.getConfigValue("provider","phoneVoice"): self.templateProcessor.set("phonevoice", config.getConfigValue("provider","phoneVoice")) if config.getConfigValue("provider","phoneFacsimile"): self.templateProcessor.set("phonefacsimile", config.getConfigValue("provider","phoneFacsimile")) else: self.templateProcessor.set("phone", 0) # address if config.getConfigValue("provider","deliveryPoint") or \ config.getConfigValue("provider","city") or \ config.getConfigValue("provider","administrativeArea") or \ config.getConfigValue("provider","postalCode") or \ config.getConfigValue("provider","country") or \ config.getConfigValue("provider","electronicMailAddress"): self.templateProcessor.set("address", 1) if config.getConfigValue("provider","deliveryPoint"): self.templateProcessor.set("deliverypoint", config.getConfigValue("provider","deliveryPoint")) if config.getConfigValue("provider","city"): self.templateProcessor.set("city", config.getConfigValue("provider","city")) if config.getConfigValue("provider","administrativeArea"): self.templateProcessor.set("administrativearea", config.getConfigValue("provider","administrativeArea")) if config.getConfigValue("provider","postalCode"): self.templateProcessor.set("postalcode", config.getConfigValue("provider","postalCode")) if config.getConfigValue("provider","country"): self.templateProcessor.set("country", config.getConfigValue("provider","country")) if config.getConfigValue("provider","electronicMailAddress"): self.templateProcessor.set("electronicmailaddress", config.getConfigValue("provider","electronicMailAddress")) else: self.templateProcessor.set("address", 0) # other ContactInfo if config.getConfigValue("provider","role"): self.templateProcessor.set("role", config.getConfigValue("provider","role")) if config.getConfigValue("provider","hoursofservice"): self.templateProcessor.set("hoursofservice", config.getConfigValue("provider","hoursofservice")) if config.getConfigValue("provider","contactinstructions"): self.templateProcessor.set("contactinstructions", config.getConfigValue("provider","contactinstructions")) # OperationsMetadata self.templateProcessor.set("Operations", [{"operation":"GetCapabilities", "url":config.getConfigValue("wps","serveraddress")}, {"operation":"DescribeProcess", "url":config.getConfigValue("wps","serveraddress")}, {"operation":"Execute", "url":config.getConfigValue("wps","serveraddress")}]) # Processes processesData = [] for process in self.getProcesses("all"): processData = {} if type(process) == types.InstanceType: process.lang.setCode(self.wps.inputs["language"]) processData["processok"] = 1 processData["identifier"] = process.identifier processData["processversion"] = process.version processData["title"] = process.i18n(process.title) if process.abstract: processData["abstract"] = process.i18n(process.abstract) if process.metadata: processData["Metadata"] = self.formatMetadata(process) if process.profile: profiles=[] if type(process.profile) == types.ListType: for profile in process.profile: profiles.append({"profile":profile}) else: profiles.append({"profile":process.profile}) processData["Profiles"] = profiles if process.wsdl: processData["wsdl"] = process.wsdl else: processData["processok"] = 0 processData["process"] = repr(process) processesData.append(processData) self.templateProcessor.set("Processes",processesData) # Language self.templateProcessor.set("defaultlanguage", pywps.DEFAULT_LANG) languages = [] for lang in self.wps.languages: languages.append({"language":lang}) self.templateProcessor.set("Languages",languages) self.response = self.templateProcessor.__str__() return