Пример #1
0
    def test_format_class(self):
        """Test pywps.formats.Format class
        """
        frmt = Format('mimetype',
                      schema='halloworld',
                      encoding='asdf',
                      validate=self.validate)

        self.assertEqual(frmt.mime_type, 'mimetype')
        self.assertEqual(frmt.schema, 'halloworld')
        self.assertEqual(frmt.encoding, 'asdf')
        self.assertTrue(frmt.validate('the input', 1))

        describeel = frmt.describe_xml()
        self.assertEqual('Format', describeel.tag)
        mimetype = xpath_ns(describeel, '/Format/MimeType')
        encoding = xpath_ns(describeel, '/Format/Encoding')
        schema = xpath_ns(describeel, '/Format/Schema')

        self.assertTrue(mimetype)
        self.assertTrue(encoding)
        self.assertTrue(schema)

        self.assertEqual(mimetype[0].text, 'mimetype')
        self.assertEqual(encoding[0].text, 'asdf')
        self.assertEqual(schema[0].text, 'halloworld')

        frmt2 = get_format('GML')

        self.assertFalse(frmt.same_as(frmt2))
Пример #2
0
def get_output(doc):
    output = {}
    for output_el in xpath_ns(doc, "/wps:ExecuteResponse" "/wps:ProcessOutputs/wps:Output"):
        [identifier_el] = xpath_ns(output_el, "./ows:Identifier")
        [value_el] = xpath_ns(output_el, "./wps:Data/wps:LiteralData")
        output[identifier_el.text] = value_el.text
    return output
Пример #3
0
        def parse_post_execute(doc):
            """Parse POST Execute request
            """

            version = doc.attrib.get('version')
            wpsrequest.check_and_set_version(version)

            wpsrequest.operation = 'execute'
            wpsrequest.identifier = xpath_ns(doc, './ows:Identifier')[0].text
            wpsrequest.lineage = 'false'
            wpsrequest.store_execute = 'false'
            wpsrequest.status = 'false'
            wpsrequest.inputs = get_inputs_from_xml(doc)
            wpsrequest.outputs = get_output_from_xml(doc)
            wpsrequest.raw = False
            if xpath_ns(doc,
                        '/wps:Execute/wps:ResponseForm/wps:RawDataOutput'):
                wpsrequest.raw = True
                # executeResponse XML will not be stored
                wpsrequest.store_execute = 'false'

            # check if response document tag has been set then retrieve
            response_document = xpath_ns(
                doc, './wps:ResponseForm/wps:ResponseDocument')
            if len(response_document) > 0:
                wpsrequest.lineage = response_document[0].attrib.get(
                    'lineage', 'false')
                wpsrequest.store_execute = response_document[0].attrib.get(
                    'storeExecuteResponse', 'false')
                wpsrequest.status = response_document[0].attrib.get(
                    'status', 'false')
Пример #4
0
    def test_bbox(self):
        if not PY2:
            self.skipTest('OWSlib not python 3 compatible')
        client = client_for(Service(processes=[create_bbox_process()]))
        request_doc = WPS.Execute(
            OWS.Identifier('my_bbox_process'),
            WPS.DataInputs(
                WPS.Input(
                    OWS.Identifier('mybbox'),
                    WPS.Data(WPS.BoundingBoxData(
                        OWS.LowerCorner('15 50'),
                        OWS.UpperCorner('16 51'),
                        ))
                )
            ),
            version='1.0.0'
        )

        resp = client.post_xml(doc=request_doc)

        assert_response_success(resp)

        [output] = xpath_ns(resp.xml, '/wps:ExecuteResponse'
                                   '/wps:ProcessOutputs/Output')
        self.assertEqual('outbbox', xpath_ns(output,
            './ows:Identifier')[0].text)
        self.assertEqual('15 50', xpath_ns(output,
            './ows:BoundingBox/ows:LowerCorner')[0].text)
Пример #5
0
    def test_format_class(self):
        """Test pywps.formats.Format class
        """
        frmt = Format('mimetype', schema='halloworld', encoding='asdf',
                      validate=self.validate)

        self.assertEqual(frmt.mime_type, 'mimetype')
        self.assertEqual(frmt.schema, 'halloworld')
        self.assertEqual(frmt.encoding, 'asdf')
        self.assertTrue(frmt.validate('the input', 1))

        describeel = frmt.describe_xml()
        self.assertEqual('Format', describeel.tag)
        mimetype = xpath_ns(describeel, '/Format/MimeType')
        encoding = xpath_ns(describeel, '/Format/Encoding')
        schema = xpath_ns(describeel, '/Format/Schema')

        self.assertTrue(mimetype)
        self.assertTrue(encoding)
        self.assertTrue(schema)

        self.assertEqual(mimetype[0].text, 'mimetype')
        self.assertEqual(encoding[0].text, 'asdf')
        self.assertEqual(schema[0].text, 'halloworld')

        frmt2 = get_format('GML')

        self.assertFalse(frmt.same_as(frmt2))
Пример #6
0
    def test_bbox(self):
        if not PY2:
            self.skipTest('OWSlib not python 3 compatible')
        client = client_for(Service(processes=[create_bbox_process()]))
        request_doc = WPS.Execute(OWS.Identifier('my_bbox_process'),
                                  WPS.DataInputs(
                                      WPS.Input(
                                          OWS.Identifier('mybbox'),
                                          WPS.Data(
                                              WPS.BoundingBoxData(
                                                  OWS.LowerCorner('15 50'),
                                                  OWS.UpperCorner('16 51'),
                                              )))),
                                  version='1.0.0')
        resp = client.post_xml(doc=request_doc)
        assert_response_success(resp)

        [output
         ] = xpath_ns(resp.xml, '/wps:ExecuteResponse'
                      '/wps:ProcessOutputs/Output')
        self.assertEqual('outbbox',
                         xpath_ns(output, './ows:Identifier')[0].text)
        self.assertEqual(
            '15 50',
            xpath_ns(output, './ows:BoundingBox/ows:LowerCorner')[0].text)
