/usr/lib/python3/dist-packages/pyuca/utils.py is in python3-pyuca 1.1-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 | """
utilities for formatting the datastructures used in pyuca.
Useful mostly for debugging output.
"""
from __future__ import unicode_literals
def hexstrings2int(hexstrings):
"""
list of hex strings to list of integers
>>> hexstrings2int(["0000", "0001", "FFFF"])
[0, 1, 65535]
"""
return [int(hexstring, 16) for hexstring in hexstrings]
def int2hexstrings(number_list):
"""
list of integers to list of 4-digit hex strings
>>> int2hexstrings([0, 1, 65535])
['0000', '0001', 'FFFF']
"""
return [str("{:04X}".format(n)) for n in number_list]
def format_collation_elements(collation_elements):
"""
format collation element array (list of list of integer weights)
>>> str(format_collation_elements([[1, 2, 3], [4, 5]]))
'[0001.0002.0003], [0004.0005]'
>>> format_collation_elements(None)
"""
if collation_elements is None:
return None
else:
return ", ".join(
"[" + ".".join(
int2hexstrings(collation_element)
) + "]" for collation_element in collation_elements
)
def format_sort_key(sort_key):
"""
format sort key (list of integers) with | level boundaries
>>> str(format_sort_key([1, 0, 65535]))
'0001 | FFFF'
"""
return " ".join(
("{:04X}".format(x) if x else "|") for x in sort_key
)
|