Metadata Requests
In SMufoLib, web requests and metadata file operations are handled in
the request module. For maximum reliability and access
to updated data, the module facilitates simultanous URL and file system
requests, while simplifying reading, parsing and writing of JSON data.
- class Request(path=None, fallback=None, encoding=CONFIG['request']['encoding'], warn=CONFIG['request']['warn'])[source]
Send HTTP or filesystem request.
A fallback path (e.g., a filesystem path to the same file), may be specified in case of connection failure when the primary path is a URL.
An optional warning may be raised in the event of a fallback.
- Parameters:
path – Primary URL or filepath.
fallback – Fallback filepath to use if
pathraisesurllib.error.URLError.encoding – File text encoding. See
open()for details. Defaults torequest.encoding.warn – Warn if URLError is raised before fallback request. Defaults to
request.warn.
- classmethod classes(decode: bool = True) dict[str, Any] | str | None[source]
Retrieve
classesmetadata from configured paths.This method attempts to load metadata from the path specified in
metadata.paths.classes, falling back tometadata.fallbacks.classesif necessary.
- classmethod font(decode: bool = True) dict[str, Any] | str | None[source]
Retrieve
fontmetadata from configured paths.This method attempts to load metadata from the path specified in the
metadata.paths.font, falling back tometadata.fallbacks.fontif necessary.
- classmethod glyphnames(decode: bool = True) dict[str, Any] | str | None[source]
Retrieve
glyphnamesmetadata from configured paths.This method attempts to load metadata from the path specified in
metadata.paths.glyphnames, falling back tometadata.fallbacks.glyphnamesif necessary.
- json() dict[str, Any] | None[source]
Parse request as JSON.
- Raises:
json.JSONDecodeError – If the response cannot be parsed as JSON.
TypeError – If the raw data is None.
- classmethod ranges(decode: bool = True) dict[str, Any] | str | None[source]
Retrieve
rangesmetadata from configured paths.This method attempts to load metadata from the path specified in
metadata.paths.ranges, falling back tometadata.fallbacks.rangesif necessary.
- property fallback: str | None
Fallback URL or filepath as string.
- Raises:
TypeError – If the fallback path cannot be normalized.
- writeJson(filepath, source, encoding=CONFIG['request']['encoding'])[source]
Writes JSON data to filepath.
- Parameters:
filepath – Path to target file.
source – JSON data source.
encoding – File text encoding. See
open()for details. Defaults torequest.encoding.
- Raises:
TypeError – If
filepathis not the expected type.ValueError – If there is an error serializing the JSON data or if
filepathdoes not have a.jsonexctension.FileNotFoundError – If the specified
filepathcannot be found.OSError – If there are any issues opening or writing to the file.
UnsupportedOperation – If the operation is not supported.