hio.help.naming
hio.help.naming Module
Mixin Base Class for one-to-one mapping with inverse: name-to-addr and addr-to-name that add support for MemoGrams to datagram based transports.
Provide mixin classes. Takes of advantage of multiple inheritance to enable mixtures of behaviors with minimal code duplication (more DRY).
New style python classes use the C3 linearization algorithm. Multiple inheritance forms a directed acyclic graph called a diamond graph. This graph is linarized into the method resolution order. Use class.mro() or class.__mro__
(see https://www.geeksforgeeks.org/method-resolution-order-in-python-inheritance/) Basically: * children always precede their parents * immediate parent classes of a child are visited in the order listed in the child class statement. * a super class is visited only after all sub classes have been visited * linearized graph is monotonic (a class is only visted once)
Module Contents
- class hio.help.naming.Namer(entries=None, **kwa)
Bases:
hio.hioing.MixinNamer mixin class for adding support for mappings between names and addresses. May be used to provide in-memory lookup of mapping and its inverse of address from name and name from address.
- property addrByName
Property that returns copy of ._addrByName
- property nameByAddr
Property that returns copy of ._nameByAddr
- property countNameAddr
Property that returns count of entries in .addrByName
- clearAllNameAddr()
Clears all entries
- getAddr(name)
Returns addr for given name or None if non-existant
- Parameters:
name (str) – name
- getName(addr)
Returns name for given addr or None if non-existant
- Parameters:
addr (str) – address
- addNameAddr(name, addr)
Add mapping and inverse mapping entries for name to addr and addr to name All mappings must be one-to-one
- Returns:
True if a new entry was added; False if matching entry already exists. Raises NamerError for conflicting partial matches.
- Return type:
bool
- Parameters:
name (str) – name of entry
addr (str) – address of entry
Raise error if preexistant
- remNameAddr(name=None, addr=None)
- Delete both name to addr and addr to name mapping entries.
When an entry is found for either name or addr or both. When both provided must be matching one-to-one entries. All mappings must be one-to-one
- Returns:
True if matching entry was deleted; False when no matching entry exists.
- Return type:
bool
- Parameters:
name (str | None) – name of remote to delete or None if delete by addr
addr (str | None) – addr of remote to delete or None if delete by name
Notes
When both name and addr are provided, delete by name.
Raise error when at least one of name or addr is not None and no mappings exist.
- changeAddrAtName(*, name=None, addr=None)
Changes existing name to addr mapping to new addr. Replaces inverse mapping of addr to name. All mappings must be one-to-one
- Returns:
True if existing entries were updated; False if no change. Raises NamerError for conflicts.
- Return type:
bool
- Parameters:
name (str) – name of entry
addr (str) – address of entry
Raise error if preexistant
- changeNameAtAddr(*, addr=None, name=None)
Changes existing addr to name mapping to new name. Replaces inverse mapping of name to addr. All mappings must be one-to-one
- Returns:
True if existing entries were updated; False if no change. Raises NamerError for conflicts.
- Return type:
bool
- Parameters:
addr (str) – address of entry
name (str) – name of entry
Raise error if preexistant