boss.helper - heros-boss 0.6.10 documentation

Skip to content
Back to top
View this page

# boss.helper

## Attributes

`log` |

## Functions

`get_module`(path[, relative_path]) |
`get_class_by_name`(name[, relative_path]) | Resolve class by name
`file_from_url`(→ io.IOBase) | Load content from a file specified by a URL.
`extend_none_allowed_list`(→ list | None) | Extend a list with another list which both can be None.
`get_remote_hero`(name, realm[, trials, delay]) | Try multiple times to get RemoteHERO.
`add_class_descriptor`(→ None) | Add a descriptor to a class.
`get_or_create_dynamic_subclass`(→ type) | Return a cached dynamic subclass of `base_cls` based on the input arguments.

## Module Contents

boss.helper.log

boss.helper.get_module(path, relative_path=None)

boss.helper.get_class_by_name(name, relative_path=None)

  Resolve class by name

  Parameters:

    name – (str) “%s.%s” % (module.name, class.name)

  Returns:

    (class)

boss.helper.file_from_url(url: str) → io.IOBase

  Load content from a file specified by a URL.

  This can be every type of URL supported by pythons urllib (e.g. http://, file://, etc ). Giving the basic auth credentials in the URL in the form http://user:password@hostname:port/path is supported.

  Returns:

    file handle on the file

boss.helper.extend_none_allowed_list(list1: list | None, list2: list | None) → list | None

  Extend a list with another list which both can be None.

  If one of the lists is None, the other list is returned. If both lists are None, None is returned.

  Parameters:

    - list1 – list to extend

    - list2 – list to extend with

boss.helper.get_remote_hero(name: str, realm: str, trials: int = 10, delay: float = 1.0)

  Try multiple times to get RemoteHERO.

  Parameters:

    - name – name of the remote HERO.

    - realm – realm of the remote HERO.

    - trials – number of trials before giving up

    - delays – time delay between trials in seconds.

boss.helper.add_class_descriptor(cls: type, attr_name: str, descriptor) → None

  Add a descriptor to a class.

  This is a simple helper function which uses setattr to add an attribute to the class and then also calls __set_name__ on the attribute.

  Parameters:

    - cls – Class to add the descriptor to

    - attr_name – Name of the attribute the descriptor will be added to

    - descriptor – The descriptor to be added

boss.helper.get_or_create_dynamic_subclass(base_cls: Any, *args: Any, **kwargs: Any) → type

  Return a cached dynamic subclass of `base_cls` based on the input arguments.

  This helper generates a subclass of `base_cls` whose identity is determined by `*args` and `**kwargs`. The argument signature is serialized into a hash, which is then used as both a cache key and the dynamic subclass name. If the subclass for a given argument combination already exists, it is returned from cache.

  The generated subclass replaces `__new__` with a dummy implementation to prevent recursive invocation of `base_cls.__new__`.

  Parameters:

    - base_cls – The base class to derive from. Must be passed positionally.

    - *args – Positional values that should influence subclass identity.

    - **kwargs – Keyword values that should influence subclass identity.

  Returns:

    A dynamically generated subclass of `base_cls`.

  Raises:

    TypeError – If arguments cannot be serialized for hashing.