Exemple #1
0
    def test_local_fn(self):
        nc, enc = utils.embed(self.nc, 'application/x-netcdf')
        assert isinstance(nc, six.binary_type)
        assert enc == 'base64'

        xml, enc = utils.embed(self.xml, 'text/xml')
        assert isinstance(xml, six.string_types)
        assert enc == 'utf-8'
Exemple #2
0
    def test_local_fn(self):
        nc, enc = utils.embed(self.nc, 'application/x-netcdf')
        assert isinstance(nc, six.binary_type)
        assert enc == 'base64'

        xml, enc = utils.embed(self.xml, 'text/xml')
        assert isinstance(xml, six.string_types)
        assert enc == 'utf-8'
Exemple #3
0
    def test_local_fn(self):
        nc, enc = utils.embed(self.nc, 'application/x-netcdf')
        assert isinstance(nc, bytes)
        assert enc == 'base64'

        xml, enc = utils.embed(self.xml, 'text/xml')
        assert isinstance(xml, str)
        assert enc == 'utf-8'
Exemple #4
0
    def test_local_fn(self):  # noqa: D102
        nc, enc = utils.embed(self.nc, "application/x-netcdf")
        assert isinstance(nc, bytes)
        assert enc == "base64"

        xml, enc = utils.embed(self.xml, "text/xml")
        assert isinstance(xml, str)
        assert enc == "utf-8"
Exemple #5
0
    def _execute(self, pid, **kwargs):
        """Execute the process."""
        wps_inputs = []
        for name, input_param in self._inputs[pid].items():
            value = kwargs.get(sanitize(name))
            if value is not None:
                if isinstance(input_param.defaultValue, ComplexData):
                    encoding = input_param.defaultValue.encoding
                    mimetype = input_param.defaultValue.mimeType

                    if isinstance(value, ComplexData):
                        inp = value

                    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(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))

        wps_outputs = [
            (o.identifier, "ComplexData" in o.dataType)
            for o in self._outputs[pid].values()
        ]

        mode = self._mode if self._processes[pid].storeSupported else SYNC

        try:
            wps_response = self._wps.execute(
                pid, inputs=wps_inputs, output=wps_outputs, mode=mode
            )

            if self._interactive and self._processes[pid].statusSupported:
                if self._notebook:
                    notebook.monitor(wps_response, sleep=.2)
                else:
                    self._console_monitor(wps_response)

        except ServiceException as e:
            if "AccessForbidden" in str(e):
                raise UnauthorizedException(
                    "You are not authorized to do a request of type: Execute"
                )
            raise

        # Add the convenience methods of WPSResult to the WPSExecution class. This adds a `get` method.
        utils.extend_instance(wps_response, WPSResult)
        wps_response.attach(wps_outputs=self._outputs[pid], converters=self._converters)
        return wps_response
Exemple #6
0
    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
Exemple #7
0
 def test_str(self):  # noqa: D102
     s = "just a string"
     assert utils.embed(s) == (s, "utf-8")
Exemple #8
0
 def test_file(self):
     with open(self.nc, 'rb') as fp:
         nc, enc = utils.embed(fp, 'application/x-netcdf')
         assert isinstance(nc, six.binary_type)
Exemple #9
0
    def test_path(self):
        p = Path(self.nc)

        nc, enc = utils.embed(p, 'application/x-netcdf')
        assert isinstance(nc, six.binary_type)
Exemple #10
0
 def test_local_uri(self):
     xml, enc = utils.embed('file://' + self.xml, 'text/xml')
     assert isinstance(xml, six.string_types)
Exemple #11
0
    def test_path(self):  # noqa: D102
        p = Path(self.nc)

        nc, enc = utils.embed(p, "application/x-netcdf")
        assert isinstance(nc, bytes)
Exemple #12
0
 def test_file(self):
     with open(self.nc, 'rb') as fp:
         nc, enc = utils.embed(fp, 'application/x-netcdf')
         assert isinstance(nc, six.binary_type)
Exemple #13
0
    def test_path(self):
        p = Path(self.nc)

        nc, enc = utils.embed(p, 'application/x-netcdf')
        assert isinstance(nc, six.binary_type)
Exemple #14
0
 def test_local_uri(self):
     xml, enc = utils.embed('file://' + self.xml, 'text/xml')
     assert isinstance(xml, six.string_types)
Exemple #15
0
    def _execute(self, pid, **kwargs):
        """Execute the process."""
        wps_inputs = []
        for name, input_param in self._inputs[pid].items():
            value = kwargs.get(sanitize(name))
            if value is not None:
                if isinstance(input_param.defaultValue, ComplexData):
                    encoding = input_param.defaultValue.encoding
                    mimetype = input_param.defaultValue.mimeType

                    if isinstance(value, ComplexData):
                        inp = value

                    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(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))

        wps_outputs = [(o.identifier, "ComplexData" in o.dataType)
                       for o in self._outputs[pid].values()]

        mode = self._mode if self._processes[pid].storeSupported else SYNC

        try:
            wps_response = self._wps.execute(pid,
                                             inputs=wps_inputs,
                                             output=wps_outputs,
                                             mode=mode)

            if self._interactive and self._processes[pid].statusSupported:
                if self._notebook:
                    notebook.monitor(wps_response, sleep=.2)
                else:
                    self._console_monitor(wps_response)

        except ServiceException as e:
            if "AccessForbidden" in str(e):
                raise UnauthorizedException(
                    "You are not authorized to do a request of type: Execute")
            raise

        # Add the convenience methods of WPSResult to the WPSExecution class. This adds a `get` method.
        utils.extend_instance(wps_response, WPSResult)
        wps_response.attach(wps_outputs=self._outputs[pid],
                            converters=self._converters)
        return wps_response
Exemple #16
0
 def test_local_uri(self):  # noqa: D102
     xml, enc = utils.embed("file://" + self.xml, "text/xml")
     assert isinstance(xml, str)
Exemple #17
0
 def test_str(self):
     s = 'just a string'
     assert utils.embed(s) == (s, 'utf-8')
Exemple #18
0
 def test_file(self):  # noqa: D102
     with open(self.nc, "rb") as fp:
         nc, enc = utils.embed(fp, "application/x-netcdf")
         assert isinstance(nc, bytes)
Exemple #19
0
 def test_str(self):
     s = 'just a string'
     assert utils.embed(s) == (s, 'utf-8')