Пример #7
0
        def parse_post_execute(doc):
            """Parse POST Execute request
            """

            version = doc.attrib.get('version')
            wpsrequest.check_and_set_version(version)

            wpsrequest.operation = 'execute'
            wpsrequest.identifier = xpath_ns(doc, './ows:Identifier')[0].text
            wpsrequest.lineage = 'false'
            wpsrequest.store_execute = 'false'
            wpsrequest.status = 'false'
            wpsrequest.inputs = get_inputs_from_xml(doc)
            wpsrequest.outputs = get_output_from_xml(doc)
            wpsrequest.raw = False
            if xpath_ns(doc, '/wps:Execute/wps:ResponseForm/wps:RawDataOutput'):
                wpsrequest.raw = True
                # executeResponse XML will not be stored
                wpsrequest.store_execute = 'false'

            # check if response document tag has been set then retrieve
            response_document = xpath_ns(doc, './wps:ResponseForm/wps:ResponseDocument')
            if len(response_document) > 0:
                wpsrequest.lineage = response_document[0].attrib.get('lineage', 'false')
                wpsrequest.store_execute = response_document[0].attrib.get('storeExecuteResponse', 'false')
                wpsrequest.status = response_document[0].attrib.get('status', 'false')
Пример #8
0
    def test_literal_allowed_values_input(self):
        """Test all around allowed_values
        """
        literal = LiteralInput(
            'foo',
            'Foo',
            data_type='integer',
            uoms=['metre'],
            allowed_values=(1, 2, (5, 10), (12, 4, 24),
                            AllowedValue(allowed_type=ALLOWEDVALUETYPE.RANGE,
                                         minval=30,
                                         maxval=33,
                                         range_closure='closed-open')))
        doc = literal.describe_xml()

        allowed_values = xpath_ns(doc, './LiteralData/ows:AllowedValues')
        self.assertEqual(len(allowed_values), 1)

        allowed_value = allowed_values[0]

        values = xpath_ns(allowed_value, './ows:Value')
        ranges = xpath_ns(allowed_value, './ows:Range')

        self.assertEqual(len(values), 2)
        self.assertEqual(len(ranges), 3)
Пример #9
0
    def test_literal_allowed_values_input(self):
        """Test all around allowed_values
        """
        literal = LiteralInput(
            'foo',
            'Foo',
            data_type='integer',
            uoms=['metre'],
            allowed_values=(
                1, 2, (5, 10), (12, 4, 24),
                AllowedValue(
                    allowed_type=ALLOWEDVALUETYPE.RANGE,
                    minval=30,
                    maxval=33,
                    range_closure='closed-open')
            )
        )
        doc = literal.describe_xml()

        allowed_values = xpath_ns(doc, './LiteralData/ows:AllowedValues')
        self.assertEqual(len(allowed_values), 1)

        allowed_value = allowed_values[0]

        values = xpath_ns(allowed_value, './ows:Value')
        ranges = xpath_ns(allowed_value, './ows:Range')

        self.assertEqual(len(values), 2)
        self.assertEqual(len(ranges), 3)
Пример #10
0
 def test_bbox_output(self):
     bbox = BoundingBoxOutput('bbox', 'BBox foo', crss=["EPSG:4326"])
     doc = bbox.describe_xml()
     [outpt] = xpath_ns(doc, '/Output')
     [default_crs] = xpath_ns(doc, './BoundingBoxOutput/Default/CRS')
     supported = xpath_ns(doc, './BoundingBoxOutput/Supported/CRS')
     assert default_crs.text == 'EPSG:4326'
     assert len(supported) == 1
Пример #11
0
def get_output(doc):
    output = {}
    for output_el in xpath_ns(doc, '/wps:ExecuteResponse'
                                   '/wps:ProcessOutputs/wps:Output'):
        [identifier_el] = xpath_ns(output_el, './ows:Identifier')
        [value_el] = xpath_ns(output_el, './wps:Data/wps:LiteralData')
        output[identifier_el.text] = value_el.text
    return output
Пример #12
0
 def test_complex_input_identifier(self):
     complex_in = ComplexInput('foo', 'Complex foo', keywords=['kw1', 'kw2'], supported_formats=[Format('bar/baz')])
     doc = complex_in.describe_xml()
     self.assertEqual(doc.tag, E.Input().tag)
     [identifier_el] = xpath_ns(doc, './ows:Identifier')
     self.assertEqual(identifier_el.text, 'foo')
     kws = xpath_ns(doc, './ows:Keywords/ows:Keyword')
     self.assertEqual(len(kws), 2)
Пример #13
0
 def test_bbox_output(self):
     bbox = BoundingBoxOutput("bbox", "BBox foo", crss=["EPSG:4326"])
     doc = bbox.describe_xml()
     [outpt] = xpath_ns(doc, "/Output")
     [default_crs] = xpath_ns(doc, "./BoundingBoxOutput/Default/CRS")
     supported = xpath_ns(doc, "./BoundingBoxOutput/Supported/CRS")
     assert default_crs.text == "EPSG:4326"
     assert len(supported) == 1
Пример #14
0
 def test_complex_input_identifier(self):
     complex_in = ComplexInput('foo', 'Complex foo', keywords=['kw1', 'kw2'], supported_formats=[Format('bar/baz')])
     doc = complex_in.describe_xml()
     self.assertEqual(doc.tag, E.Input().tag)
     [identifier_el] = xpath_ns(doc, './ows:Identifier')
     self.assertEqual(identifier_el.text, 'foo')
     kws = xpath_ns(doc, './ows:Keywords/ows:Keyword')
     self.assertEqual(len(kws), 2)
