crossbar._util

Attributes

Functions

_add_cbdir_config(parser)

_add_debug_options(parser)

_add_log_arguments(parser)

_deep_merge_list(a, b)

Merges two lists. The list being merged must have length >= the

_deep_merge_map(a, b)

_deep_merge_object(a, b)

_qn(obj)

alternative_username(username)

class_name(obj)

This returns a name like "module.Class" given either an instance, or a class.

dump_json(obj[, minified])

Dump JSON to a string, either pretty printed or not. Returns a Unicode

extract_member_oid(→ uuid.UUID)

Extract the XBR network member ID from the WAMP session authid (eg member_oid==72de3e0c-ca62-452f-8f09-2d3d30d1b511 from authid=="member-72de3e0c-ca62-452f-8f09-2d3d30d1b511"

first_free_tcp_port([host, portrange])

Returns the first free listening port within the given range.

get_free_tcp_address([host])

Returns default local listening address with random port.

get_free_tcp_port([host])

Returns random, free listening port.

hl(text[, bold, color])

Returns highlighted text.

hlcontract(oid)

hlfixme(msg, obj)

hlflag(flag[, true_txt, false_txt, null_txt])

hlid(oid)

hltype(obj[, render])

hluserid(oid)

Returns highlighted text.

hlval(val[, color])

maybe_from_env(value)

merge_config(base_config, other_config)

set_flags_from_args(_args)

term_print(text)

This directly prints to the process controlling terminal (if there is any).

Module Contents

DEBUG_LIFECYCLE = False[source]
DEBUG_PROGRAMFLOW = False[source]
_ENVPAT[source]
_ENVPAT_STR = '^\\$\\{(.+)\\}$'[source]
_TERMINAL = None[source]
_TERMINAL = '/dev/tty'[source]
_TERMINAL = None[source]
_add_cbdir_config(parser)[source]
_add_debug_options(parser)[source]
_add_log_arguments(parser)[source]
_deep_merge_list(a, b)[source]

Merges two lists. The list being merged must have length >= the list into which is merged.

Parameters:
  • a – The list into which the other list is merged

  • b – The list to be merged into the former

Returns:

The merged list

_deep_merge_map(a, b)[source]
Parameters:
  • a

  • b

Returns:

_deep_merge_object(a, b)[source]
Parameters:
  • a

  • b

Returns:

_qn(obj)[source]
alternative_username(username)[source]
class_name(obj)[source]

This returns a name like “module.Class” given either an instance, or a class.

dump_json(obj, minified=True)[source]

Dump JSON to a string, either pretty printed or not. Returns a Unicode string.

extract_member_oid(details: autobahn.wamp.CallDetails) uuid.UUID[source]

Extract the XBR network member ID from the WAMP session authid (eg member_oid==72de3e0c-ca62-452f-8f09-2d3d30d1b511 from authid=="member-72de3e0c-ca62-452f-8f09-2d3d30d1b511"

Parameters:

details – Call details.

Returns:

Extracted XBR network member ID.

first_free_tcp_port(host='127.0.0.1', portrange=(1024, 65535))[source]

Returns the first free listening port within the given range.

Parameters:
  • host (str) – Host (interface) for which to return a free port for.

  • portrange (tuple) – Pair of start and end port for port range to select free port within.

Returns:

Free TCP listening port.

Return type:

int

get_free_tcp_address(host='127.0.0.1')[source]

Returns default local listening address with random port.

Note: this is _not_ completely race free, as a port returned as free might be used by another process before the caller can bind it.

Returns:

Default/free listening address:port.

Return type:

str

get_free_tcp_port(host='127.0.0.1')[source]

Returns random, free listening port.

Note

This is _not_ completely race free, as a port returned as free is closed before returning, and might then be used by another process before the caller of this function can actually bind it. So watch out ..

Parameters:

host (str) – Host (interface) for which to return a free port for.

Returns:

Free TCP listening port.

Return type:

int

hl(text, bold=False, color='yellow')[source]

Returns highlighted text.

hlcontract(oid)[source]
hlfixme(msg, obj)[source]
hlflag(flag, true_txt='YES', false_txt='NO', null_txt='UNSET')[source]
hlid(oid)[source]
hltype(obj, render=True)[source]
hluserid(oid)[source]

Returns highlighted text.

hlval(val, color='white')[source]
maybe_from_env(value)[source]
merge_config(base_config, other_config)[source]
Parameters:
  • base_config

  • other_config

Returns:

set_flags_from_args(_args)[source]
term_print(text)[source]

This directly prints to the process controlling terminal (if there is any). It bypasses any output redirections, or closes stdout/stderr pipes.

This can be used eg for “admin messages”, such as “node is shutting down now!”

This currently only works on Unix like systems (tested only on Linux). When it cannot do so, it falls back to plain old print.