def _check_colorshift(option, opt_str, values, parser):
"""OptionParser callback to check if the given colors are valid.
Also transfroms a little bit the args to make it works:
[color1, color2, speed] -> [[color1, color2], speed]
"""
colors = values[:-1]
speed = values[-1]
for color in colors:
if not helpers.is_color(color):
raise OptionValueError("option %s: invalid color: '%s'" % (opt_str, color)) # noqa
if not speed.isdigit():
raise OptionValueError("option %s: invalid speed: '%s'" % (opt_str, speed)) # noqa
setattr(parser.values, option.dest, [colors, int(speed)])
评论列表
文章目录