module documentation

URN parsing and project-name mapping utilities.

Function get_id_from_urn Extract the trailing identifier from a URN.
Function get_project_from_urn Extract the project name from a URN.
Function get_type_from_urn Extract the type segment from a URN.
Function is_platform_urn Check whether urn is in a DataGraphs platform namespace.
Function is_valid_urn Check whether urn matches the RFC 2141 URN syntax.
Function map_project_name Recursively replace a URN prefix in all string values of obj.
Function rewrite_urns_for_project Recursively rewrite URNs in obj to match the target project.
Constant _PLATFORM_URN_NAMESPACES Undocumented
Constant _URN_PATTERN Undocumented
def get_id_from_urn(urn: str) -> str:

Extract the trailing identifier from a URN.

Returns the segment after the last colon.

Parameters
urn:strA valid URN string.
Returns
strThe identifier.
Raises
ValueErrorIf urn is not a valid URN.
def get_project_from_urn(urn: str) -> str:

Extract the project name from a URN.

Returns the segment between the first and second colons.

Parameters
urn:strA valid URN string.
Returns
strThe project name.
Raises
ValueErrorIf urn is not a valid URN.
def get_type_from_urn(urn: str) -> str:

Extract the type segment from a URN.

Returns the segment between the second and last colons.

Parameters
urn:strA valid URN string.
Returns
strThe type segment.
Raises
ValueErrorIf urn is not a valid URN.
def is_platform_urn(urn: str) -> bool:

Check whether urn is in a DataGraphs platform namespace.

Only the namespace is inspected (case-insensitively, as RFC 2141 requires): use is_valid_urn to check the URN as a whole.

Parameters
urn:strThe string to test.
Returns
boolTrue if urn starts urn:datagraphs: or urn:models:.
def is_valid_urn(urn: str) -> bool:

Check whether urn matches the RFC 2141 URN syntax.

Parameters
urn:strThe string to test.
Returns
boolTrue if urn is a valid URN.
def map_project_name(obj: dict | list | str | Any, from_urn: str, to_urn: str) -> dict | list | str | Any:

Recursively replace a URN prefix in all string values of obj.

Parameters
obj:dict | list | str | AnyThe object to process (dict, list, str, or other).
from_urn:strURN prefix to replace.
to_urn:strReplacement URN prefix.
Returns
dict | list | str | AnyA copy of obj with URN prefixes replaced.
def rewrite_urns_for_project(obj: dict | list | str | Any, project_name: str) -> dict | list | str | Any:

Recursively rewrite URNs in obj to match the target project.

Every valid URN string has its project segment (between the first and second colons) replaced with project_name, so urn:my-test:path1:id1 becomes urn:<project_name>:path1:id1. Platform URNs (see is_platform_urn) and non-URN strings are left as-is.

Parameters
obj:dict | list | str | AnyThe object to process (dict, list, str, or other).
project_name:strThe project name to write into each URN.
Returns
dict | list | str | AnyA copy of obj with URNs rewritten to the target project.
_PLATFORM_URN_NAMESPACES =

Undocumented

Value
frozenset(set(['datagraphs', 'models']))
_URN_PATTERN =

Undocumented

Value
re.compile(r'^[Uu][Rr][Nn]:(?![Uu][Rr][Nn]-)[a-zA-Z0-9][a-zA-Z0-9-]{1,31}:(?:[a-↵
zA-Z0-9\(\)\+,-\.:=@;\$_!\*\']|%[0-9A-Fa-f]{2})+$')