Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def db_value(self, val):
if isinstance(val, (DatetimeWithNanoseconds, datetime, Sentinel, type(None))):
return val
raise errors.InvalidFieldType(f'Invalid field type. Field "{self.name}" expected {datetime}, '
f'got {type(val)}')
def attr_range(self, attr_val, field_val):
"""Method for attribute range"""
try:
start, stop = attr_val
except TypeError:
start = attr_val
stop = None
if start and field_val < start:
raise errors.NumberRangeError(f'Field "{self.name}" expect number must be grater or equal '
f'than {start}, given {field_val}')
if stop and field_val > stop:
raise errors.NumberRangeError(f'Field "{self.name}" expect number must be less than or equal '
f'to {stop}, given {field_val}')
return field_val