summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMathieu Le Marec - Pasquet <kiorky@cryptelium.net>2016-08-15 22:21:14 +0200
committerGitHub <noreply@github.com>2016-08-15 22:21:14 +0200
commitafa938fff4cca9cab5f3f65127e4784b80219bee (patch)
treeed2f497b402856928c5d7e0a3e6f6124cfbfb7ef
parent3827e2ab306a59104dd24aba45d169592d81f9be (diff)
parent3284e2146aae69e0bbf53e570133d65db470b1a7 (diff)
downloadcroniter-afa938fff4cca9cab5f3f65127e4784b80219bee.tar.gz
Merge pull request #15 from kiorky/revert-14-revert-13-master
Revert "Revert "merge from taichino""
-rw-r--r--src/croniter/croniter.py13
-rwxr-xr-xsrc/croniter/tests/test_croniter.py6
2 files changed, 14 insertions, 5 deletions
diff --git a/src/croniter/croniter.py b/src/croniter/croniter.py
index 5cc2f41..25bb42d 100644
--- a/src/croniter/croniter.py
+++ b/src/croniter/croniter.py
@@ -86,10 +86,10 @@ class croniter(object):
(low, high, step) = m.group(1), m.group(2), m.group(4) or 1
if not any_int_re.search(low):
- low = "{0}".format(self.ALPHACONV[i][low.lower()])
+ low = "{0}".format(self._alphaconv(i, low))
if not any_int_re.search(high):
- high = "{0}".format(self.ALPHACONV[i][high.lower()])
+ high = "{0}".format(self._alphaconv(i, high))
if (
not low or not high or int(low) > int(high)
@@ -111,7 +111,7 @@ class croniter(object):
# e_list.append(j)
else:
if not star_or_int_re.search(t):
- t = self.ALPHACONV[i][t.lower()]
+ t = self._alphaconv(i, t)
try:
t = int(t)
@@ -138,6 +138,13 @@ class croniter(object):
else res)
self.expanded = expanded
+ def _alphaconv(self, index, key):
+ try:
+ return self.ALPHACONV[index][key.lower()]
+ except KeyError:
+ raise ValueError(
+ "[{0}] is not acceptable".format(" ".join(self.exprs)))
+
def get_next(self, ret_type=None):
return self._get_next(ret_type or self._ret_type, is_prev=False)
diff --git a/src/croniter/tests/test_croniter.py b/src/croniter/tests/test_croniter.py
index 55b81a2..0601a7f 100755
--- a/src/croniter/tests/test_croniter.py
+++ b/src/croniter/tests/test_croniter.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/env python
# -*- coding: utf-8 -*-
import unittest
@@ -228,7 +228,9 @@ class CroniterTest(base.TestCase):
self.assertRaises(TypeError, itr.get_next, str)
self.assertRaises(ValueError, croniter, '* * * *')
self.assertRaises(ValueError, croniter, '* * 5-1 * *')
- self.assertRaises(KeyError, croniter, '* * * janu-jun *')
+ self.assertRaises(ValueError, croniter, '-90 * * * *')
+ self.assertRaises(ValueError, croniter, 'a * * * *')
+ self.assertRaises(ValueError, croniter, '* * * janu-jun *')
def testSundayToThursdayWithAlphaConversion(self):
base = datetime(2010, 8, 25, 15, 56) #wednesday