Skip to content

Commit

Permalink
shared _is_empty
Browse files Browse the repository at this point in the history
  • Loading branch information
jtimpe committed Nov 8, 2023
1 parent 11c6a93 commit 8c3c6eb
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions tdrs-backend/tdpservice/parsers/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,18 +192,23 @@ def isStringLargerThan(val):
lambda value: f'{value} is not larger than {val}.'
)


def _is_empty(value, start, end):
return value_is_empty(value[start:end], end - start)


def notEmpty(start=0, end=None):
"""Validate that string value isn't only blanks."""
# asdf = not str(value)[start:end if end else len(str(value))].isspace()
return make_validator(
lambda value: not value_is_empty(str(value)[start:end if end else len(str(value))], len(str(value))),
lambda value: not _is_empty(str(value), start, end if end else len(value)),
lambda value: f'{str(value)} contains blanks between positions {start} and {end if end else len(str(value))}.'
)

def isEmpty(start=0, end=None):
"""Validate that string value is only blanks."""
return make_validator(
lambda value: value_is_empty(str(value)[start:end if end else len(str(value))], len(str(value))),
lambda value: _is_empty(str(value), start, end if end else len(value)),
lambda value: f'{value} is not blank between positions {start} and {end if end else len(value)}.'
)

Expand Down

0 comments on commit 8c3c6eb

Please sign in to comment.