Utilities

class batou.utils.Address(connect_address, port=None, require_v4=True, require_v6=False)

An internet service address that can be listened and connected to.

The constructor address is expected to be the address that can be connected to. The listen address will be computed automatically.

>>> x = Address('localhost', 80)
>>> str(x.connect)
'localhost:80'
>>> str(x.listen)
'127.0.0.1:80'
connect = None

The connect address as it should be used when configuring clients. This is a batou.utils.NetLoc object.

property listen

The IPv4 listen (or bind) address as it should be used when configuring servers. This is a batou.utils.NetLoc object. It raises an batou.IPAddressConfigurationError if used unconfigured.

property listen_v6

The IPv6 listen (or bind) address as it should be used when configuring servers. This is a batou.utils.NetLoc object. It raises an batou.IPAddressConfigurationError if used unconfigured.

class batou.utils.BagOfAttributes

Provide a dict-like object that can also be accessed using attributes.

It’s sometimes more convenient to write a.x instead of a[‘x’]. However, namespaces may require being able to also use non-Python-identifier keys.

exception batou.utils.CmdExecutionError(cmd, returncode, stdout, stderr)
exception batou.utils.CycleError
class batou.utils.NetLoc(host, port=None)

A network location specified by host and port.

Network locations can automatically render an appropriate string representation:

>>> x = NetLoc('127.0.0.1')
>>> x.host
'127.0.0.1'
>>> x.port
None
>>> str(x)
'127.0.0.1'

>>> y = NetLoc('127.0.0.1', 80)
>>> str(y)
'127.0.0.1:80'
host = None

The host part of this network location. Can be a hostname or IP address.

port = None

The port of this network location. Can be None or an integer.

batou.utils.call_with_optional_args(func, **kw)

Provide a way to perform backwards-compatible call, passing only arguments that the function actually expects.

batou.utils.dict_merge(a, b)

recursively merges dict’s. not just simple a[‘key’] = b[‘key’], if both a and b have a key who’s value is a dict then dict_merge is called on both values and the result stored in the returned dictionary. https://www.xormedia.com/recursively-merge-dictionaries-in-python/