Exemple #1
0
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
Exemple #2
0
    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)