Merge pull request #33 from pengwk/add-value-boundary-check
Add value boundary check.
This commit is contained in:
commit
9efb124c7b
2 changed files with 20 additions and 4 deletions
|
@ -293,6 +293,12 @@ class _Matcher(object):
|
|||
_assert(start <= end,
|
||||
"%s range start value %r > end value %r",
|
||||
_attribute[which], start, end)
|
||||
|
||||
if increment:
|
||||
next_value = start + increment
|
||||
_assert(next_value <= _end_limit,
|
||||
"the first next value %r out of range [%r, %r]",
|
||||
next_value, start, _end_limit)
|
||||
return set(range(start, end+1, increment or 1))
|
||||
|
||||
_start, _end = _ranges[which]
|
||||
|
@ -320,6 +326,10 @@ class _Matcher(object):
|
|||
"last <day> specifier must include a day number or range in the 'weekday' field, you entered %r", entry)
|
||||
return None, _end
|
||||
|
||||
# allow Sunday to be specified as weekday 7
|
||||
if which == WEEK_OFFSET:
|
||||
_end_limit = 7
|
||||
|
||||
increment = None
|
||||
# increments
|
||||
if '/' in entry:
|
||||
|
@ -328,10 +338,11 @@ class _Matcher(object):
|
|||
_assert(increment > 0,
|
||||
"you can only use positive increment values, you provided %r",
|
||||
increment)
|
||||
|
||||
# allow Sunday to be specified as weekday 7
|
||||
if which == WEEK_OFFSET:
|
||||
_end_limit = 7
|
||||
exceed_limit_error_msg_tpl = ("you can only use increment values "
|
||||
"which less than or equal to the %r")
|
||||
_assert(increment <= _end_limit,
|
||||
exceed_limit_error_msg_tpl,
|
||||
_end_limit)
|
||||
|
||||
# handle singles and ranges
|
||||
good = _parse_piece(entry)
|
||||
|
|
|
@ -161,6 +161,11 @@ class TestCrontab(unittest.TestCase):
|
|||
self.assertRaises(ValueError, lambda: CronTab('* * 32 * *'))
|
||||
self.assertRaises(ValueError, lambda: CronTab('* * * 13 *'))
|
||||
self.assertRaises(ValueError, lambda: CronTab('* * * * 9999'))
|
||||
self.assertRaises(ValueError, lambda: CronTab('20/50 * * * * *'))
|
||||
self.assertRaises(ValueError, lambda: CronTab('0/100 * * * * *'))
|
||||
self.assertRaises(ValueError, lambda: CronTab('*,50-59/12 * * * *'))
|
||||
self.assertRaises(ValueError, lambda: CronTab('* * * DEC/7 * *'))
|
||||
self.assertRaises(ValueError, lambda: CronTab('* * * * MON/7 *'))
|
||||
|
||||
def test_previous(self):
|
||||
schedule = CronTab('0 * * * *')
|
||||
|
|
Loading…
Reference in a new issue