示例#1
0
 def get_required_bool_dict_property(properties: dict,
                                     key: str,
                                     required_error=None) -> bool:
     """
     Get the required dictionary value and cast it to 'bool'
     :param properties: dict data
     :param key: key
     :param required_error: error message if parameter is none
     :return: bool object
     """
     value = DictUtils.get_required_dict_property(properties, key,
                                                  required_error)
     status, result = ParseUtils.try_parse_bool(value)
     if status:
         return result
     else:
         raise InvalidParameterError(
             f'Parameter "{key}" could not be converted to a bool')
示例#2
0
    def get_float_dict_property(properties: dict,
                                key: str,
                                default_value=None) -> float:
        """
        Get the dictionary value and cast it to 'float'
        :param properties: dict data
        :param key: key
        :param default_value: default value
        :return: float object
        """
        value = DictUtils.get_dict_property(properties, key)

        if DictUtils.str_is_null_or_empty(value):
            value = default_value

        status, result = ParseUtils.try_parse_float(value)
        if status:
            return result
        else:
            raise InvalidParameterError(
                f'Parameter "{key}" could not be converted to a float')
示例#3
0
    def get_required_date_dict_property(properties: dict,
                                        key: str,
                                        required_error=None,
                                        format: str = None) -> datetime.date:
        """
        Get the required dictionary value and cast it to 'date'
        :param format: date format
        :param properties: dict data
        :param key: key
        :param required_error: error message if parameter is none
        :return: date object
        """
        value = DictUtils.get_required_dict_property(properties, key,
                                                     required_error)

        status, result = ParseUtils.try_parse_date(value, format=format)
        if status:
            return result
        else:
            raise InvalidParameterError(
                f'Parameter "{key}" could not be converted to a date')
示例#4
0
    def get_date_dict_property(properties: dict,
                               key: str,
                               default_value=None,
                               format: str = None) -> datetime.date:
        """
        Get the dictionary value and cast it to 'date'
        :param format: date format
        :param properties: dict data
        :param key: key
        :param default_value: default value
        :return: date object
        """
        value = DictUtils.get_dict_property(properties, key)

        if DictUtils.str_is_null_or_empty(value):
            value = default_value

        status, result = ParseUtils.try_parse_date(value, format=format)
        if status:
            return result
        else:
            raise InvalidParameterError(
                f'Parameter "{key}" could not be converted to a date')