Esempio n. 1
0
def encode_process_full(process):
    """ Encode a full process description (ProcessDescription element) of the
    ProcessDescriptions XML document.
    """
    if getattr(process, 'asynchronous', False):
        supports_store = True
        supports_update = True
    else:
        supports_store = False
        supports_update = False

    # TODO: remove backward compatibility support for inputs/outputs dicts
    if isinstance(process.inputs, dict):
        process.inputs = process.inputs.items()
    if isinstance(process.outputs, dict):
        process.outputs = process.outputs.items()

    inputs = [
        item for item in (
            encode_input_descr(fix_parameter(n, p)) for n, p in process.inputs
        ) if item is not None
    ]
    outputs = [
        encode_output_descr(fix_parameter(n, p)) for n, p in process.outputs
    ]

    elem = _encode_process_brief(process, NIL("ProcessDescription"))
    if supports_store:
        elem.attrib["storeSupported"] = "true"
    if supports_update:
        elem.attrib["statusSupported"] = "true"
    elem.append(NIL("DataInputs", *inputs))
    elem.append(NIL("ProcessOutputs", *outputs))

    return elem
Esempio n. 2
0
def _encode_format(frmt):
    elem = NIL("Format", NIL("MimeType", frmt.mime_type))
    if frmt.encoding is not None:
        elem.append(NIL("Encoding", frmt.encoding))
    if frmt.schema is not None:
        elem.append(NIL("Schema", frmt.schema))
    return elem
Esempio n. 3
0
def _encode_complex(prm, is_input):
    """ Encode process description ComplexData (parameter definition) element.
    """
    return NIL(
        "ComplexData" if is_input else "ComplexOutput",
        NIL("Default", _encode_format(prm.default_format)),
        NIL("Supported",
            *[_encode_format(f) for f in prm.formats.itervalues()]))
Esempio n. 4
0
def _encode_bbox(prm, is_input):
    """ Encode process description BoundingBoxData (parameter definition)
    element.
    """
    return NIL(
        "BoundingBoxData" if is_input else "BoundingBoxOutput",
        NIL("Default", NIL("CRS", prm.encode_crs(prm.default_crs))),
        NIL("Supported",
            *[NIL("CRS", prm.encode_crs(crs)) for crs in prm.crss]))
Esempio n. 5
0
def _encode_format(frmt):
    """ Encode process description ComplexData format definition.
    The function returns Format element.
    """
    elem = NIL("Format", NIL("MimeType", frmt.mime_type))
    if frmt.encoding is not None:
        elem.append(NIL("Encoding", frmt.encoding))
    if frmt.schema is not None:
        elem.append(NIL("Schema", frmt.schema))
    return elem
Esempio n. 6
0
def _encode_format(frmt):
    """ Encode process description ComplexData format definition.
    The function returns Format element.
    """
    elem = NIL("Format", NIL("MimeType", frmt.mime_type))
    if frmt.encoding is not None:
        elem.append(NIL("Encoding", frmt.encoding))
    if frmt.schema is not None:
        elem.append(NIL("Schema", frmt.schema))
    return elem
Esempio n. 7
0
def encode_input_descr(prm):
    """ Encode process description Input element."""
    # Request input parameters are not visible from the process description.
    if isinstance(prm, RequestParameter):
        return None
    elem = NIL("Input", *_encode_param_common(prm))
    elem.attrib["minOccurs"] = ("1", "0")[bool(prm.is_optional)]
    elem.attrib["maxOccurs"] = "1"
    if isinstance(prm, LiteralData):
        elem.append(_encode_literal(prm, True))
    elif isinstance(prm, ComplexData):
        elem.append(_encode_complex(prm, True))
    elif isinstance(prm, BoundingBoxData):
        elem.append(_encode_bbox(prm, True))
    return elem
Esempio n. 8
0
def encode_input_descr(prm):
    """ Encode process description input."""
    elem = NIL("Input", *_encode_param_common(prm))
    elem.attrib["minOccurs"] = ("1", "0")[bool(prm.is_optional)]
    elem.attrib["maxOccurs"] = "1"
    if isinstance(prm, LiteralData):
        elem.append(_encode_literal(prm, True))
    elif isinstance(prm, ComplexData):
        elem.append(_encode_complex(prm, True))
    elif isinstance(prm, BoundingBoxData):
        elem.append(_encode_bbox(prm, True))
    return elem
Esempio n. 9
0
def encode_output_descr(prm):
    """ Encode process description Output element."""
    elem = NIL("Output", *_encode_param_common(prm))
    if isinstance(prm, LiteralData):
        elem.append(_encode_literal(prm, False))
    elif isinstance(prm, ComplexData):
        elem.append(_encode_complex(prm, False))
    elif isinstance(prm, BoundingBoxData):
        elem.append(_encode_bbox(prm, False))
    return elem
Esempio n. 10
0
def encode_input_descr(prm):
    """ Encode process description Input element."""
    # Request input parameters are not visible from the process description.
    if isinstance(prm, RequestParameter):
        return None
    elem = NIL("Input", *_encode_param_common(prm))
    elem.attrib["minOccurs"] = ("1", "0")[bool(prm.is_optional)]
    elem.attrib["maxOccurs"] = "1"
    if isinstance(prm, LiteralData):
        elem.append(_encode_literal(prm, True))
    elif isinstance(prm, ComplexData):
        elem.append(_encode_complex(prm, True))
    elif isinstance(prm, BoundingBoxData):
        elem.append(_encode_bbox(prm, True))
    return elem
Esempio n. 11
0
def encode_output_descr(prm):
    """ Encode process description Output element."""
    elem = NIL("Output", *_encode_param_common(prm))
    if isinstance(prm, LiteralData):
        elem.append(_encode_literal(prm, False))
    elif isinstance(prm, ComplexData):
        elem.append(_encode_complex(prm, False))
    elif isinstance(prm, BoundingBoxData):
        elem.append(_encode_bbox(prm, False))
    return elem
Esempio n. 12
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
Esempio n. 13
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