weaver.formats¶
Module Contents¶
-
weaver.formats.get_format(mime_type: str, default: Optional[str] = None) → pywps.inout.formats.Format[source]¶ Obtains a
Formatwith predefined extension and encoding details from known MIME-types.
-
weaver.formats.get_extension(mime_type: str) → str[source]¶ Retrieves the extension corresponding to
mime_typeif explicitly defined, or by parsing it.
-
weaver.formats.get_cwl_file_format(mime_type: str, make_reference: bool = False, must_exist: bool = True, allow_synonym: bool = True) → Union[Tuple[Optional[JSON], Optional[str]], Optional[str]][source]¶ Obtains the corresponding IANA/EDAM
formatvalue to be applied under a CWL I/OFilefrom themime_type(Content-Type header) using the first matched one.Lookup procedure is as follows:
- If
make_reference=False: - If there is a match, returns
tuple({<namespace-name: namespace-url>}, <format>)with: corresponding namespace mapping to be applied under
$namespacesin the CWL.value of
formatadjusted according to the namespace to be applied toFilein the CWL.
- If there is a match, returns
If there is no match but
must_exist=False, returns a literal and non-existing definition astuple({"iana": <iana-url>}, <format>).If there is no match but
must_exist=TrueANDallow_synonym=True, retry the call with the synonym if available, or move to next step. Skip this step ifallow_synonym=False.Otherwise, returns
(None, None)
- If
- If
make_reference=True: If there is a match, returns the explicit format reference as
<namespace-url>/<format>.If there is no match but
must_exist=False, returns the literal reference as<iana-url>/<format>(N.B.: literal non-official MIME-type reference will be returned even if an official synonym exists).If there is no match but
must_exist=TrueANDallow_synonym=True, retry the call with the synonym if available, or move to next step. Skip this step ifallow_synonym=False.Returns a single
Noneas there is not match (directly or synonym).
- If
- Note:
In situations where
must_exist=Falseis used and that the namespace and/or full format URL cannot be resolved to an existing reference, CWL will raise a validation error as it cannot confirm theformat. You must therefore make sure that the returned reference (or a synonym format) really exists when usingmust_exist=Falsebefore providing it to the CWL I/O definition. Settingmust_exist=Falseshould be used only for literal string comparison or pre-processing steps to evaluate formats.
- Parameters
mime_type – Some reference, namespace’d or literal (possibly extended) MIME-type string.
make_reference – Construct the full URL reference to the resolved MIME-type. Otherwise return tuple details.
must_exist – Return result only if it can be resolved to an official MIME-type (or synonym if enabled), otherwise
None. Non-official MIME-type can be enforced if disabled, in which case IANA namespace/URL is used as it preserves the original<type>/<subtype>format.allow_synonym – Allow resolution of non-official MIME-type to an official MIME-type synonym if available. Types defined as synonym have semantically the same format validation/resolution for CWL. Requires
must_exist=True, otherwise the non-official MIME-type is employed directly as result.
- Returns
Resolved MIME-type format for CWL usage, accordingly to specified arguments (see description details).
-
weaver.formats.clean_mime_type_format(mime_type: str, suffix_subtype: bool = False, strip_parameters: bool = False) → str[source]¶ Removes any additional namespace key or URL from
mime_typeso that it corresponds to the generic representation (e.g.:application/json) instead of the<namespace-name>:<format>mapping variant used in CWL->inputs/outputs->File->format or the complete URL reference.According to provided arguments, it also cleans up additional parameters or extracts sub-type suffixes.
- Parameters
mime_type – MIME-type, full URL to MIME-type or namespace-formatted string that must be cleaned up.
suffix_subtype – Remove additional sub-type specializations details separated by
+symbol such that an explicit format likeapplication/vnd.api+jsonreturns only its most basic suffix format defined as``application/json``.strip_parameters – Removes additional MIME-type parameters such that only the leading part defining the
type/subtypeare returned. For example, this will get rid of; charset=UTF-8or; version=4.0parameters.
Note
Parameters
suffix_subtypeandstrip_parametersare not necessarily exclusive.