Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
"""Parse a ranged value in a cronjob"""
if value.count('/') == 1:
value, seq = value.split('/')
try:
self.seq = self.slice.parse_value(seq)
except SundayError:
self.seq = 1
value = "0-0"
if self.seq < 1 or self.seq > self.slice.max - 1:
raise ValueError("Sequence can not be divided by zero or max")
if value.count('-') == 1:
vfrom, vto = value.split('-')
self.vfrom = self.slice.parse_value(vfrom, sunday=0)
try:
self.vto = self.slice.parse_value(vto)
except SundayError:
if self.vfrom == 1:
self.vfrom = 0
else:
self.dangling = 0
self.vto = self.slice.parse_value(vto, sunday=6)
elif value == '*':
self.all()
else:
raise ValueError('Unknown cron range value "%s"' % value)
"""Parse the value of the cron slice and raise any errors needed"""
if val == '>':
val = self.max
elif val == '<':
val = self.min
try:
out = get_cronvalue(val, self.enum)
except ValueError:
raise ValueError("Unrecognised '%s'='%s'" % (self.name, val))
except KeyError:
raise KeyError("No enumeration '%s' got '%s'" % (self.name, val))
if self.max == 6 and int(out) == 7:
if sunday is not None:
return sunday
raise SundayError("Detected Sunday as 7 instead of 0!")
if int(out) < self.min or int(out) > self.max:
raise ValueError("Invalid value '%s', expected %d-%d for %s" % (
str(val), self.min, self.max, self.name))
return out