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'
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'
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"
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
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
def test_str(self): # noqa: D102 s = "just a string" assert utils.embed(s) == (s, "utf-8")
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)
def test_path(self): p = Path(self.nc) nc, enc = utils.embed(p, 'application/x-netcdf') assert isinstance(nc, six.binary_type)
def test_local_uri(self): xml, enc = utils.embed('file://' + self.xml, 'text/xml') assert isinstance(xml, six.string_types)
def test_path(self): # noqa: D102 p = Path(self.nc) nc, enc = utils.embed(p, "application/x-netcdf") assert isinstance(nc, bytes)
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
def test_local_uri(self): # noqa: D102 xml, enc = utils.embed("file://" + self.xml, "text/xml") assert isinstance(xml, str)
def test_str(self): s = 'just a string' assert utils.embed(s) == (s, 'utf-8')
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)