Пример #15
0
 def test_bbox_output(self):
     bbox = BoundingBoxOutput('bbox', 'BBox foo',
             crss=["EPSG:4326"])
     doc = bbox.describe_xml()
     [outpt] = xpath_ns(doc, '/Output')
     [default_crs] = xpath_ns(doc, './BoundingBoxOutput/Default/CRS')
     supported = xpath_ns(doc, './BoundingBoxOutput/Supported/CRS')
     assert default_crs.text == 'EPSG:4326'
     assert len(supported) == 1
Пример #16
0
 def test_literal_integer_input(self):
     literal = LiteralInput('foo', 'Literal foo', data_type='integer')
     doc = literal.describe_xml()
     assert doc.tag == E.Input().tag
     [identifier_el] = xpath_ns(doc, './ows:Identifier')
     assert identifier_el.text == 'foo'
     [type_el] = xpath_ns(doc, './LiteralData/ows:DataType')
     assert type_el.text == 'integer'
     assert type_el.attrib['reference'] == XMLSCHEMA_2 + 'integer'
Пример #17
0
 def test_bbox_input(self):
     bbox = BoundingBoxInput("bbox", "BBox foo", crss=["EPSG:4326", "EPSG:3035"])
     doc = bbox.describe_xml()
     [inpt] = xpath_ns(doc, "/Input")
     [default_crs] = xpath_ns(doc, "./BoundingBoxData/Default/CRS")
     supported = xpath_ns(doc, "./BoundingBoxData/Supported/CRS")
     assert inpt.attrib["minOccurs"] == "1"
     assert default_crs.text == "EPSG:4326"
     assert len(supported) == 2
Пример #18
0
    def test_complex_output(self):
        complexo = ComplexOutput("complex", "Complex foo", [Format("GML")])
        doc = complexo.describe_xml()
        [outpt] = xpath_ns(doc, "/Output")
        [default] = xpath_ns(doc, "/Output/ComplexOutput/Default/Format/MimeType")
        supported = xpath_ns(doc, "/Output/ComplexOutput/Supported/Format/MimeType")

        assert default.text == "application/gml+xml"
        assert len(supported) == 1
Пример #19
0
 def test_bbox_input(self):
     bbox = BoundingBoxInput('bbox', 'BBox foo',
                             crss=["EPSG:4326", "EPSG:3035"])
     doc = bbox.describe_xml()
     [inpt] = xpath_ns(doc, '/Input')
     [default_crs] = xpath_ns(doc, './BoundingBoxData/Default/CRS')
     supported = xpath_ns(doc, './BoundingBoxData/Supported/CRS')
     self.assertEqual(inpt.attrib['minOccurs'], '1')
     self.assertEqual(default_crs.text, 'EPSG:4326')
     self.assertEqual(len(supported), 2)
Пример #20
0
    def test_complex_output(self):
        complexo = ComplexOutput('complex', 'Complex foo', [Format('GML')])
        doc = complexo.describe_xml()
        [outpt] = xpath_ns(doc, '/Output')
        [default] = xpath_ns(doc, '/Output/ComplexOutput/Default/Format/MimeType')
        supported = xpath_ns(doc,
                             '/Output/ComplexOutput/Supported/Format/MimeType')

        assert default.text == 'application/gml+xml'
        assert len(supported) == 1
Пример #21
0
def get_describe_result(resp):
    assert resp.status_code == 200
    assert resp.headers['Content-Type'] == 'text/xml'
    result = []
    for desc_el in resp.xpath('/wps:ProcessDescriptions/ProcessDescription'):
        [identifier_el] = xpath_ns(desc_el, './ows:Identifier')
        inputs = []
        metadata = []
        for metadata_el in xpath_ns(desc_el, './ows:Metadata'):
            metadata.append(metadata_el.attrib['{http://www.w3.org/1999/xlink}title'])
        for input_el in xpath_ns(desc_el, './DataInputs/Input'):
            [input_identifier_el] = xpath_ns(input_el, './ows:Identifier')
            input_identifier = input_identifier_el.text
            literal_data_el_list = xpath_ns(input_el, './LiteralData')
            complex_data_el_list = xpath_ns(input_el, './ComplexData')
            if literal_data_el_list:
                [literal_data_el] = literal_data_el_list
                [data_type_el] = xpath_ns(literal_data_el, './ows:DataType')
                data_type = get_data_type(data_type_el)
                inputs.append((input_identifier, 'literal', data_type))
            elif complex_data_el_list:
                [complex_data_el] = complex_data_el_list
                formats = []
                for format_el in xpath_ns(complex_data_el,
                                          './Supported/Format'):
                    [mimetype_el] = xpath_ns(format_el, './ows:MimeType')
                    formats.append({'mime_type': mimetype_el.text})
                inputs.append((input_identifier, 'complex', formats))
            else:
                raise RuntimeError("Can't parse input description")
        result.append(ProcessDescription(identifier_el.text, inputs, metadata))
    return result
Пример #22
0
def get_describe_result(resp):
    assert resp.status_code == 200
    assert resp.headers['Content-Type'] == 'text/xml'
    result = []
    for desc_el in resp.xpath('/wps:ProcessDescriptions/ProcessDescription'):
        [identifier_el] = xpath_ns(desc_el, './ows:Identifier')
        inputs = []
        metadata = []
        for metadata_el in xpath_ns(desc_el, './ows:Metadata'):
            metadata.append(
                metadata_el.attrib['{http://www.w3.org/1999/xlink}title'])
        for input_el in xpath_ns(desc_el, './DataInputs/Input'):
            [input_identifier_el] = xpath_ns(input_el, './ows:Identifier')
            input_identifier = input_identifier_el.text
            literal_data_el_list = xpath_ns(input_el, './LiteralData')
            complex_data_el_list = xpath_ns(input_el, './ComplexData')
            if literal_data_el_list:
                [literal_data_el] = literal_data_el_list
                [data_type_el] = xpath_ns(literal_data_el, './ows:DataType')
                data_type = get_data_type(data_type_el)
                inputs.append((input_identifier, 'literal', data_type))
            elif complex_data_el_list:
                [complex_data_el] = complex_data_el_list
                formats = []
                for format_el in xpath_ns(complex_data_el,
                                          './Supported/Format'):
                    [mimetype_el] = xpath_ns(format_el, './ows:MimeType')
                    formats.append({'mime_type': mimetype_el.text})
                inputs.append((input_identifier, 'complex', formats))
            else:
                raise RuntimeError("Can't parse input description")
        result.append(ProcessDescription(identifier_el.text, inputs, metadata))
    return result
