fireman.load#
Feed data in through resources and sources.
- exception fireman.load.DuplicateKeyError(messages)#
A mapping repeats a key.
- messages#
One line per repeat, e.g.
line 12: duplicate key 'rules'.
- class fireman.load.Extracted(items, problems)#
Result of
Resource.extract.- items#
Surviving
(index, item)pairs, with their original positions.
- exception fireman.load.LoadError(problems)#
Raised when input cannot be loaded.
- problems#
Everything that went wrong.
- exception fireman.load.NestingError#
The input is nested too deeply to parse.
- class fireman.load.Resource(name, fn, schema=None, maps=(), firewall=None, policy=None, paths=())#
Items of one kind, checked against an optional schema and reshaped by converters.
A missing or wrong scope is allowed here, so
scopedcan fix it later;Pipeline.loadreports what is left throughscope_problem.- name#
What the items are.
- Type:
- schema#
Describes the raw data, if given. It is the user’s, not fireman’s.
- scope_problem()#
What is wrong with the scope, or
None: rules need a firewall and a policy, objects no policy.
- add_map(fn)#
Return a new resource with
fnadded after the existing converters.
- scoped(*, firewall=None, policy=None)#
Return a new resource with this firewall and policy, for scopes found in the data.
The result is not checked until
Pipeline.load.
- reads(*paths)#
Return a new resource that also lists
pathsas files it reads (repeats are dropped).
- extract()#
Run every raw item through the schema and converters.
Bad items are skipped and reported. If the generator itself fails (a missing file, say), what it yielded so far is kept and one problem without an index is recorded. Other exceptions propagate, since they are bugs.
- class fireman.load.Source(resources)#
Resources that belong together. Several may share a name; all are kept, in order.
- fireman.load.csv_file(path, name, *, schema=None, firewall=None, policy=None, delimiter=',', encoding='utf-8-sig')#
Yield the rows of a CSV file as
dict[str, str], read lazily.Cells are strings, so a schema or converter is expected. The default
utf-8-sigreads plain UTF-8 and drops the byte order mark Excel adds. A missing or unreadable file becomes a problem when the resource is extracted. The file is listed inpaths, so a later change to it is noticed.
- fireman.load.file_source(path)#
Read a YAML or JSON file, chosen by its suffix.
- fireman.load.json_file(path)#
Read a JSON file, laid out like the YAML one.
- fireman.load.load_json(text)#
Parse JSON, rejecting repeated keys (JSON gives no line for them).
- Raises:
DuplicateKeyError – With every repeated key.
NestingError – If the text is nested too deeply.
JSONDecodeError – If the text is not valid JSON.
- fireman.load.load_yaml(text)#
Parse YAML like
yaml.safe_load, but reject repeated keys.- Raises:
DuplicateKeyError – With every repeated key and its line.
NestingError – If the text is nested too deeply.
yaml.YAMLError – If the text is not valid YAML.
- fireman.load.resource(name, *, schema=None, firewall=None, policy=None)#
Turn a function yielding items into one that returns a
Resource.
- fireman.load.source(f)#
Turn a function returning resources into one that returns a
Source.
- fireman.load.yaml_file(path)#
Read a YAML file: global objects plus
firewallswith their own objects andpolicies.
- fireman.load.resource.ResourceNameT#
Type alias.
Type aliases are created through the type statement:
type Alias = intIn this example, Alias and int will be treated equivalently by static type checkers.
At runtime, Alias is an instance of TypeAliasType. The __name__ attribute holds the name of the type alias. The value of the type alias is stored in the __value__ attribute. It is evaluated lazily, so the value is computed only if the attribute is accessed.
Type aliases can also be generic:
type ListOrSet[T] = list[T] | set[T]In this case, the type parameters of the alias are stored in the __type_params__ attribute.
See PEP 695 for more information.