Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def hex_color_type(string):
"""Type parser for argparse. Argument must be an hexadecimal number representing a color.
For example 'AABBCC' (RGB) or 'AABBCCFF' (RGBA). An exception will be raised if the argument
is not of that form.
"""
try:
components = tuple(bytearray.fromhex(string))
if len(components) == 3:
components += (255,)
c = Color(*components)
return c
except:
error = "Color must be an hexadecimal number, for example 'AABBCC'"
raise argparse.ArgumentTypeError(error)