Пример #23
0
    def test_literal_output(self):
        literal = LiteralOutput('literal',
                                'Literal foo',
                                abstract='Description',
                                keywords=['kw1', 'kw2'],
                                uoms=['metre'])
        doc = literal.describe_xml()
        [output] = xpath_ns(doc, '/Output')
        [identifier] = xpath_ns(doc, '/Output/ows:Identifier')
        [abstract] = xpath_ns(doc, '/Output/ows:Abstract')
        [keywords] = xpath_ns(doc, '/Output/ows:Keywords')
        kws = xpath_ns(keywords, './ows:Keyword')
        [data_type] = xpath_ns(doc, '/Output/LiteralOutput/ows:DataType')
        [uoms] = xpath_ns(doc, '/Output/LiteralOutput/UOMs')
        [default_uom] = xpath_ns(uoms, './Default/ows:UOM')
        supported_uoms = xpath_ns(uoms, './Supported/ows:UOM')

        assert output is not None
        assert identifier.text == 'literal'
        assert abstract.text == 'Description'
        assert keywords is not None
        assert len(kws) == 2
        assert data_type.attrib['{%s}reference' %
                                NAMESPACES['ows']] == OGCTYPE['string']
        assert uoms is not None
        assert default_uom.text == 'metre'
        assert default_uom.attrib['{%s}reference' %
                                  NAMESPACES['ows']] == OGCUNIT['metre']
        assert len(supported_uoms) == 1
Пример #24
0
 def test_complex_input_default_and_supported(self):
     complex_in = ComplexInput("foo", "Complex foo", supported_formats=[Format("a/b"), Format("c/d")])
     doc = complex_in.describe_xml()
     [default_format] = xpath_ns(doc, "./ComplexData/Default/Format")
     [default_mime_el] = xpath_ns(default_format, "./MimeType")
     assert default_mime_el.text == "a/b"
     supported_mime_types = []
     for supported_el in xpath_ns(doc, "./ComplexData/Supported/Format"):
         [mime_el] = xpath_ns(supported_el, "./MimeType")
         supported_mime_types.append(mime_el.text)
     assert supported_mime_types == ["a/b", "c/d"]
Пример #25
0
 def test_complex_input_default_and_supported(self):
     complex = ComplexInput('foo', 'Complex foo', allowed_formats=[Format('a/b'), Format('c/d')])
     doc = complex.describe_xml()
     [default_format] = xpath_ns(doc, './ComplexData/Default/Format')
     [default_mime_el] = xpath_ns(default_format, './MimeType')
     assert default_mime_el.text == 'a/b'
     supported_mime_types = []
     for supported_el in xpath_ns(doc, './ComplexData/Supported/Format'):
         [mime_el] = xpath_ns(supported_el, './MimeType')
         supported_mime_types.append(mime_el.text)
     assert supported_mime_types == ['a/b', 'c/d']
Пример #26
0
 def test_literal_integer_input(self):
     literal = LiteralInput("foo", "Literal foo", data_type="positiveInteger", uoms=["metre"])
     doc = literal.describe_xml()
     assert doc.tag == E.Input().tag
     [identifier_el] = xpath_ns(doc, "./ows:Identifier")
     assert identifier_el.text == "foo"
     [type_el] = xpath_ns(doc, "./LiteralData/ows:DataType")
     assert type_el.text == "positiveInteger"
     assert type_el.attrib["{%s}reference" % NAMESPACES["ows"]] == OGCTYPE["positiveInteger"]
     anyvalue = xpath_ns(doc, "./LiteralData/ows:AnyValue")
     assert len(anyvalue) == 1
Пример #27
0
 def test_literal_integer_input(self):
     literal = LiteralInput('foo', 'Literal foo', data_type='positiveInteger', uoms=['metre'])
     doc = literal.describe_xml()
     self.assertEqual(doc.tag, E.Input().tag)
     [identifier_el] = xpath_ns(doc, './ows:Identifier')
     self.assertEqual(identifier_el.text, 'foo')
     [type_el] = xpath_ns(doc, './LiteralData/ows:DataType')
     self.assertEqual(type_el.text, 'positiveInteger')
     self.assertEqual(type_el.attrib['{%s}reference' % NAMESPACES['ows']],
         OGCTYPE['positiveInteger'])
     anyvalue = xpath_ns(doc, './LiteralData/ows:AnyValue')
     self.assertEqual(len(anyvalue), 1)
Пример #28
0
 def test_bbox_output(self):
     bbox = BoundingBoxOutput('bbox', 'BBox foo', keywords=['kw1', 'kw2'],
                              crss=["EPSG:4326"])
     doc = bbox.describe_xml()
     [outpt] = xpath_ns(doc, '/Output')
     [default_crs] = xpath_ns(doc, './BoundingBoxOutput/Default/CRS')
     supported = xpath_ns(doc, './BoundingBoxOutput/Supported/CRS')
     assert default_crs.text == 'EPSG:4326'
     assert len(supported) == 1
     [keywords] = xpath_ns(doc, '/Output/ows:Keywords')
     kws = xpath_ns(keywords, './ows:Keyword')
     assert keywords is not None
     assert len(kws) == 2
