kyanit.colorid module

This module publishes two helper functions to work with Color IDs.

See the function documentations for details on usage.


def from_number(num)

Calculate a Color ID string from a number passed to num. If num is negative or larger than 342, ValueError will be raised. The Color ID is used for representing the last octet of an IP address, so any value above 245 is probably also not valid, but 342 is the maximum number that can be represented with the 7 available color symbols.

If num is not int, TypeError will be raised.

def to_colors(color_id)

Return a list with 3 RGB color tuples corresponding to the color_id. The color_id must be a string with 3 upper-case characters, which can be any of 'R', 'G', 'B', 'C', 'M', 'Y', or 'W' (white).

If the color_id is a longer string, subsequent characters are disregarded. If the first 3 characters are not one of the above list, IndexError will be raised.

color_id may also be any other indexable type, but if color_id is not indexable, TypeError will be raised.