Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
Size: Mime:
# 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