Пример #29
0
 def test_bbox_output(self):
     bbox = BoundingBoxOutput('bbox', 'BBox foo', keywords=['kw1', 'kw2'],
                              crss=["EPSG:4326"])
     doc = bbox.describe_xml()
     [outpt] = xpath_ns(doc, '/Output')
     [default_crs] = xpath_ns(doc, './BoundingBoxOutput/Default/CRS')
     supported = xpath_ns(doc, './BoundingBoxOutput/Supported/CRS')
     assert default_crs.text == 'EPSG:4326'
     assert len(supported) == 1
     [keywords] = xpath_ns(doc, '/Output/ows:Keywords')
     kws = xpath_ns(keywords, './ows:Keyword')
     assert keywords is not None
     assert len(kws) == 2
Пример #30
0
    def test_complex_output(self):
        complexo = ComplexOutput('complex', 'Complex foo', [Format('GML')], keywords=['kw1', 'kw2'])
        doc = complexo.describe_xml()
        [outpt] = xpath_ns(doc, '/Output')
        [default] = xpath_ns(doc, '/Output/ComplexOutput/Default/Format/MimeType')
        supported = xpath_ns(doc,
                             '/Output/ComplexOutput/Supported/Format/MimeType')

        assert default.text == 'application/gml+xml'
        assert len(supported) == 1
        [keywords] = xpath_ns(doc, '/Output/ows:Keywords')
        kws = xpath_ns(keywords, './ows:Keyword')
        assert keywords is not None
        assert len(kws) == 2
Пример #31
0
def get_describe_result(resp):
    assert resp.status_code == 200
    assert resp.headers["Content-Type"] == "text/xml"
    result = []
    for desc_el in resp.xpath("/wps:ProcessDescriptions/ProcessDescription"):
        [identifier_el] = xpath_ns(desc_el, "./ows:Identifier")
        inputs = []
        for input_el in xpath_ns(desc_el, "./DataInputs/Input"):
            [input_identifier_el] = xpath_ns(input_el, "./ows:Identifier")
            input_identifier = input_identifier_el.text
            literal_data_el_list = xpath_ns(input_el, "./LiteralData")
            complex_data_el_list = xpath_ns(input_el, "./ComplexData")
            if literal_data_el_list:
                [literal_data_el] = literal_data_el_list
                [data_type_el] = xpath_ns(literal_data_el, "./ows:DataType")
                data_type = get_data_type(data_type_el)
                inputs.append((input_identifier, "literal", data_type))
            elif complex_data_el_list:
                [complex_data_el] = complex_data_el_list
                formats = []
                for format_el in xpath_ns(complex_data_el, "./Supported/Format"):
                    [mimetype_el] = xpath_ns(format_el, "./ows:MimeType")
                    formats.append({"mime_type": mimetype_el.text})
                inputs.append((input_identifier, "complex", formats))
            else:
                raise RuntimeError("Can't parse input description")
        result.append(ProcessDescription(identifier_el.text, inputs))
    return result
Пример #32
0
def get_output(doc):
    from pywps.app.basic import xpath_ns
    output = {}
    for output_el in xpath_ns(
            doc, '/wps:ExecuteResponse'
            '/wps:ProcessOutputs/wps:Output'):
        [identifier_el] = xpath_ns(output_el, './ows:Identifier')
        try:
            [value_el] = xpath_ns(output_el, './wps:Data/wps:LiteralData')
        except:
            [value] = xpath_ns(output_el, './wps:Reference')
            value_el = value.get('{http://www.w3.org/1999/xlink}href')
        output[identifier_el.text] = value_el
    return output
Пример #33
0
def get_output(xml):
    """Return a dictionary of output values from the WPS response xml."""
    output = {}
    for output_el in xpath_ns(xml, '/wps:ExecuteResponse'
                                   '/wps:ProcessOutputs/wps:Output'):
        [identifier_el] = xpath_ns(output_el, './ows:Identifier')
        [value_el] = xpath_ns(output_el, './wps:Reference')
        if value_el is not None:
            output[identifier_el.text] = value_el.attrib["{http://www.w3.org/1999/xlink}href"]
        else:
            [value_el] = xpath_ns(output_el, './wps:Data/wps:LiteralData')
            output[identifier_el.text] = value_el.text

    return output
Пример #34
0
 def test_complex_input_default_and_supported(self):
     complex_in = ComplexInput(
         'foo',
         'Complex foo',
         supported_formats=[Format('a/b'), Format('c/d')])
     doc = complex_in.describe_xml()
     [default_format] = xpath_ns(doc, './ComplexData/Default/Format')
     [default_mime_el] = xpath_ns(default_format, './MimeType')
     assert default_mime_el.text == 'a/b'
     supported_mime_types = []
     for supported_el in xpath_ns(doc, './ComplexData/Supported/Format'):
         [mime_el] = xpath_ns(supported_el, './MimeType')
         supported_mime_types.append(mime_el.text)
     assert supported_mime_types == ['a/b', 'c/d']
Пример #35
0
    def test_complex_output(self):
        complexo = ComplexOutput('complex', 'Complex foo', [Format('GML')], keywords=['kw1', 'kw2'])
        doc = complexo.describe_xml()
        [outpt] = xpath_ns(doc, '/Output')
        [default] = xpath_ns(doc, '/Output/ComplexOutput/Default/Format/MimeType')
        supported = xpath_ns(doc,
                             '/Output/ComplexOutput/Supported/Format/MimeType')

        assert default.text == 'application/gml+xml'
        assert len(supported) == 1
        [keywords] = xpath_ns(doc, '/Output/ows:Keywords')
        kws = xpath_ns(keywords, './ows:Keyword')
        assert keywords is not None
        assert len(kws) == 2
