Ejemplo n.º 1
0
    def _matches_str_multi_char_field(self, item, start, stop, step=None):
        """
        Check to see if this multi character part (broken into start, stop, and optional step)
        of the field matches the given time value.

        :param item: Time value to check against the multi character field value.
        :param start: First character string value of the part.
        :param stop: Second character string value of the part.
        :param step: (Optional) Third character string value of the part.
        :return: :bool:`True` if they match; :bool:`False` otherwise.
        """
        # If it's the "last" special character (last "day of month" or "day of week"). TODO - #11
        if stop == LAST:
            raise RuntimeError('Special character {0} is not yet supported'.format(stop))

        # If it's a wildcard special character (match all) as the range "start" value, e.g. "*/2", we want to
        # accept the entire value range of this field. Additionally for this case, there won't be a "stop" value, just
        # a "step". Ex: */2 -> 0-59/2
        if start == ALL:
            start, stop, step = self.min, self.max, stop

        # Check to see if the given item is within our range and a multiple of
        # the step/interval, if one was provided.
        start, stop, step = compat.int(start), compat.int(stop), compat.int(step) if step else None
        is_within_range = start <= item <= stop
        is_multiple_of_step = (not step or (item + start) % step == 0)

        return is_within_range and is_multiple_of_step
Ejemplo n.º 2
0
    def _matches_str_multi_char_field(self, item, start, stop, step=1):
        """
        Check to see if this multi character part (broken into start, stop, and optional step)
        of the field matches the given time value.

        :param item: Time value to check against the multi character field value.
        :param start: First character string value of the part.
        :param stop: Second character string value of the part.
        :param step: (Optional) Third character string value of the part.
        :return: :bool:`True` if they match; :bool:`False` otherwise.
        """
        # If it's the "last" special character (last "day of month" or "day of week"). TODO - #11
        if stop == LAST:
            raise RuntimeError(
                'Special character {0} is not yet supported'.format(stop))

        # If it's a wildcard special character (match all) as the range "start" value, e.g. "*/2", we want to
        # accept the entire value range of this field. Additionally for this case, there won't be a "stop" value, just
        # a "step". Ex: */2 -> 0-59/2
        if start == ALL:
            start, stop, step = self.min, self.max, stop

        # Check to see if the given item is within our range and a multiple of
        # the step/interval, if one was provided.
        start, stop, step = [compat.int(v) for v in (start, stop, step)]
        is_within_range = start <= item <= stop
        is_multiple_of_step = (not step or (item - start) % step == 0)

        return is_within_range and is_multiple_of_step
Ejemplo n.º 3
0
def test_range_wildcard_str_second_field_matches_all_members_within_bounds(second_field_all_match_range_with_step_str):
    """
    Assert that the "second" field created from a "all match" range string with a step value _only_
    matches items within the range itself that are multiples of the step and none other within the bounds.
    """
    start, stop = second_field_all_match_range_with_step_str.min, second_field_all_match_range_with_step_str.max
    step = compat.int(second_field_all_match_range_with_step_str.value.split('/')[-1])
    assert _field_matches_multiple_values_within_bounds(second_field_all_match_range_with_step_str,
                                                        compat.range(start, stop, step))
Ejemplo n.º 4
0
def _int_try_parse(value):
    """
    Attempt to convert the given string to an int. If it cannot be converted, the original string is returned.

    :param value: String to try and convert.
    :return: :class:`int` if conversion was successful; the original :class:`string` otherwise.
    """
    try:
        return compat.int(value)
    except (TypeError, ValueError):
        return value
Ejemplo n.º 5
0
def _int_try_parse(value):
    """
    Attempt to convert the given string to an int. If it cannot be converted, the original string is returned.

    :param value: String to try and convert.
    :return: :class:`int` if conversion was successful; the original :class:`string` otherwise.
    """
    try:
        return compat.int(value)
    except (TypeError, ValueError):
        return value
Ejemplo n.º 6
0
def test_range_wildcard_str_second_field_matches_all_members_within_bounds(
        second_field_all_match_range_with_step_str):
    """
    Assert that the "second" field created from a "all match" range string with a step value _only_
    matches items within the range itself that are multiples of the step and none other within the bounds.
    """
    start, stop = second_field_all_match_range_with_step_str.min, second_field_all_match_range_with_step_str.max
    step = compat.int(
        second_field_all_match_range_with_step_str.value.split('/')[-1])
    assert _field_matches_multiple_values_within_bounds(
        second_field_all_match_range_with_step_str,
        compat.range(start, stop, step))