예제 #1
0
def _parse_response_form(elem_rform):
    """ Parse ResponseForm element holding either ResponseDocument or
    RawDataOutput elements.
    """
    elem_rdoc = elem_rform.find("./"+ns_wps("ResponseDocument"))
    if elem_rdoc is not None:
        rdoc = ResponseDocument(
            lineage=parse_bool(elem_rdoc.attrib.get("lineage")),
            status=parse_bool(elem_rdoc.attrib.get("status")),
            store_response=parse_bool(
                elem_rdoc.attrib.get("storeExecuteResponse")
            ),
        )
        for elem in elem_rdoc.iterfind("./"+ns_wps("Output")):
            id_ = elem.findtext(ns_ows("Identifier"))
            title = elem.findtext(ns_ows("Title"))
            abstr = elem.findtext(ns_ows("Abstract"))
            rdoc.set_output(_create_output(id_, elem.attrib, title, abstr))
        return rdoc

    elem_rawout = elem_rform.find("./"+ns_wps("RawDataOutput"))
    if elem_rawout is not None:
        id_ = elem_rawout.findtext(ns_ows("Identifier"))
        return RawDataOutput(_create_output(id_, elem_rawout.attrib))

    raise InvalidParameterValue('Invalid ResponseForm!', 'ResponseForm')
예제 #2
0
def _parse_response_form(elem_rform):
    """ Parse ResponseForm element holding either ResponseDocument or
    RawDataOutput elements.
    """
    elem_rdoc = elem_rform.find("./" + ns_wps("ResponseDocument"))
    if elem_rdoc is not None:
        rdoc = ResponseDocument(
            lineage=parse_bool(elem_rdoc.attrib.get("lineage")),
            status=parse_bool(elem_rdoc.attrib.get("status")),
            store_response=parse_bool(
                elem_rdoc.attrib.get("storeExecuteResponse")),
        )
        for elem in elem_rdoc.iterfind("./" + ns_wps("Output")):
            id_ = elem.findtext(ns_ows("Identifier"))
            title = elem.findtext(ns_ows("Title"))
            abstr = elem.findtext(ns_ows("Abstract"))
            rdoc.set_output(_create_output(id_, elem.attrib, title, abstr))
        return rdoc

    elem_rawout = elem_rform.find("./" + ns_wps("RawDataOutput"))
    if elem_rawout is not None:
        id_ = elem_rawout.findtext(ns_ows("Identifier"))
        return RawDataOutput(_create_output(id_, elem_rawout.attrib))

    raise InvalidParameterValue('Invalid ResponseForm!', 'ResponseForm')
def _parse_input_bbox(elem):
    args = {}
    lower_corner = elem.findtext("./"+ns_ows("LowerCorner"))
    upper_corner = elem.findtext("./"+ns_ows("UpperCorner"))
    if lower_corner is None or upper_corner is None:
        raise ValueError("Invalid 'wps:BoundingBoxData' element!")
    args['data'] = (lower_corner, upper_corner, elem.attrib.get("crs"))
    return args
예제 #4
0
def _parse_input_bbox(elem):
    """ Parse one bounding-box input item value. """
    args = {}
    lower_corner = elem.findtext("./" + ns_ows("LowerCorner"))
    upper_corner = elem.findtext("./" + ns_ows("UpperCorner"))
    if lower_corner is None or upper_corner is None:
        raise ValueError("Invalid 'wps:BoundingBoxData' element!")
    args['data'] = (lower_corner, upper_corner, elem.attrib.get("crs"))
    return args
예제 #5
0
def parse_response_form_xml(elem):
    if elem.tag == ns_wps("ResponseDocument"):
        outputs = {}
        for output_elem in elem.xpath("wps:Output", namespaces=nsmap):
            identifier = output_elem.findtext(ns_ows("Identifier"))
            outputs[identifier] = parse_output(output_elem.attrib)

        return ResponseDocument(outputs, elem.attrib.get("lineage") == "true")
    elif elem.tag == ns_wps("RawDataOutput"):
        return RawDataOutput({elem.findtext(ns_ows("Identifier")): parse_output(elem.attrib)})

    raise