Пример #36
0
 def test_literal_integer_input(self):
     literal = LiteralInput('foo',
                            'Literal foo',
                            data_type='positiveInteger',
                            uoms=['metre'])
     doc = literal.describe_xml()
     assert doc.tag == E.Input().tag
     [identifier_el] = xpath_ns(doc, './ows:Identifier')
     assert identifier_el.text == 'foo'
     [type_el] = xpath_ns(doc, './LiteralData/ows:DataType')
     assert type_el.text == 'positiveInteger'
     assert type_el.attrib['{%s}reference' %
                           NAMESPACES['ows']] == OGCTYPE['positiveInteger']
     anyvalue = xpath_ns(doc, './LiteralData/ows:AnyValue')
     assert len(anyvalue) == 1
Пример #37
0
 def _handler(self, request, response):
     import lxml.etree
     from pywps.app.basic import xpath_ns
     doc = lxml.etree.parse(request.inputs['layer'][0].file)
     feature_elements = xpath_ns(doc, '//gml:featureMember')
     response.outputs['count'].data = len(feature_elements)
     return response
Пример #38
0
 def _handler(self, request, response):
     import lxml.etree
     from pywps.app.basic import xpath_ns
     doc = lxml.etree.parse(request.inputs['layer'][0].file)
     feature_elements = xpath_ns(doc, '//gml:featureMember')
     response.outputs['count'].data = len(feature_elements)
     return response
Пример #39
0
 def test_complex_input_identifier(self):
     complex_in = ComplexInput('foo',
                               'Complex foo',
                               supported_formats=[Format('bar/baz')])
     doc = complex_in.describe_xml()
     assert doc.tag == E.Input().tag
     [identifier_el] = xpath_ns(doc, './ows:Identifier')
     assert identifier_el.text == 'foo'
Пример #40
0
 def parse_post_getcapabilities(doc):
     """Parse POST GetCapabilities request
     """
     acceptedversions = xpath_ns(
         doc, '/wps:GetCapabilities/ows:AcceptVersions/ows:Version')
     acceptedversions = ','.join(
         map(lambda v: v.text, acceptedversions))
     wpsrequest.check_accepted_versions(acceptedversions)
Пример #41
0
 def parse_post_getcapabilities(doc):
     """Parse POST GetCapabilities request
     """
     acceptedversions = xpath_ns(
         doc, '/wps:GetCapabilities/ows:AcceptVersions/ows:Version')
     acceptedversions = ','.join(map(lambda v: v.text,
                                     acceptedversions))
     wpsrequest.check_accepted_versions(acceptedversions)
Пример #42
0
        def parse_post_describeprocess(doc):
            """Parse POST DescribeProcess request
            """

            version = doc.attrib.get('version')
            wpsrequest.check_and_set_version(version)

            wpsrequest.operation = 'describeprocess'
            wpsrequest.identifiers = [identifier_el.text for identifier_el in
                                xpath_ns(doc, './ows:Identifier')]
Пример #43
0
    def test_bbox(self):
        if not PY2:
            self.skipTest("OWSlib not python 3 compatible")
        client = client_for(Service(processes=[create_bbox_process()]))
        request_doc = WPS.Execute(
            OWS.Identifier("my_bbox_process"),
            WPS.DataInputs(
                WPS.Input(
                    OWS.Identifier("mybbox"),
                    WPS.Data(WPS.BoundingBoxData(OWS.LowerCorner("15 50"), OWS.UpperCorner("16 51"))),
                )
            ),
            version="1.0.0",
        )
        resp = client.post_xml(doc=request_doc)
        assert_response_success(resp)

        [output] = xpath_ns(resp.xml, "/wps:ExecuteResponse" "/wps:ProcessOutputs/Output")
        self.assertEqual("outbbox", xpath_ns(output, "./ows:Identifier")[0].text)
        self.assertEqual("15 50", xpath_ns(output, "./ows:BoundingBox/ows:LowerCorner")[0].text)
Пример #44
0
        def parse_post_describeprocess(doc):
            """Parse POST DescribeProcess request
            """

            version = doc.attrib.get('version')
            wpsrequest.check_and_set_version(version)

            wpsrequest.operation = 'describeprocess'
            wpsrequest.identifiers = [
                identifier_el.text
                for identifier_el in xpath_ns(doc, './ows:Identifier')
            ]
Пример #45
0
def get_inputs_from_xml(doc):
    the_inputs = {}
    for input_el in xpath_ns(doc, '/wps:Execute/wps:DataInputs/wps:Input'):
        [identifier_el] = xpath_ns(input_el, './ows:Identifier')
        identifier = identifier_el.text

        if identifier not in the_inputs:
            the_inputs[identifier] = []

        literal_data = xpath_ns(input_el, './wps:Data/wps:LiteralData')
        if literal_data:
            value_el = literal_data[0]
            inpt = {}
            inpt['identifier'] = identifier_el.text
            inpt['data'] = text_type(value_el.text)
            inpt['uom'] = value_el.attrib.get('uom', '')
            inpt['datatype'] = value_el.attrib.get('datatype', '')
            the_inputs[identifier].append(inpt)
            continue

        complex_data = xpath_ns(input_el, './wps:Data/wps:ComplexData')
        if complex_data:
            complex_data_el = complex_data[0]
            inpt = {}
            inpt['identifier'] = identifier_el.text
            if len(complex_data_el.getchildren()) > 0:
                value_el = complex_data_el[0]
                inpt['data'] = _get_dataelement_value(value_el)
            else:
                inpt['data'] = _get_rawvalue_value(complex_data_el.text)
            inpt['mimeType'] = complex_data_el.attrib.get('mimeType', '')
            inpt['encoding'] = complex_data_el.attrib.get('encoding', '')
            inpt['schema'] = complex_data_el.attrib.get('schema', '')
            inpt['method'] = complex_data_el.attrib.get('method', 'GET')
            the_inputs[identifier].append(inpt)
            continue

        reference_data = xpath_ns(input_el, './wps:Reference')
        if reference_data:
            reference_data_el = reference_data[0]
            inpt = {}
            inpt['identifier'] = identifier_el.text
            inpt[identifier_el.text] = reference_data_el.text
            inpt['href'] = reference_data_el.attrib.get(
                '{http://www.w3.org/1999/xlink}href', '')
            inpt['mimeType'] = reference_data_el.attrib.get('mimeType', '')
            the_inputs[identifier].append(inpt)
            continue

        # OWSlib is not python 3 compatible yet
        if PY2:
            from owslib.ows import BoundingBox
            bbox_datas = xpath_ns(input_el, './wps:Data/wps:BoundingBoxData')
            if bbox_datas:
                for bbox_data in bbox_datas:
                    bbox_data_el = bbox_data
                    bbox = BoundingBox(bbox_data_el)
                    the_inputs[identifier].append(bbox)

    return the_inputs
