prance.util.formats¶
This submodule contains file format related utility code for Prance.
Exceptions¶
Functions¶
- prance.util.formats.format_info(format_name)[source]¶
Return content type and extension for a supported format.
Valid formats are YAML or JSON.
- Parameters
format_name (str) – The name of the format.
- Returns
The preferred content type and file name extension, or (None, None) if the format name is not supported.
- Return type
tuple
- prance.util.formats.parse_spec(spec_str, filename=None, **kwargs)[source]¶
Return a parsed dict of the given spec string.
The function exists for legacy reasons and just wraps parse_spec_details, returning only the parsed specs.
- Parameters
spec_str (str) – The specifications as string.
filename (str) – [optional] Filename to determine the format from.
content_type (str) – [optional] Content type to determine the format from.
- Returns
The specifications.
- Return type
dict
- Raises
ParseError – when parsing fails.
- prance.util.formats.parse_spec_details(spec_str, filename=None, **kwargs)[source]¶
Return a parsed dict of the given spec string.
Also returned are the detected mime type and file name extension.
The default format is assumed to be JSON, but if you provide a filename, its extension is used to determine whether YAML or JSON should be parsed.
- Parameters
spec_str (str) – The specifications as string.
filename (str) – [optional] Filename to determine the format from.
content_type (str) – [optional] Content type to determine the format from.
- Returns
The specifications, mime type, and extension.
- Return type
tuple
- Raises
ParseError – when parsing fails.
- prance.util.formats.serialize_spec(specs, filename=None, **kwargs)[source]¶
Return a serialized version of the given spec.
The default format is assumed to be JSON, but if you provide a filename, its extension is used to determine whether YAML or JSON should be parsed.
- Parameters
specs (dict) – The specifications as dict.
filename (str) – [optional] Filename to determine the format from.
content_type (str) – [optional] Content type to determine the format from.
- Returns
The serialized specifications.
- Return type
str