예제 #6
0
def _encode_literal(prm, is_input):
    """ Encode process description LiteralData (parameter definition) element.
    """
    dtype = prm.dtype
    elem = NIL("LiteralData" if is_input else "LiteralOutput")

    elem.append(
        OWS(
            "DataType", dtype.name, **{
                ns_ows("reference"):
                "http://www.w3.org/TR/xmlschema-2/#%s" % dtype.name,
            }))

    if prm.uoms:
        elem.append(
            NIL("UOMs", NIL("Default", OWS("UOM", prm.uoms[0])),
                NIL("Supported", *[OWS("UOM", u) for u in prm.uoms])))

    if is_input:
        elem.append(_encode_allowed_value(prm.allowed_values))

        if prm.default is not None:
            elem.append(NIL("DefaultValue", str(prm.default)))

    return elem
예제 #7
0
def _encode_allowed_value(avobj):
    """ Encode process description LiteralData allowed values definition.
    Based on the type of the allowed value definition either AnyValue,
    ValuesReference, or AllowedValues element is returned.
    """
    enum, ranges, elist = None, [], []

    if isinstance(avobj, AllowedAny):
        return OWS("AnyValue")
    elif isinstance(avobj, AllowedByReference):
        return WPS(
            "ValuesReference", **{
                ns_ows("reference"): avobj.url,
                "valuesForm": avobj.url,
            })
    elif isinstance(avobj, AllowedEnum):
        enum = avobj
    elif isinstance(avobj, AllowedRange):
        ranges = [avobj]
    elif isinstance(avobj, AllowedRangeCollection):
        enum, ranges = avobj.enum, avobj.ranges
    else:
        raise TypeError("Invalid allowed value object! OBJ=%r" % avobj)

    dtype = avobj.dtype
    ddtype = dtype.get_diff_dtype()

    if enum is not None:
        elist.extend(OWS("Value", dtype.encode(v)) for v in enum.values)
    for range_ in ranges:
        attr, elms = {}, []
        if range_.closure != 'closed':
            attr = {ns_ows("rangeClosure"): range_.closure}
        if range_.minval is not None:
            elms.append(OWS("MinimumValue", dtype.encode(range_.minval)))
        if range_.maxval is not None:
            elms.append(OWS("MaximumValue", dtype.encode(range_.maxval)))
        if range_.spacing is not None:
            elms.append(OWS("Spacing", ddtype.encode(range_.spacing)))
        elist.append(OWS("Range", *elms, **attr))

    return OWS("AllowedValues", *elist)
def _parse_input(element):
    id_ = element.findtext("./"+ns_ows("Identifier"))
    title = element.findtext("./"+ns_ows("Title"))
    abstract = element.findtext("./"+ns_ows("Abstract"))

    if id_ is None:
        raise ValueError("Missing the mandatory input identifier!")

    elem_ref = element.find("./"+ns_wps("Reference"))
    elem_data = element.find("./"+ns_wps("Data"))

    if elem_ref is not None:
        value = _parse_input_reference(elem_ref, id_, title, abstract)

    elif elem_data is not None:
        if len(elem_data) != 1:
            raise ValueError("Invalid input content of the 'wps:Data' element!")
        value = _parse_input_data(elem_data[0], id_, title, abstract)

    return id_, value
예제 #9
0
def _encode_allowed_value(avobj):
    """ Encode process description LiteralData allowed values definition.
    Based on the type of the allowed value definition either AnyValue,
    ValuesReference, or AllowedValues element is returned.
    """
    enum, ranges, elist = None, [], []

    if isinstance(avobj, AllowedAny):
        return OWS("AnyValue")
    elif isinstance(avobj, AllowedByReference):
        return WPS("ValuesReference", **{
            ns_ows("reference"): avobj.url,
            "valuesForm": avobj.url,
        })
    elif isinstance(avobj, AllowedEnum):
        enum = avobj
    elif isinstance(avobj, AllowedRange):
        ranges = [avobj]
    elif isinstance(avobj, AllowedRangeCollection):
        enum, ranges = avobj.enum, avobj.ranges
    else:
        raise TypeError("Invalid allowed value object! OBJ=%r"%avobj)

    dtype = avobj.dtype
    ddtype = dtype.get_diff_dtype()

    if enum is not None:
        elist.extend(OWS("Value", dtype.encode(v)) for v in enum.values)
    for range_ in ranges:
        attr, elms = {}, []
        if range_.closure != 'closed':
            attr = {ns_ows("rangeClosure"): range_.closure}
        if range_.minval is not None:
            elms.append(OWS("MinimumValue", dtype.encode(range_.minval)))
        if range_.maxval is not None:
            elms.append(OWS("MaximumValue", dtype.encode(range_.maxval)))
        if range_.spacing is not None:
            elms.append(OWS("Spacing", ddtype.encode(range_.spacing)))
        elist.append(OWS("Range", *elms, **attr))

    return OWS("AllowedValues", *elist)
