Utils

handy utilities

exception switchio.utils.APIError

ESL api error

exception switchio.utils.ConfigurationError

Config error

switchio.utils.DictProxy(d, extra_attrs={})

A dictionary proxy object which provides attribute access to elements

exception switchio.utils.ESLError

An error pertaining to the connection

exception switchio.utils.TimeoutError

Timing error

class switchio.utils.Timer(timer=None)

Simple timer that reports an elapsed duration since the last reset.

elapsed()

Returns the elapsed time since the last reset

last_time

Last time the timer was reset

reset()

Reset the timer start point to now

switchio.utils.compose(func_1, func_2)

(f1, f2) -> function The function returned is a composition of f1 and f2.

switchio.utils.con_repr(self)

Repr with a [<connection-status>] slapped in

switchio.utils.dirinfo(inst)

Return common info useful for dir output

switchio.utils.event2dict(event)

Return event serialized data in a python dict Warning: this function is kinda slow!

switchio.utils.get_args(func)

Return the argument names found in func’s signature in a tuple

Returns:the argnames, kwargnames defined by func
Return type:tuple
switchio.utils.get_event_time(event, epoch=0.0)

Return micro-second time stamp value in seconds

switchio.utils.get_logger(name=None)

Return the package log or a sub-log for name if provided.

switchio.utils.get_name(obj)

Return a name for object checking the usual places

switchio.utils.is_callback(func)

Check whether func is valid as a callback

switchio.utils.iter_import_submods(packages, recursive=False, imp_excs=())

Iteratively import all submodules of a module, including subpackages with optional recursion.

Parameters:package (str | module) – package (name or actual module)
Return type:(dict[str, types.ModuleType], dict[str, ImportError])
switchio.utils.log_to_stderr(level=None)

Turn on logging and add a handler which writes to stderr

switchio.utils.ncompose(*funcs)

Perform n-function composition

switchio.utils.param2header(name)

Return the appropriate event header name corresponding to the named parameter name which should be used when the param is received as a header in event data.

Most often this is just the original parameter name with a 'variable_' prefix. This is pretty much a shitty hack (thanks goes to FS for the asymmetry in variable referencing…)

switchio.utils.pstr(self, host='unknown-host')

Pretty str repr of connection-like instances.

switchio.utils.uncons(first, *rest)

Unpack args into first element and tail as tuple

switchio.utils.uuid()

Return a new uuid1 string

switchio.utils.waitwhile(predicate, timeout=inf, period=0.1, exc=True)

Block until predicate evaluates to False.

Parameters:
  • predicate (function) – predicate function
  • timeout (float) – time to wait in seconds for predicate to eval False
  • period (float) – poll loop sleep period in seconds
Raises:

TimeoutError – if predicate does not eval to False within timeout

switchio.utils.xheaderify(header_name)

Prefix the given name with the freeswitch xheader token thus transforming it into an fs xheader variable