예제 #1
0
def _parse_input_reference(elem, identifier, title, abstract):
    """ Parse one input item passed as a reference. """
    href = elem.attrib.get(ns_xlink("href"))
    if href is None:
        raise ValueError("Missing the mandatory 'xlink:href' attribute!")

    body = elem.findtext("./" + ns_wps("Body"))
    elem_tmp = elem.find("./" + ns_wps("BodyReference"))
    body_href = elem_tmp.attrib.get(ns_xlink("href")) if elem_tmp else None

    headers = dict((header.attrib["key"], header.attrib["value"])
                   for header in elem.iterfind("./" + ns_wps("Header")))

    return InputReference(
        identifier,
        title,
        abstract,
        href,
        headers,
        body,
        elem.attrib.get("method", "GET"),
        elem.attrib.get("mimeType"),
        elem.attrib.get("encoding"),
        elem.attrib.get("schema"),
        body_href,
    )
예제 #2
0
def parse_input_xml(element):
    name = element.xpath("ows:Identifier/text()", namespaces=nsmap)[0]
    data_elem = element.xpath("wps:Data/*[1]", namespaces=nsmap)[0]

    if data_elem.tag == ns_wps("Reference"):
        headers = dict(
            (header.attrib["key"], header.attrib["value"]) for header in data_elem.xpath("wps:Header", namespaces=nsmap)
        )
        body = etree.tostring(data_elem.xpath("wps:Body")[0])
        # TODO: BodyReference?

        value = Reference(
            data_elem.attrib[ns_xlink("href")],
            headers,
            body,
            data_elem.attrib.get("method", "GET"),
            data_elem.attrib.get("mimeType"),
            data_elem.attrib.get("encoding"),
            data_elem.attrib.get("schema"),
        )

    elif data_elem.tag == ns_wps("LiteralData"):
        value = data_elem.text

    elif data_elem.tag == ns_wps("BoundingBoxData"):
        # TODO: parse BBOX
        pass

    elif data_elem.tag == ns_wps("ComplexData"):
        value = data_elem[0]

    return name, value
예제 #3
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')
예제 #4
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_data(elem, identifier, title, abstract):
    if elem.tag == ns_wps("LiteralData"):
        args = _parse_input_literal(elem)
    elif elem.tag == ns_wps("BoundingBoxData"):
        args = _parse_input_bbox(elem)
    elif elem.tag == ns_wps("ComplexData"):
        args = _parse_input_complex(elem)
    else:
        raise ValueError("Invalid input content of the 'wps:Data' element!")

    return InputData(identifier, title, abstract, **args)
예제 #6
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
예제 #7
0
def _parse_input_data(elem, identifier, title, abstract):
    """ Parse one input item value. """
    if elem.tag == ns_wps("LiteralData"):
        args = _parse_input_literal(elem)
    elif elem.tag == ns_wps("BoundingBoxData"):
        args = _parse_input_bbox(elem)
    elif elem.tag == ns_wps("ComplexData"):
        args = _parse_input_complex(elem)
    else:
        raise ValueError("Invalid input content of the 'wps:Data' element!")
    return InputData(identifier=identifier,
                     title=title,
                     abstract=abstract,
                     **args)
예제 #8
0
def _encode_process_brief(process, elem):
    """ Insert a brief process description into an XML element passed as the
    second argument.
    The brief process description is shared by both the Capabilities and
    ProcessDescriptions XML encoders.
    """
    identifier = getattr(process, 'identifier', type(process).__name__)
    title = getattr(process, 'title', identifier)
    abstract = getattr(process, 'description', process.__doc__)
    version = getattr(process, "version", "1.0.0")
    metadata = getattr(process, "metadata", {})
    profiles = getattr(process, "profiles", [])
    wsdl = getattr(process, "wsdl", None)

    elem.append(OWS("Identifier", identifier))
    elem.append(OWS("Title", title))
    elem.attrib[ns_wps("processVersion")] = version
    if abstract:
        elem.append(OWS("Abstract", abstract))
    elem.extend(_encode_metadata(k, metadata[k]) for k in metadata)
    elem.extend(WPS("Profile", profile) for profile in profiles)
    if wsdl:
        elem.append(WPS("WSDL", **{ns_xlink("href"): wsdl}))

    return elem
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
def _parse_input_reference(elem, identifier, title, abstract):
    href = elem.attrib.get(ns_xlink("href"))
    if href is None:
        raise ValueError("Missing the mandatory 'xlink:href' attribute!")

    body = elem.findtext("./"+ns_wps("Body"))
    elem_tmp = elem.find("./"+ns_wps("BodyReference"))
    body_href = elem_tmp.attrib.get(ns_xlink("href")) if elem_tmp else None

    headers = dict(
        (header.attrib["key"], header.attrib["value"])
        for header in elem.iterfind("./"+ns_wps("Header"))
    )

    return InputReference(
        identifier, title, abstract,
        href, headers, body,
        elem.attrib.get("method", "GET"),
        elem.attrib.get("mimeType"),
        elem.attrib.get("encoding"),
        elem.attrib.get("schema"),
        body_href,
    )
예제 #11
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
예제 #12
0
    def encode_process_brief(self, process):
        elem = WPS("Process",
            OWS("Identifier", process.identifier),
            OWS("Title", getattr(process, "title", None) or process.identifier),
            OWS("Abstract", getattr(process, "description", ""))
        )

        elem.extend([
            OWS("Metadata", metadata)
            for metadata in getattr(process, "metadata", [])
        ])

        elem.extend([
            OWS("Profile", profile)
            for profile in getattr(process, "profiles", [])
        ])

        version = getattr(process, "version", None)
        if version:
            elem.attr[ns_wps("processVersion")] = version

        return elem
예제 #13
0
def _encode_process_brief(process, elem):
    """ auxiliary shared brief process description encoder"""
    id_ = getattr(process, 'identifier', process.__class__.__name__)
    title = getattr(process, 'title', id_)
    #abstract = getattr(process, 'abstract', process.__class__.__doc__)
    abstract = getattr(process, 'description', process.__class__.__doc__)
    version = getattr(process, "version", "1.0.0")
    metadata = getattr(process, "metadata", {})
    profiles = getattr(process, "profiles", [])
    wsdl = getattr(process, "wsdl", None)

    elem.append(OWS("Identifier", id_))
    elem.append(OWS("Title", title))
    elem.attrib[ns_wps("processVersion")] = version
    if abstract:
        elem.append(OWS("Abstract", abstract))
    elem.extend(_encode_metadata(k, metadata[k]) for k in metadata)
    elem.extend(WPS("Profile", p) for p in profiles)
    if wsdl:
        elem.append(WPS("WSDL", **{ns_xlink("href"): wsdl}))

    return elem