Firebird-uuid Reference¶
- firebird.uuid.ROOT_SPEC = 'https://raw.githubusercontent.com/FirebirdSQL/firebird-uuid/master/root.oid'¶
str(object=’’) -> str str(bytes_or_buffer[, encoding[, errors]]) -> str
Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.__str__() (if defined) or repr(object). encoding defaults to sys.getdefaultencoding(). errors defaults to ‘strict’.
URL for ROOT specification
- firebird.uuid.IANA_ROOT_NAME = 'iso.org.dod.internet.private.enterprise'¶
str(object=’’) -> str str(bytes_or_buffer[, encoding[, errors]]) -> str
Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.__str__() (if defined) or repr(object). encoding defaults to sys.getdefaultencoding(). errors defaults to ‘strict’.
IANA name before Firebird namespace. Does not contain trailing dot.
- firebird.uuid.oid_registry = OIDRegistry([])¶
A specialized registry for managing
OIDNodeobjects, keyed by their UUID.This class inherits from
firebird.base.collections.Registryand provides methods specifically tailored for handling the Firebird OID hierarchy. It allows populating the registry from parsed specification data or TOML documents, retrieves nodes (including the designated root node), triggers the linking of nodes into a tree structure viabuild_tree, and enables serializing the registry content back into TOML format.
- firebird.uuid.get_specification(url: str) str[source]¶
Fetches the text content of an OID specification from a URL.
Supports both HTTP(S) and local
file://URLs via a configuredrequests.Session.- Parameters:
url (str) – The URL (http, https, or file) of the OID specification YAML file.
- Returns:
The YAML text content of the specification.
- Raises:
requests.exceptions.RequestException – If a network or file access error occurs.
requests.exceptions.HTTPError – If an HTTP error response (e.g., 404) is received.
- Return type:
- firebird.uuid.get_specifications(root: str = 'https://raw.githubusercontent.com/FirebirdSQL/firebird-uuid/master/root.oid') tuple[dict[str, str], dict[str, Exception]][source]¶
Recursively fetches all OID YAML specifications starting from a root URL.
Traverses the tree of specifications by following ‘node-spec’ URLs found in child definitions. It collects the raw YAML text of successfully fetched specifications and records any exceptions encountered during fetching or initial YAML parsing (needed to find child URLs).
This function performs only minimal validation necessary to navigate the tree.
- Parameters:
root (str) – The URL of the root specification to start traversal from. Defaults to
ROOT_SPEC.- Returns:
spec_map:dict[str, str]mapping URL to successfully fetched YAML content (string).err_map:dict[str, Exception]mapping URL to the Exception encountered while trying to fetch or minimally parse that spec.
- Return type:
A tuple containing two dictionaries
- firebird.uuid.parse_specifications(specifications: dict[str, str]) tuple[dict[str, dict], dict[str, Exception]][source]¶
Parses, validates, and normalizes multiple OID YAML specifications.
Takes a dictionary of raw YAML specification strings (typically from
get_specifications), parses each string into a Python dictionary, validates its structure and content against the defined format, and normalizes keys (e.g., ‘node-spec’ to ‘node_spec’) usingpythonize_spec.- Parameters:
specifications (dict[str, str]) – A dictionary mapping specification URLs (str) to their raw YAML content (str).
- Returns:
data_map:dict[str, dict]mapping URL to the successfully parsed, validated, and key-normalized specification data (dictionary).err_map:dict[str, Exception]mapping URL to the Exception encountered during YAML parsing or validation for that spec.
- Return type:
A tuple containing two dictionaries
- class firebird.uuid.OIDNodeType(value)[source]¶
Bases:
EnumEnumeration of possible types for an
OIDNode.- LEAF = 'leaf'¶
A terminal node in the hierarchy; it cannot have children defined in a separate specification file.
- NODE = 'node'¶
An intermediate node that references another specification file (via
node_spec) to define its children.
- PRIVATE = 'private'¶
A node reserved for private use, similar to a LEAF in that it does not link to a separate specification file for children.
- ROOT = 'root'¶
The top-level node in a specific OID specification file. Only one true root (from IANA) exists in the full conceptual tree.
- class firebird.uuid.OIDNode(*, parent: OIDNode | None | Literal['None'] = None, oid: str | None = None, number: int | None = None, name: str | None = None, description: str | None = None, contact: str | None = None, email: str | None = None, site: str | None = None, parent_spec: str | None = None, node_spec: str | None = None, node_type: str | None = None)[source]¶
Bases:
DistinctRepresents a single node within the Firebird OID hierarchy.
Each node encapsulates information such as its Object Identifier (OID), name, description, contact details, and type. It maintains links to its parent (using a weak reference) and holds a list of its direct children.
Nodes are uniquely identified by a UUID (
uid) deterministically generated from their OID usinguuid.uuid5with theNAMESPACE_OID.- Parameters:
parent (OIDNode | None | Literal[NONE_VALUE]) – The parent
OIDNode. Stored as a weak reference.Nonefor the absolute root node of the entire hierarchy.oid (str | None) – The full OID string for this node. If
None, it’s constructed fromparent.oidandnumber. One ofoidor (parentandnumber) must be provided.number (int | None) – The node’s number relative to its parent. Used to construct the OID if
oidis not given.name (str | None) – Node name (e.g., ‘firebird’).
description (str | None) – Node description.
contact (str | None) – Contact person/entity name.
email (str | None) – Contact email address.
site (str | None) – URL associated with the node owner/maintainer.
parent_spec (str | None) – URL to the YAML specification of the parent node. If
None, it’s derived from theparentobject’snode_spec.node_spec (str | None) – URL to this node’s YAML specification file (if it’s a NODE type) or one of the keywords ‘leaf’ or ‘private’. Used to determine
node_typeifnode_typeargument is not provided.node_type (str | None) – Explicit node type (‘root’, ‘node’, ‘leaf’, ‘private’). If
None, it’s inferred fromnode_spec(‘leaf’/’private’ keywords or defaults to ‘node’ if it looks like a URL/path).
- Raises:
ValueError – If the OID cannot be determined (neither
oidnorparent`+`numberare sufficient).
- classmethod from_spec(spec_url: str, data: dict[str, Any], parent: OIDNode | None = None) OIDNode[source]¶
Creates a new OIDNode and its direct children from parsed specification data.
- Parameters:
spec_url (str) – The URL from which the specification
datawas loaded. Used as thenode_specfor the created node.data (dict[str, Any]) – Parsed and validated dictionary from an OID node specification document (typically after
pythonize_spec). Expected keys: ‘node’ (dict for the main node), ‘children’ (list of dicts).parent (OIDNode | None) – The parent node for the node being created (if applicable).
- Returns:
The newly created
OIDNodeinstance representing the root of the specification defined indata, with itschildrenlist populated.- Return type:
- as_toml_dict() dict[str, Any][source]¶
Returns node data as a dictionary suitable for TOML serialization.
Parent is represented by its UUID string. Uses the original
oidif provided directly, otherwise relies on the potentially calculatedoid. Node type is represented by the original string (__node_type) if provided, otherwise potentially derived.node_specfor LEAF/PRIVATE is output as the type keyword (‘leaf’/’private’).
- set_parent(parent: OIDNode | None) None[source]¶
Sets or updates the parent node and related attributes.
Establishes a weak reference to the new parent. If the node’s
numberis set, it recalculates the node’soidbased on the new parent’s OID. It also updatesparent_specfrom the new parent’snode_spec.Important
This method ONLY updates the child (
self). It does NOT modify the old or new parent’schildrenlist. Tree modifications should be handled externally (e.g., bybuild_tree).
- property full_name: str¶
Returns the fully qualified node name, starting from the root.
Example: ‘iso.org.dod.internet.private.enterprise.firebird.subsytem’. Returns just the node’s
nameif it has no parent.
- node_type: OIDNodeType | None¶
Node type (enum member)
- class firebird.uuid.OIDRegistry(data: Mapping[Any, Distinct] | Sequence[Distinct] | Registry = None)[source]¶
Bases:
RegistryA specialized registry for managing
OIDNodeobjects, keyed by their UUID.This class inherits from
firebird.base.collections.Registryand provides methods specifically tailored for handling the Firebird OID hierarchy. It allows populating the registry from parsed specification data or TOML documents, retrieves nodes (including the designated root node), triggers the linking of nodes into a tree structure viabuild_tree, and enables serializing the registry content back into TOML format.- Parameters:
data (Mapping[Any, Distinct] | Sequence[Distinct] | Registry)
- as_toml() str[source]¶
Serializes the entire registry content into a TOML formatted string.
Iterates through all
OIDNodeobjects currently held in the registry. For each node, it calls itsas_toml_dict()method to get a TOML- compatible dictionary representation.The final output is a single TOML string where the top level is a table (dictionary) mapping node UUID strings to their corresponding attribute dictionaries.
- Returns:
A string containing the TOML representation of the registry’s nodes. An empty string if registry is empty.
- Return type:
- get_root() OIDNode | None[source]¶
Retrieves the root node of the OID hierarchy from the registry.
Searches the registered nodes for the unique node whose
node_typeattribute isOIDNodeType.ROOT.
- update_from_specifications(specifications: dict[str, dict[str, Any]]) None[source]¶
Populates or updates the registry from parsed OID specification data.
Processes a dictionary where keys are specification URLs and values are the corresponding parsed/validated/pythonized specification data. For each specification, it instantiates
OIDNodeobjects for both the main node defined in the spec (‘node’ key) and all its listed children (‘children’ key). All created nodes are added or updated in the registry using their UUIDs as keys.After processing all specifications, it calls
build_treeon the registry’s current contents to link the nodes into a hierarchical structure based onnode_specreferences and parent relationships.
- update_from_toml(toml_data: str) None[source]¶
Updates the registry by loading node data from a TOML document string.
Parses the TOML string, which is expected to contain a dictionary mapping node UUID strings to dictionaries of node attributes (as produced by the
as_tomlmethod).Performs validation checks before loading:
Ensures the TOML data either defines a root node (node_type=’root’ and no ‘parent’) or contains at least one node whose parent UUID already exists in the current registry.
If a root node is defined in the TOML and a root node is already registered, verifies that their UUIDs match.
Nodes are then instantiated and added to the registry iteratively. A queue is used to handle dependencies: if a node’s parent hasn’t been loaded yet, the node is re-queued until its parent becomes available.
After all nodes from the TOML are successfully loaded and registered,
build_treeis called on the registry’s contents to reconstruct the full node hierarchy.- Parameters:
toml_data (str) – A string containing the TOML document representation of the OID nodes to load.
- Raises:
Error – If validation fails (e.g., no linkable starting node, root UUID mismatch, unresolvable parent dependencies after attempting to load all nodes).
toml.TOMLDecodeError – If the
toml_datastring is not valid TOML.uuid.ValueError – If a UUID string key or parent value in the TOML is malformed.
KeyError – If essential keys like ‘node_type’ are missing in the TOML data for a node.
- Return type:
None