Repository URL to install this package:
Version:
5.0.16-5.0 ▾
|
python3-workloadmgrclient-el8
/
usr
/
lib
/
python3.6
/
site-packages
/
workloadmgrclient
/
v1
/
validators.py
|
---|
# Copyright (c) 2014 TrilioData, Inc
# All Rights Reserved.
import uuid
from workloadmgrclient.exceptions import InvalidUUIDException
from datetime import datetime
def validate_int_value(value, lower_bound, upper_bound=None, **kwargs):
if isinstance(value, str):
try:
value = int(value)
except ValueError:
return False
if value < lower_bound:
return False
if upper_bound and value > upper_bound:
return False
return True
def validate_uuid(id_val):
"""Check if id is valid UUID.
Raises:
InvalidUUIDException: Raise invalid uuid Exception.
"""
try:
uuid.UUID(id_val)
except (ValueError, TypeError) as ex:
raise InvalidUUIDException(f"Invalid id : '{id_val}'. Error: {ex}")
def validate_date_value(value, date_formats):
for i in date_formats:
try:
datetime.strptime(value, i)
return True
except:
pass
return False