def non_blank_str_validator(input_str): """ A simple filter allowing string len > 1 and not None Raises ValidationError otherwise. """ if input_str in [None, '']: raise ValidationError('Input here cannot be empty. (Ctrl-C to exit)\n') else: return input_str
def reminder_validator(input_str): """ Allows a string that matches utils.REMINDER_REGEX. Raises ValidationError otherwise. """ match = re.match(REMINDER_REGEX, input_str) if match or input_str == ".": return input_str else: raise ValidationError("Expected format: <number><w|d|h|m> " "<popup|email|sms>. (Ctrl-C to exit)\n")
def parsable_duration_validator(input_str): """ A filter allowing any duration string which can be parsed by parsedatetime. Raises ValidationError otherwise. """ try: get_timedelta_from_str(input_str) return input_str except ValueError: raise ValidationError('Expected format: a duration (e.g. 1m, 1s, 1h3m)' '(Ctrl-C to exit)\n')
def str_to_int_validator(input_str): """ A filter allowing any string which can be converted to an int. Raises ValidationError otherwise. """ try: int(input_str) return input_str except ValueError: raise ValidationError( 'Input here must be a number. (Ctrl-C to exit)\n')
def parsable_date_validator(input_str): """ A filter allowing any string which can be parsed by dateutil. Raises ValidationError otherwise. """ try: get_time_from_str(input_str) return input_str except ValueError: raise ValidationError( 'Expected format: a date (e.g. 2019-01-01, tomorrow 10am, ' '2nd Jan, Jan 4th, etc) or valid time if today. ' '(Ctrl-C to exit)\n')
def color_validator(input_str): """ A filter allowing only the particular colors used by the Google Calendar API Raises ValidationError otherwise. """ try: assert input_str in VALID_OVERRIDE_COLORS + [''] return input_str except AssertionError: raise ValidationError( "Expected colors are: " + ', '.join(color for color in VALID_OVERRIDE_COLORS) + ". (Ctrl-C to exit)\n")