コード例 #1
0
    def test_nc(self):
        mime, enc = utils.guess_type(
            "https://remote.org/thredds/dodsC/a.nc",
            ["application/x-netcdf", "application/x-ogc-dods"])
        assert mime == "application/x-ogc-dods"

        mime, enc = utils.guess_type(
            "https://remote.org/thredds/file/a.nc",
            ["application/x-ogc-dods", "application/x-netcdf"])
        assert mime == "application/x-netcdf"
コード例 #2
0
    def test_zip(self):
        mime, enc = utils.guess_type("LSJ_LL.zip", [
            "application/gml+xml",
            "application/zip",
            "application/x-zipped-shp",
        ])
        assert mime == "application/zip"

        mime, enc = utils.guess_type("LSJ_LL.zip", [
            "application/gml+xml",
            "application/x-zipped-shp",
        ])
        assert mime == "application/x-zipped-shp"
コード例 #3
0
ファイル: test_utils.py プロジェクト: bird-house/birdy
    def test_path(self):  # noqa: D102
        from pathlib import Path

        mime, enc = utils.guess_type(Path("shape.json"),
                                     ["wrong", "application/geo+json"])
        assert mime == "application/geo+json"

        mime, enc = utils.guess_type(
            Path("data.nc"),
            ["application/x-ogc-dods", "application/x-netcdf"])
        assert mime == "application/x-netcdf"

        mime, enc = utils.guess_type(
            Path("file:///dodsC/data.nc"),
            ["application/x-netcdf", "application/x-ogc-dods"],
        )
        assert mime == "application/x-ogc-dods"
コード例 #4
0
ファイル: base.py プロジェクト: bird-house/birdy
    def _build_inputs(self, pid, **kwargs):
        """Build the input sequence from the function arguments."""
        wps_inputs = []
        for name, input_param in list(self._inputs[pid].items()):
            arg = kwargs.get(sanitize(name))
            if arg is None:
                continue

            values = (
                [
                    arg,
                ]
                if not isinstance(arg, (list, tuple))
                else arg
            )
            supported_mimetypes = [v.mimeType for v in input_param.supportedValues]

            for value in values:
                #  if input_param.dataType == "ComplexData": seems simpler
                if isinstance(input_param.defaultValue, ComplexData):

                    # Guess the mimetype of the input value
                    mimetype, encoding = guess_type(value, supported_mimetypes)

                    if encoding is None:
                        encoding = input_param.defaultValue.encoding

                    if isinstance(value, ComplexData):
                        inp = value

                    # Either embed the file content or just the reference.
                    else:
                        if utils.is_embedded_in_request(self._wps.url, value):
                            # If encoding is None, this will return the actual encoding used (utf-8 or base64).
                            value, encoding = embed(value, mimetype, encoding=encoding)
                        else:
                            value = fix_url(str(value))

                        inp = utils.to_owslib(
                            value,
                            data_type=input_param.dataType,
                            encoding=encoding,
                            mimetype=mimetype,
                        )

                else:
                    inp = utils.to_owslib(value, data_type=input_param.dataType)

                wps_inputs.append((name, inp))

        return wps_inputs