コード例 #1
0
    def test_file_like(self):
        import io
        f = io.StringIO()
        f.write(u"just a string")
        f.seek(0)

        assert is_embedded_in_request(self.remote, f)
        assert is_embedded_in_request(self.local, f)
コード例 #2
0
ファイル: base.py プロジェクト: bird-house/birdy
    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
コード例 #3
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
コード例 #4
0
ファイル: test_client.py プロジェクト: bird-house/birdy
 def test_url(self):  # noqa: D102
     assert not is_embedded_in_request(self.remote, self.url)
     assert not is_embedded_in_request(self.local, self.url)
コード例 #5
0
ファイル: test_client.py プロジェクト: bird-house/birdy
 def test_local_path(self):  # noqa: D102
     assert is_embedded_in_request(self.remote, self.path)
     assert not is_embedded_in_request(self.local, self.path)
コード例 #6
0
ファイル: test_client.py プロジェクト: bird-house/birdy
 def test_string(self):  # noqa: D102
     assert is_embedded_in_request(self.remote, "just a string")
     assert is_embedded_in_request(self.local, "just a string")
コード例 #7
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
コード例 #8
0
ファイル: test_client.py プロジェクト: bird-house/birdy
 def test_url(self):
     assert not is_embedded_in_request(self.remote, self.url)
     assert not is_embedded_in_request(self.local, self.url)
コード例 #9
0
 def test_local_uri(self):
     assert is_embedded_in_request(self.remote, self.uri)
     assert not is_embedded_in_request(self.local, self.uri)
コード例 #10
0
ファイル: test_client.py プロジェクト: bird-house/birdy
 def test_local_path(self):
     assert is_embedded_in_request(self.remote, self.path)
     assert not is_embedded_in_request(self.local, self.path)
コード例 #11
0
 def test_local_fn(self):
     assert is_embedded_in_request(self.remote, self.fn)
     assert not is_embedded_in_request(self.local, self.fn)
コード例 #12
0
 def test_string(self):
     assert is_embedded_in_request(self.remote, 'just a string')
     assert is_embedded_in_request(self.local, 'just a string')