def int_list(value_list, default=None): if value_list is None: return default if not isinstance(value_list, list): raise InvalidValueException("Value is not a dict instance '%s'" % value_list) values = [value.strip() for value in value_list] int_values = [] for value in values: try: int_values.append(int(value)) except: raise InvalidValueException("Invalid int value '%s'" % value) return int_values
def dict(value_dict, default=None): if value_dict is None: return default if not isinstance(value_dict, dict): raise InvalidValueException("Value is not a dict instance '%s'" % value_dict) return value_dict
def list(value_list, default=None): if value_list is None: return default if not isinstance(value_list, list): raise InvalidValueException("Value is not a list instance '%s'" % value_list) return value_list
def datetime(value_dt, default=None): if value_dt is None: return default if not isinstance(value_dt, datetime.datetime): raise InvalidValueException("Value is not datetime instance '%s'" % value_dt) return value_dt
def int_csv_to_list(value_csv, default=None): if value_csv is None or value_csv == "": return default values = [value.strip() for value in value_csv.split(",")] int_values = [] for value in values: try: int_values.append(int(value)) except: raise InvalidValueException("Invalid int value '%s'" % value) return int_values
def bool(value, default=None): if value is None or value == "": return default if isinstance(value, bool): return value value = value.lower() if value == "yes" or value == "on" or value == "true": return True elif value == "no" or value == "off" or value == "false": return False else: raise InvalidValueException("Invalid bool value '%s'" % value)
def __init__(self, order_by_str): self.order_by = {} self.keys = [] if not order_by_str: return segments = order_by_str.split(";") for segment in segments: segment = segment.strip() if not segment: continue parts = segment.split(":", 1) if len(parts) < 2: raise InvalidValueException("Invalid orderby format") key = parts[0] value = parts[1] if not key: raise InvalidValueException("Invalid orderby format") if not value: continue elif valid_order_by_values.index(value) >= 0: self.order_by[key] = value self.keys.append(key)
def __init__(self, filter_str): self.filters = {} self.operators = {} self.keys = [] if not filter_str: return segments = filter_str.split(";") for segment in segments: segment = segment.strip() if not segment: continue parts = segment.split(":", 1) if len(parts) < 2: raise InvalidValueException("Invalid filters format") key = parts[0] values = parts[1] if not key: raise InvalidValueException("Invalid filters format") if not values: continue if "," in values: self.operators[key] = ApiFiltersOperatorEnum.OR.value self.filters[key] = [ value.strip() for value in values.split(",") ] elif "$" in values: self.operators[key] = ApiFiltersOperatorEnum.AND.value self.filters[key] = [ value.strip() for value in values.split("$") ] else: self.operators[key] = ApiFiltersOperatorEnum.OR.value self.filters[key] = [ value.strip() for value in values.split(",") ] self.keys.append(key)
def str_list_lower(value_list, default=None): if value_list is None: return default if not isinstance(value_list, list): raise InvalidValueException("Value is not a dict instance '%s'" % value_list) return [value.strip().lower() for value in value_list]
def float(value, default=None): if value is None or value == "": return default try: return float(value) except: raise InvalidValueException("Invalid float value '%s'" % value)