string_helpers – String/Byte helper functionalities

Utilities to deal with strings and bytes for a better python2/3 compatibility

tcs_lib.string_helpers.TIME_FMT = '{t:.9f}'

Default formatter to times in TCS events

tcs_lib.string_helpers.bytes_to_string(byte, encoding='utf-8')[source]

If the input is a string or a list of strings, returns it, otherwise interprets it as a byte string or a list of bytes strings.

Parameters:
byte : (list of) byte string(s)

byte string or list of byte strings to decode

encoding : string, optional

encoding to use; see Standard Encodings for a list of possible encodings

Returns:
Python2: input; Python3: (list of) string(s).

If the input is not iterable returns it

Raises:
ConvertTypeError

if the input is not a string/byte string or a list thereof

tcs_lib.string_helpers.string_to_bytes(string, encoding='utf-8')[source]

If the input is a byte string or a list of byte strings, returns it, otherwise interprets it as a string or a list of strings.

Parameters:
string : (list of) string(s)

string or list of strings to encode

encoding : string, optional

encoding to use; see Standard Encodings for a list of possible encodings

Returns:
Python2: input; Python3: (list of) byte string(s).

If the input is not iterable returns it

Raises:
ConvertTypeError

if the input is not a string/byte string or a list thereof

tcs_lib.string_helpers.time_str()[source]
Returns:
string

time.time as a string with format TIME_FMT