Пример #46
0
def get_output_from_xml(doc):
    the_output = {}

    if xpath_ns(doc, '/wps:Execute/wps:ResponseForm/wps:ResponseDocument'):
        for output_el in xpath_ns(
                doc,
                '/wps:Execute/wps:ResponseForm/wps:ResponseDocument/wps:Output'
        ):
            [identifier_el] = xpath_ns(output_el, './ows:Identifier')
            outpt = {}
            outpt[identifier_el.text] = ''
            outpt['mimetype'] = output_el.attrib.get('mimeType', '')
            outpt['encoding'] = output_el.attrib.get('encoding', '')
            outpt['schema'] = output_el.attrib.get('schema', '')
            outpt['uom'] = output_el.attrib.get('uom', '')
            outpt['asReference'] = output_el.attrib.get('asReference', 'false')
            the_output[identifier_el.text] = outpt

    elif xpath_ns(doc, '/wps:Execute/wps:ResponseForm/wps:RawDataOutput'):
        for output_el in xpath_ns(
                doc, '/wps:Execute/wps:ResponseForm/wps:RawDataOutput'):
            [identifier_el] = xpath_ns(output_el, './ows:Identifier')
            outpt = {}
            outpt[identifier_el.text] = ''
            outpt['mimetype'] = output_el.attrib.get('mimeType', '')
            outpt['encoding'] = output_el.attrib.get('encoding', '')
            outpt['schema'] = output_el.attrib.get('schema', '')
            outpt['uom'] = output_el.attrib.get('uom', '')
            the_output[identifier_el.text] = outpt

    return the_output
Пример #47
0
def get_output_from_xml(doc):
    the_output = {}

    if xpath_ns(doc, '/wps:Execute/wps:ResponseForm/wps:ResponseDocument'):
        for output_el in xpath_ns(doc, '/wps:Execute/wps:ResponseForm/wps:ResponseDocument/wps:Output'):
            [identifier_el] = xpath_ns(output_el, './ows:Identifier')
            outpt = {}
            outpt[identifier_el.text] = ''
            outpt['mimetype'] = output_el.attrib.get('mimeType', '')
            outpt['encoding'] = output_el.attrib.get('encoding', '')
            outpt['schema'] = output_el.attrib.get('schema', '')
            outpt['uom'] = output_el.attrib.get('uom', '')
            outpt['asReference'] = output_el.attrib.get('asReference', 'false')
            the_output[identifier_el.text] = outpt

    elif xpath_ns(doc, '/wps:Execute/wps:ResponseForm/wps:RawDataOutput'):
        for output_el in xpath_ns(doc, '/wps:Execute/wps:ResponseForm/wps:RawDataOutput'):
            [identifier_el] = xpath_ns(output_el, './ows:Identifier')
            outpt = {}
            outpt[identifier_el.text] = ''
            outpt['mimetype'] = output_el.attrib.get('mimeType', '')
            outpt['encoding'] = output_el.attrib.get('encoding', '')
            outpt['schema'] = output_el.attrib.get('schema', '')
            outpt['uom'] = output_el.attrib.get('uom', '')
            the_output[identifier_el.text] = outpt

    return the_output
Пример #48
0
def get_inputs_from_xml(doc):
    the_inputs = {}
    for input_el in xpath_ns(doc, '/wps:Execute/wps:DataInputs/wps:Input'):
        [identifier_el] = xpath_ns(input_el, './ows:Identifier')
        identifier = identifier_el.text

        if identifier not in the_inputs:
            the_inputs[identifier] = []

        literal_data = xpath_ns(input_el, './wps:Data/wps:LiteralData')
        if literal_data:
            value_el = literal_data[0]
            inpt = {}
            inpt['identifier'] = identifier_el.text
            inpt['data'] = text_type(value_el.text)
            inpt['uom'] = value_el.attrib.get('uom', '')
            inpt['datatype'] = value_el.attrib.get('datatype', '')
            the_inputs[identifier].append(inpt)
            continue

        complex_data = xpath_ns(input_el, './wps:Data/wps:ComplexData')
        if complex_data:
            complex_data_el = complex_data[0]
            inpt = {}
            inpt['identifier'] = identifier_el.text
            if len(complex_data_el.getchildren()) > 0:
                value_el = complex_data_el[0]
                inpt['data'] = _get_dataelement_value(value_el)
            else:
                inpt['data'] = _get_rawvalue_value(complex_data_el.text)
            inpt['mimeType'] = complex_data_el.attrib.get('mimeType', '')
            inpt['encoding'] = complex_data_el.attrib.get('encoding', '')
            inpt['schema'] = complex_data_el.attrib.get('schema', '')
            inpt['method'] = complex_data_el.attrib.get('method', 'GET')
            the_inputs[identifier].append(inpt)
            continue

        reference_data = xpath_ns(input_el, './wps:Reference')
        if reference_data:
            reference_data_el = reference_data[0]
            inpt = {}
            inpt['identifier'] = identifier_el.text
            inpt[identifier_el.text] = reference_data_el.text
            inpt['href'] = reference_data_el.attrib.get('{http://www.w3.org/1999/xlink}href', '')
            inpt['mimeType'] = reference_data_el.attrib.get('mimeType', '')
            the_inputs[identifier].append(inpt)
            continue

        # OWSlib is not python 3 compatible yet
        if PY2:
            from owslib.ows import BoundingBox
            bbox_datas = xpath_ns(input_el, './wps:Data/wps:BoundingBoxData')
            if bbox_datas:
                for bbox_data in bbox_datas:
                    bbox_data_el = bbox_data
                    bbox = BoundingBox(bbox_data_el)
                    the_inputs[identifier].append(bbox)

    return the_inputs
