Exemple #1
0
def _encode_operations_metadata(conf):
    """ Encode OperationsMetadata XML element. """
    component = ServiceComponent(env)
    versions = ("1.0.0", )
    get_handlers = component.query_service_handlers(service="WPS",
                                                    versions=versions,
                                                    method="GET")
    post_handlers = component.query_service_handlers(service="WPS",
                                                     versions=versions,
                                                     method="POST")
    all_handlers = sorted(set(get_handlers + post_handlers),
                          key=lambda h: h.request)
    url = conf.http_service_url
    return OWS(
        "OperationsMetadata", *[
            OWS("Operation",
                OWS(
                    "DCP",
                    OWS(
                        "HTTP",
                        OWS("Get", **{ns_xlink("href"): url}),
                        OWS("Post", **{ns_xlink("href"): url}),
                    )),
                name=handler.request) for handler in all_handlers
        ])
def _encode_operations_metadata(conf):
    component = ServiceComponent(env)
    versions = ("1.0.0",)
    get_handlers = component.query_service_handlers(
        service="WPS", versions=versions, method="GET"
    )
    post_handlers = component.query_service_handlers(
        service="WPS", versions=versions, method="POST"
    )
    all_handlers = sorted(
        set(get_handlers + post_handlers), key=lambda h: h.request
    )
    url = conf.http_service_url
    return OWS("OperationsMetadata", *[
        OWS("Operation",
            OWS("DCP",
                OWS("HTTP",
                    # TODO: only select available
                    OWS("Get", **{ns_xlink("href"): url}),
                    OWS("Post", **{ns_xlink("href"): url}),
                )
            ), name=handler.request
        )
        for handler in all_handlers
    ])
Exemple #3
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,
    )
Exemple #4
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
Exemple #5
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
Exemple #6
0
    def encode_capabilities(processes):
        """ Encode Capabilities XML document. """
        conf = CapabilitiesConfigReader(get_eoxserver_config())

        # Avoid duplicate process offerings ...
        process_set = set()
        process_offerings = []
        for process in processes:
            process_identifier = (getattr(process, 'identifier', None)
                                  or type(process).__name__)
            if process_identifier not in process_set:
                process_offerings.append(encode_process_brief(process))
                process_set.add(process_identifier)

        return WPS(
            "Capabilities",
            OWS(
                "ServiceIdentification",
                OWS("Title", conf.title),
                OWS("Abstract", conf.abstract),
                OWS("Keywords", *(OWS("Keyword", kw) for kw in conf.keywords)),
                OWS("ServiceType", "WPS"),
                OWS("ServiceTypeVersion", "1.0.0"),
                OWS("Fees", conf.fees),
                OWS("AccessConstraints", conf.access_constraints),
            ),
            OWS(
                "ServiceProvider", OWS("ProviderName", conf.provider_name),
                OWS("ProviderSite", **{ns_xlink("href"): conf.provider_site}),
                OWS(
                    "ServiceContact",
                    OWS("IndividualName", conf.individual_name),
                    OWS("PositionName", conf.position_name),
                    OWS(
                        "ContactInfo",
                        OWS("Phone", OWS("Voice", conf.phone_voice),
                            OWS("Facsimile", conf.phone_facsimile)),
                        OWS(
                            "Address", OWS("DeliveryPoint",
                                           conf.delivery_point),
                            OWS("City", conf.city),
                            OWS("AdministrativeArea",
                                conf.administrative_area),
                            OWS("PostalCode", conf.postal_code),
                            OWS("Country", conf.country),
                            OWS("ElectronicMailAddress",
                                conf.electronic_mail_address))))),
            _encode_operations_metadata(conf),
            WPS("ProcessOfferings", *process_offerings),
            WPS("Languages", WPS("Default", OWS("Language", "en-US")),
                WPS("Supported", OWS("Language", "en-US"))),
            # TODO: WPS("WSDL")
            **{
                "service": "WPS",
                "version": "1.0.0",
                ns_xml("lang"): "en-US",
                "updateSequence": conf.update_sequence,
            })
 def encode_capabilities(processes):
     conf = CapabilitiesConfigReader(get_eoxserver_config())
     return WPS("Capabilities",
         OWS("ServiceIdentification",
             OWS("Title", conf.title),
             OWS("Abstract", conf.abstract),
             OWS("Keywords", *(OWS("Keyword", kw) for kw in conf.keywords)),
             OWS("ServiceType", "WPS"),
             OWS("ServiceTypeVersion", "1.0.0"),
             OWS("Fees", conf.fees),
             OWS("AccessConstraints", conf.access_constraints),
         ),
         OWS("ServiceProvider",
             OWS("ProviderName", conf.provider_name),
             OWS("ProviderSite", **{ns_xlink("href"): conf.provider_site}),
             OWS("ServiceContact",
                 OWS("IndividualName", conf.individual_name),
                 OWS("PositionName", conf.position_name),
                 OWS("ContactInfo",
                     OWS("Phone",
                         OWS("Voice", conf.phone_voice),
                         OWS("Facsimile", conf.phone_facsimile)
                     ),
                     OWS("Address",
                         OWS("DeliveryPoint", conf.delivery_point),
                         OWS("City", conf.city),
                         OWS("AdministrativeArea", conf.administrative_area),
                         OWS("PostalCode", conf.postal_code),
                         OWS("Country", conf.country),
                         OWS("ElectronicMailAddress", conf.electronic_mail_address)
                     )
                 )
             )
         ),
         _encode_operations_metadata(conf),
         WPS("ProcessOfferings", *(encode_process_brief(p) for p in processes)),
         WPS("Languages",
             WPS("Default",
                 OWS("Language", "en-US")
             ),
             WPS("Supported",
                 OWS("Language", "en-US")
             )
         ),
         # TODO: WPS("WSDL") ?
         **{
             "service": "WPS",
             "version": "1.0.0",
             ns_xml("lang"): "en-US",
             "updateSequence": conf.update_sequence,
         }
     )
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,
    )
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
Exemple #10
0
def _encode_input_reference(ref):
    """ Encode DataInputs/Reference element. """
    #TODO proper input reference encoding
    return WPS("Reference", **{ns_xlink("href"): ref.href})
Exemple #11
0
def _encode_metadata(title, href):
    """ Encode one Metadata element. """
    return OWS("Metadata", **{ns_xlink("title"): title, ns_xlink("href"): href})
def _encode_input_reference(ref):
    #TODO proper input reference encoding
    return WPS("Reference", **{ns_xlink("href"): ref.href})
def _encode_metadata(title, href):
    return OWS("Metadata", **{ns_xlink("title"): title, ns_xlink("href"): href})
def _encode_input_reference(ref):
    """ Encode DataInputs/Reference element. """
    #TODO proper input reference encoding
    return WPS("Reference", **{ns_xlink("href"): ref.href})