Beispiel #1
0
def _field_matches_upper_bound_inclusive(field):
    """
    Return :bool:`True` if the given field matches its maximum bound value.
    """
    below = field.matches(field.max - 1)
    exact = field.matches(field.max)
    above = field.matches(field.max + 1)
    return below is True and exact is True and above is False
Beispiel #2
0
def _field_matches_multiple_values_within_bounds(field, values):
    """
    Return :bool:`True` if the given field _only_ matches against a collection of specified values. This will check
    that the given values match and that no other values within the expected min/max bounds do.
    """
    exact = (field.matches(v) for v in values)
    others_within_bounds = (field.matches(v) for v in compat.range(field.min, field.max) if v not in values)
    return all(exact) and not any(others_within_bounds)
Beispiel #3
0
def _field_matches_single_value_within_bounds(field, value):
    """
    Return :bool:`True` if the given field _only_ matches the given value. This will check that the given
    value matches and that no other values within the expected min/max bounds do.
    """
    exact = field.matches(value)
    others_within_bounds = (field.matches(v) for v in compat.range(field.min, field.max) if v != value)
    return exact is True and not any(others_within_bounds)
Beispiel #4
0
def _field_matches_upper_bound_inclusive(field):
    """
    Return :bool:`True` if the given field matches its maximum bound value.
    """
    below = field.matches(field.max - 1)
    exact = field.matches(field.max)
    above = field.matches(field.max + 1)
    return below is True and exact is True and above is False
Beispiel #5
0
def _field_matches_multiple_values_within_bounds(field, values):
    """
    Return :bool:`True` if the given field _only_ matches against a collection of specified values. This will check
    that the given values match and that no other values within the expected min/max bounds do.
    """
    exact = (field.matches(v) for v in values)
    others_within_bounds = (field.matches(v)
                            for v in compat.range(field.min, field.max)
                            if v not in values)
    return all(exact) and not any(others_within_bounds)
Beispiel #6
0
def _field_matches_single_value_within_bounds(field, value):
    """
    Return :bool:`True` if the given field _only_ matches the given value. This will check that the given
    value matches and that no other values within the expected min/max bounds do.
    """
    exact = field.matches(value)
    others_within_bounds = (field.matches(v)
                            for v in compat.range(field.min, field.max)
                            if v != value)
    return exact is True and not any(others_within_bounds)
Beispiel #7
0
        def fields_lazy_eval(datetime_fields,
                             expression_fields,
                             field_names=field.NAMES):
            """
            Generator function that yields back individual field names and the "match" result of the
            :class:`~crython.field.CronField` with the :class:`~datetime.datetime` field value.

            :param datetime_fields: Mapping of field name to actual datetime value.
            :param expression_fields: Mapping of field name to cron field instance.
            :param field_names: Sequence of field names to use.
            :return: Generator that yields tuple pairs of field name and the match result.
            """
            for name in field_names:
                field = expression_fields[name]  # pylint: disable=redefined-outer-name
                time = datetime_fields[name]
                match = field.matches(datetime_fields[name])
                match_str = 'matches' if match else 'does not match'
                self.logger.debug('Field "{0}:{1}" {2} value "{3}"'.format(
                    name, field, match_str, time))
                yield match