Пример #49
0
    def get_input_from_xml(doc):
        the_input = {}
        for input_el in xpath_ns(doc, '/wps:Execute/wps:DataInputs/wps:Input'):
            [identifier_el] = xpath_ns(input_el, './ows:Identifier')

            literal_data = xpath_ns(input_el, './wps:Data/wps:LiteralData')
            if literal_data:
                value_el = literal_data[0]
                inpt = {}
                inpt['identifier'] = identifier_el.text
                inpt['data'] = text_type(value_el.text)
                inpt['uom'] = value_el.attrib.get('uom', '')
                inpt['datatype'] = value_el.attrib.get('datatype', '')
                the_input[identifier_el.text] = inpt
                continue

            complex_data = xpath_ns(input_el, './wps:Data/wps:ComplexData')
            if complex_data:
                complex_data_el = complex_data[0]
                value_el = complex_data_el[0]
                inpt = {}
                inpt['identifier'] = identifier_el.text
                inpt['data'] = value_el
                inpt['mime_type'] = complex_data_el.attrib.get('mimeType', '')
                inpt['encoding'] = complex_data_el.attrib.get('encoding', '')
                inpt['schema'] = complex_data_el.attrib.get('schema', '')
                inpt['method'] = complex_data_el.attrib.get('method', 'GET')
                the_input[identifier_el.text] = inpt
                continue

            reference_data = xpath_ns(input_el, './wps:Reference')
            if reference_data:
                reference_data_el = reference_data[0]
                inpt = {}
                inpt['identifier'] = identifier_el.text
                inpt[identifier_el.text] = reference_data_el.text
                inpt['href'] = reference_data_el.attrib.get('href', '')
                if not inpt['href']:
                    inpt['href'] = reference_data_el.attrib.get('{http://www.w3.org/1999/xlink}href', '')
                inpt['mimeType'] = reference_data_el.attrib.get('mimeType', '')
                the_input[identifier_el.text] = inpt
                continue

            # OWSlib is not python 3 compatible yet
            if PY2:
                from owslib.ows import BoundingBox

                bbox_data = xpath_ns(input_el, './wps:Data/wps:BoundingBoxData')
                if bbox_data:
                    bbox_data_el = bbox_data[0]
                    bbox = BoundingBox(bbox_data_el)
                    the_input.update({identifier_el.text: bbox})
                    continue

        return the_input
Пример #50
0
    def test_literal_output(self):
        literal = LiteralOutput('literal', 'Literal foo', abstract='Description', keywords=['kw1', 'kw2'], uoms=['metre'])
        doc = literal.describe_xml()
        [output] = xpath_ns(doc, '/Output')
        [identifier] = xpath_ns(doc, '/Output/ows:Identifier')
        [abstract] = xpath_ns(doc, '/Output/ows:Abstract')
        [keywords] = xpath_ns(doc, '/Output/ows:Keywords')
        kws = xpath_ns(keywords, './ows:Keyword')
        [data_type] = xpath_ns(doc, '/Output/LiteralOutput/ows:DataType')
        [uoms] = xpath_ns(doc, '/Output/LiteralOutput/UOMs')
        [default_uom] = xpath_ns(uoms, './Default/ows:UOM')
        supported_uoms = xpath_ns(uoms, './Supported/ows:UOM')

        assert output is not None
        assert identifier.text == 'literal'
        assert abstract.text == 'Description'
        assert keywords is not None
        assert len(kws) == 2
        assert data_type.attrib['{%s}reference' % NAMESPACES['ows']] == OGCTYPE['string']
        assert uoms is not None
        assert default_uom.text == 'metre'
        assert default_uom.attrib['{%s}reference' % NAMESPACES['ows']] == OGCUNIT['metre']
        assert len(supported_uoms) == 1
Пример #51
0
    def test_literal_output(self):
        literal = LiteralOutput("literal", "Literal foo", uoms=["metre"])
        doc = literal.describe_xml()
        [output] = xpath_ns(doc, "/Output")
        [identifier] = xpath_ns(doc, "/Output/ows:Identifier")
        [data_type] = xpath_ns(doc, "/Output/LiteralOutput/ows:DataType")
        [uoms] = xpath_ns(doc, "/Output/LiteralOutput/UOMs")
        [default_uom] = xpath_ns(uoms, "./Default/ows:UOM")
        supported_uoms = xpath_ns(uoms, "./Supported/ows:UOM")

        assert output is not None
        assert identifier.text == "literal"
        assert data_type.attrib["{%s}reference" % NAMESPACES["ows"]] == OGCTYPE["string"]
        assert uoms is not None
        assert default_uom.text == "metre"
        assert default_uom.attrib["{%s}reference" % NAMESPACES["ows"]] == OGCUNIT["metre"]
        assert len(supported_uoms) == 1