Module Contents

weaver.wps.utils._get_settings_or_wps_config(container: weaver.typedefs.AnySettingsContainer, weaver_setting_name: str, config_setting_section: str, config_setting_name: str, default_not_found: str, message_not_found: str, load: bool = False) str[source]
weaver.wps.utils.get_wps_path(container: weaver.typedefs.AnySettingsContainer, load: bool = True) str[source]

Retrieves the WPS path (without hostname).

Searches directly in settings, then weaver.wps_cfg file, or finally, uses the default values if not found.

weaver.wps.utils.get_wps_url(container: weaver.typedefs.AnySettingsContainer, load: bool = True) str[source]

Retrieves the full WPS URL (hostname + WPS path).

Searches directly in settings, then weaver.wps_cfg file, or finally, uses the default values if not found.

weaver.wps.utils.get_wps_output_dir(container: weaver.typedefs.AnySettingsContainer, load: bool = True) str[source]

Retrieves the WPS output directory path where to write XML and result files.

Searches directly in settings, then weaver.wps_cfg file, or finally, uses the default values if not found.

weaver.wps.utils.get_wps_output_path(container: weaver.typedefs.AnySettingsContainer, load: bool = True) str[source]

Retrieves the WPS output path (without hostname) for staging XML status, logs and process outputs.

Searches directly in settings, then weaver.wps_cfg file, or finally, uses the default values if not found.

weaver.wps.utils.get_wps_output_url(container: weaver.typedefs.AnySettingsContainer, load: bool = True) str[source]

Retrieves the WPS output URL that maps to WPS output directory path.

Searches directly in settings, then weaver.wps_cfg file, or finally, uses the default values if not found.

weaver.wps.utils.get_wps_output_context(request: weaver.typedefs.AnyRequestType) str | None[source]

Obtains and validates allowed values for sub-directory context of WPS outputs in header X-WPS-Output-Context.


HTTPUnprocessableEntity – if the header was provided and contains invalid or illegal value.


validated context or None if not specified.

weaver.wps.utils.get_wps_local_status_location(url_status_location: str, container: weaver.typedefs.AnySettingsContainer, must_exist: bool = True) str | None[source]

Attempts to retrieve the local XML file path corresponding to the WPS status location as URL.

  • url_status_location – URL reference pointing to some WPS status location XML.

  • container – any settings container to map configured local paths.

  • must_exist – return only existing path if enabled, otherwise return the parsed value without validation.


found local file path if it exists, None otherwise.

weaver.wps.utils.map_wps_output_location(reference: str, container: weaver.typedefs.AnySettingsContainer, url: bool = False, exists: bool = True, file_scheme: bool = False) str | None[source]

Obtains the mapped WPS output location of a file where applicable.

  • reference – Local file path or file URL to be mapped.

  • container – Retrieve application settings.

  • url – Perform URL mapping (True: local path -> URL endpoint, False: URL endpoint -> local path).

  • exists – Ensure that the mapped file exists, otherwise don’t map it (otherwise None).

  • file_scheme – Ensure that the ‘file://’ scheme is applied to resulting local file location when mapped from WPS output URL. When in ‘reverse’ mode, ‘file://’ is always removed if present to form a potential local file path.


Mapped reference that corresponds to the local/URL WPS output location.

weaver.wps.utils._describe_process_cached(self: owslib.wps.WebProcessingService, identifier: str, xml: weaver.xml_util.XML | None = None) weaver.typedefs.ProcessOWS[source]
weaver.wps.utils._get_wps_client_cached(url: str, headers: weaver.typedefs.HeadersType, verify: bool, language: str | None) owslib.wps.WebProcessingService[source]
weaver.wps.utils.get_wps_client(url: str, container: weaver.typedefs.AnySettingsContainer | None = None, verify: bool = None, headers: weaver.typedefs.HeadersType | None = None, language: str | None = None) owslib.wps.WebProcessingService[source]

Obtains a WebProcessingService with pre-configured request options for the given URL.

  • url – WPS URL location.

  • container – request or settings container to retrieve headers and other request options.

  • verify – flag to enable SSL verification (overrides request options from container).

  • headers – specific headers to apply (overrides retrieved ones from container).

  • language – preferred response language if supported by the service.


created WPS client object with configured request options.

weaver.wps.utils.get_wps_client_filtered_headers(headers: weaver.typedefs.HeadersType | None, container: weaver.typedefs.AnySettingsContainer) weaver.typedefs.HeadersType[source]

Filters out any headers configured for the WPS client by the weaver.wps_client_headers_filter setting.

  • headers – Headers to filter as applicable.

  • container – Any settings container to retrieve application settings.


Filtered WPS headers.

weaver.wps.utils.check_wps_status(location: str | None = None, response: weaver.xml_util.XML | None = None, sleep_secs: int = 2, verify: bool = True, settings: weaver.typedefs.AnySettingsContainer | None = None) owslib.wps.WPSExecution[source]

Run owslib.wps.WPSExecution.checkStatus() with additional exception handling.

  • location – job URL or file path where to look for job status.

  • response – WPS response document of job status.

  • sleep_secs – number of seconds to sleep before returning control to the caller.

  • verify – flag to enable SSL verification.

  • settings – application settings to retrieve any additional request parameters as applicable.


OWSLib.wps.WPSExecution object.

weaver.wps.utils.get_exception_from_xml_status(xml: weaver.xml_util.XML | str) weaver.owsexceptions.OWSException | None[source]

Retrieves the OWS exception that corresponds to the XML status.

Expects the following XML status response structure (ows:Exception block can be at any level):

<ows:Exception exceptionCode="NoApplicableCode" locator="None">
  <ows:ExceptionText>Error message about the cause of the exception.</ows:ExceptionText>

xml – XML tree object with exception details.


Matched owsexceptions.OWSException. If no matching exception code is found within available exception classes, defaults to generic OWSException. If any parsing error occurs, returns nothing.

weaver.wps.utils.load_pywps_config(container: weaver.typedefs.AnySettingsContainer, config: str | Dict[str, str] | None = None) configparser.ConfigParser[source]

Loads and updates the PyWPS configuration using Weaver settings.

weaver.wps.utils.set_wps_language(wps: owslib.wps.WebProcessingService, accept_language: str | None = None, request: weaver.typedefs.AnyRequestType | None = None) str | None[source]

Applies the best match between requested accept languages and supported ones by the WPS server.

Given the Accept-Language header value, match the best language to the supported languages retrieved from WPS. By default, and if no match is found, sets WebProcessingService.language property to None.

See also

Details about the format of the Accept-Language header: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Accept-Language


This function considers quality-factor weighting and parsing resolution of Accept-Language header according to RFC 7231#section-5.3.2.

  • wps – service for which to apply a supported language if matched.

  • accept_language – value of the Accept-Language header.

  • request – request from which to extract Accept-Language header if not provided directly.


language that has been set, or None if no match could be found.