def check_color(c, greyscale, which):
    """
    Checks that a colour argument for transparent or background options
    is the right form.
    Returns the colour
    (which, if it's a bare integer, is "corrected" to a 1-tuple).
    """

    if c is None:
        return c
    if greyscale:
        try:
            len(c)
        except TypeError:
            c = (c,)
        if len(c) != 1:
            raise ProtocolError("%s for greyscale must be 1-tuple" % which)
        if not is_natural(c[0]):
            raise ProtocolError(
                "%s colour for greyscale must be integer" % which)
    else:
        if not (len(c) == 3 and
                is_natural(c[0]) and
                is_natural(c[1]) and
                is_natural(c[2])):
            raise ProtocolError(
                "%s colour must be a triple of integers" % which)
    return c
def check_color ( c , greyscale , which ) : if c is None : return c if greyscale : try : len ( c ) except TypeError : c = ( c , ) if len ( c ) != 1 : raise ProtocolError ( "%s for greyscale must be 1-tuple" % which ) if not is_natural ( c [ 0 ] ) : raise ProtocolError ( "%s colour for greyscale must be integer" % which ) else : if not ( len ( c ) == 3 and is_natural ( c [ 0 ] ) and is_natural ( c [ 1 ] ) and is_natural ( c [ 2 ] ) ) : raise ProtocolError ( "%s colour must be a triple of integers" % which ) return c
Checks that a colour argument for transparent or background options
    is the right form.
    Returns the colour
    (which, if it's a bare integer, is "corrected" to a 1-tuple).