

def _parse_color_88(desc):
    "\n    Return a color number for the description desc.\n    'h0'..'h87' -> 0..87 actual color number\n    '#000'..'#fff' -> 16..79 color cube colors\n    'g0'..'g100' -> 16, 80..87, 79 grays and color cube black/white\n    'g#00'..'g#ff' -> 16, 80...87, 79 gray and color cube black/white\n    \n    Returns None if desc is invalid.\n    \n    >>> _parse_color_88('h142')\n    >>> _parse_color_88('h42')\n    42\n    >>> _parse_color_88('#f00')\n    64\n    >>> _parse_color_88('g100')\n    79\n    >>> _parse_color_88('g#80')\n    83\n    "
    if (len(desc) > 4):
        return None
    try:
        if desc.startswith('h'):
            num = int(desc[1:], 10)
            if ((num < 0) or (num > 87)):
                return None
            return num
        if (desc.startswith('#') and (len(desc) == 4)):
            rgb = int(desc[1:], 16)
            if (rgb < 0):
                return None
            (b, rgb) = ((rgb % 16), (rgb // 16))
            (g, r) = ((rgb % 16), (rgb // 16))
            r = _CUBE_88_LOOKUP_16[r]
            g = _CUBE_88_LOOKUP_16[g]
            b = _CUBE_88_LOOKUP_16[b]
            return ((_CUBE_START + (((r * _CUBE_SIZE_88) + g) * _CUBE_SIZE_88)) + b)
        if desc.startswith('g#'):
            gray = int(desc[2:], 16)
            if ((gray < 0) or (g > 255)):
                return None
            gray = _GRAY_88_LOOKUP[gray]
        elif desc.startswith('g'):
            gray = int(desc[1:], 10)
            if ((gray < 0) or (gray > 100)):
                return None
            gray = _GRAY_88_LOOKUP_101[gray]
        else:
            return None
        if (gray == 0):
            return _CUBE_BLACK
        gray -= 1
        if (gray == _GRAY_SIZE_88):
            return _CUBE_WHITE_88
        return (_GRAY_START_88 + gray)
    except ValueError:
        return None

dataset/ETHPy150Open AnyMesh/anyMesh-Python/example/urwid/display_common.py _parse_color_88/VarMisuse@244/537 `gray`->`g`