예제 #10
0
def _parse_input(element):
    """ Parse one data input element. """
    id_ = element.findtext("./" + ns_ows("Identifier"))
    title = element.findtext("./" + ns_ows("Title"))
    abstract = element.findtext("./" + ns_ows("Abstract"))

    if id_ is None:
        raise ValueError("Missing the mandatory input identifier!")

    elem_ref = element.find("./" + ns_wps("Reference"))
    elem_data = element.find("./" + ns_wps("Data"))

    if elem_ref is not None:
        value = _parse_input_reference(elem_ref, id_, title, abstract)

    elif elem_data is not None:
        if len(elem_data) != 1:
            raise ValueError(
                "Invalid input content of the 'wps:Data' element!")
        # pylint: disable=redefined-variable-type
        value = _parse_input_data(elem_data[0], id_, title, abstract)

    return id_, value
예제 #11
0
def _encode_literal(prm, is_input):
    dtype = prm.dtype
    elem = NIL("LiteralData" if is_input else "LiteralOutput")

    elem.append(OWS("DataType", dtype.name, **{
        ns_ows("reference"): "http://www.w3.org/TR/xmlschema-2/#%s"%dtype.name,
    }))

    if prm.uoms:
        elem.append(NIL("UOMs",
            NIL("Default", OWS("UOM", prm.uoms[0])),
            NIL("Supported", *[OWS("UOM", u) for u in prm.uoms])
        ))

    if is_input:
        elem.append(_encode_allowed_value(prm.allowed_values))

        if prm.default is not None:
            elem.append(NIL("DefaultValue", str(prm.default)))

    return elem
예제 #12
0
    def encode_parameter(self, name, parameter, is_input):
        # support for the shorthand
        if is_literal_type(parameter):
            parameter = LiteralData(name, parameter)

        # TODO: minOccurs/maxOccurs correct
        elem = WPS("Input" if is_input else "Output",
            OWS("Identifier", parameter.identifier or name)
        )

        if parameter.title:
            elem.append(OWS("Title", parameter.title))
        if parameter.description:
            elem.append(OWS("Abstract", parameter.description))

        if isinstance(parameter, LiteralData):
            data_elem = WPS("LiteralData" if is_input else "LiteralOutput")

            literal_type_name = parameter.type_name
            if literal_type_name:
                data_elem.append(
                    OWS("DataType", literal_type_name, **{
                        ns_ows("reference"): "http://www.w3.org/TR/xmlschema-2/#%s" % literal_type_name
                    })
                )

            if parameter.uoms:
                data_elem.append(
                    WPS("UOMs",
                        WPS("Default",
                            OWS("UOM", parameter.uoms[0])
                        ),
                        WPS("Supported", *[
                            OWS("UOM", uom) for uom in parameter.uoms
                        ])
                    )
                )

            if is_input and parameter.allowed_values:
                data_elem.append(
                    OWS("AllowedValues", *[
                        OWS("AllowedValue", str(allowed_value))
                        for allowed_value in parameter.allowed_values
                    ])
                )
            elif is_input and parameter.values_reference:
                data_elem.append(
                    WPS("ValuesReference", **{
                        ns_ows("reference"): parameter.values_reference,
                        "valuesForm": parameter.values_reference
                    })
                )
            elif is_input:
                data_elem.append(OWS("AnyValue"))

            if is_input and parameter.default is not None:
                elem.attrib["minOccurs"] = "0"
                data_elem.append(
                    WPS("Default", str(parameter.default))
                )

        elif isinstance(parameter, ComplexData):
            formats = parameter.formats
            if isinstance(formats, Format):
                formats = (formats,)

            data_elem = WPS("ComplexData" if is_input else "ComplexOutput",
                WPS("Default",
                    self.encode_format(formats[0])
                ),
                WPS("Supported", *[
                    self.encode_format(frmt) for frmt in formats
                ])
            )

        elif isinstance(parameter, BoundingBoxData):
            # TODO: implement
            data_elem = WPS("BoundingBoxData" if is_input else "BoundingBoxOutput")

        elem.append(data_elem)
        return elem