topmark.registry.filetypes¶
topmark / registry / filetypes
Advanced public registry for file type definitions.
This module exposes read-oriented views and limited mutation hooks for the
composed file type registry used by TopMark. Most callers should prefer the
stable facade in topmark.registry.registry.Registry;
this module primarily serves advanced integrations, plugins, and tests.
Notes
- Public views such as
as_mapping_by_local_key()anditer_meta_by_local_key()expose the local-key compatibility view, whileas_mapping()anditer_meta()expose the canonical qualified-key view. register()andunregister()apply overlay-only changes; they do not mutate the base registry built bytopmark.filetypes.instances.- Overlay state is process-local and guarded by an
RLock.
FileTypeRegistry ¶
Composed registry view for file type definitions.
Notes
- Only validated
FileTypeinstances are admitted to the effective registry. - Mutation hooks are intended for plugin authors and test scaffolding. Most integrations should consume metadata and read-only views instead.
names
classmethod
¶
Return all registered file type names (sorted).
Returns:
| Type | Description |
|---|---|
tuple[str, ...]
|
Tuple with sorted file type names. |
Source code in src/topmark/registry/filetypes.py
qualified_keys
classmethod
¶
Return the qualified keys of all registered file types (sorted).
TODO: define a stable and sensible "prioritized" sort helper (builtins lowest precedence).
Returns:
| Type | Description |
|---|---|
tuple[str, ...]
|
Tuple with sorted file type qualified keys. |
Source code in src/topmark/registry/filetypes.py
namespaces
classmethod
¶
Return the namespaces of all registered file types (sorted).
TODO: define a stable and sensible "prioritized" sort helper (builtins lowest precedence).
Returns:
| Type | Description |
|---|---|
tuple[str, ...]
|
Tuple with sorted file type namepaces. |
Source code in src/topmark/registry/filetypes.py
resolve_filetype_id
classmethod
¶
Resolve a file type identifier to a FileType instance.
This helper supports both unqualified and qualified identifiers:
- Unqualified:
"<local_key>" - Qualified:
"<namespace>:<local_key>"
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_type_id
|
str
|
Identifier to resolve (unqualified or qualified). |
required |
default_namespace
|
str | None
|
Optional namespace constraint applied when the identifier is unqualified. |
None
|
Returns:
| Type | Description |
|---|---|
FileType | None
|
The resolved |
Raises:
| Type | Description |
|---|---|
AmbiguousFileTypeIdentifierError
|
If an unqualified identifier would match multiple file types in the composed registry. |
InvalidRegistryIdentityError
|
If registration is attempted with an invalid registry identifier. |
Notes
The composed registry is still keyed by unqualified file type local_key for
compatibility, but this resolver treats namespace:local_key as the canonical stable
identity and is the preferred lookup entry point for namespace-aware code.
Source code in src/topmark/registry/filetypes.py
get
classmethod
¶
Return a file type by qualified key.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_type_key
|
str
|
Qualified key used as the registry key. |
required |
Returns:
| Type | Description |
|---|---|
FileType | None
|
The file type if found, else None. |
Source code in src/topmark/registry/filetypes.py
as_mapping_by_local_key
classmethod
¶
Return the read-only local-key compatibility view of file types.
Returns:
| Type | Description |
|---|---|
Mapping[str, FileType]
|
Mapping of file type local key to |
Notes
The returned mapping is a MappingProxyType and must not be mutated.
Source code in src/topmark/registry/filetypes.py
as_mapping
classmethod
¶
Return the read-only qualified-key canonical view of file types.
Returns:
| Type | Description |
|---|---|
Mapping[str, FileType]
|
Mapping of file type qualified key to |
Notes
The returned mapping is a MappingProxyType and must not be mutated.
Source code in src/topmark/registry/filetypes.py
iter_meta_by_local_key
classmethod
¶
Iterate stable metadata for the local-key compatibility view.
No getattr needed because types are guaranteed.
Yields:
| Type | Description |
|---|---|
FileTypeMeta
|
Serializable |
Source code in src/topmark/registry/filetypes.py
iter_meta
classmethod
¶
Iterate stable metadata for the qualified-key canonical view.
No getattr needed because types are guaranteed.
Yields:
| Type | Description |
|---|---|
FileTypeMeta
|
Serializable |
Source code in src/topmark/registry/filetypes.py
register
classmethod
¶
Register a new file type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ft_obj
|
FileType
|
A |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Notes
- This mutates global registry state. Prefer temporary usage in tests with try/finally to ensure cleanup.
- Thread safe via RLock; process-global state; do not mutate in long-lived multi-tenant processes.
Source code in src/topmark/registry/filetypes.py
unregister_by_local_key
classmethod
¶
Unregister a file type by unqualified local key.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
local_key
|
str
|
Registered file type local_key. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
|
Notes
- This mutates global registry state.
- Thread safe via RLock; process-global state; do not mutate in long-lived multi-tenant processes.
Source code in src/topmark/registry/filetypes.py
unregister
classmethod
¶
Unregister a file type by qualified key.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_type_key
|
str
|
Registered file type qualified key. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
|
Notes
- This mutates global registry state.
- Thread safe via RLock; process-global state; do not mutate in long-lived multi-tenant processes.