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 path raises urllib.error.URLError.

  • encoding – File text encoding. See open() for details. Defaults to request.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 classes metadata from configured paths.

This method attempts to load metadata from the path specified in metadata.paths.classes, falling back to metadata.fallbacks.classes if necessary.

Parameters:

decode – If True, return parsed JSON data; otherwise, return raw response. Defaults to True.

classmethod font(decode: bool = True) dict[str, Any] | str | None[source]

Retrieve font metadata from configured paths.

This method attempts to load metadata from the path specified in the metadata.paths.font, falling back to metadata.fallbacks.font if necessary.

Parameters:

decode – If True, return parsed JSON data; otherwise, return raw response. Defaults to True.

classmethod glyphnames(decode: bool = True) dict[str, Any] | str | None[source]

Retrieve glyphnames metadata from configured paths.

This method attempts to load metadata from the path specified in metadata.paths.glyphnames, falling back to metadata.fallbacks.glyphnames if necessary.

Parameters:

decode – If True, return parsed JSON data; otherwise, return raw response. Defaults to True.

json() dict[str, Any] | None[source]

Parse request as JSON.

Raises:
classmethod ranges(decode: bool = True) dict[str, Any] | str | None[source]

Retrieve ranges metadata from configured paths.

This method attempts to load metadata from the path specified in metadata.paths.ranges, falling back to metadata.fallbacks.ranges if necessary.

Parameters:

decode – If True, return parsed JSON data; otherwise, return raw response. Defaults to True.

property content: bytes | None

The raw response data as bytes.

This property is read-only.

property encoding: str

File text encoding.

property fallback: str | None

Fallback URL or filepath as string.

Raises:

TypeError – If the fallback path cannot be normalized.

property path: str | None

Primary URL or filepath as string.

Raises:

TypeError – If the path cannot be normalized.

property text: str | None

The raw response data as text.

This property is read-only.

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 to request.encoding.

Raises:
  • TypeError – If filepath is not the expected type.

  • ValueError – If there is an error serializing the JSON data or if filepath does not have a .json exctension.

  • FileNotFoundError – If the specified filepath cannot be found.

  • OSError – If there are any issues opening or writing to the file.

  • UnsupportedOperation – If the operation is not supported.