-try:
- from itertools import product
-except ImportError:
- def product(*args):
- if args:
- head, tail = args[0], args[1:]
- for h in head:
- for t in product(*tail):
- yield (h,) + t
-
+def unescape_():
+ h = '[0-9A-Fa-f]'
+ r = re.compile(r'\\x('+h+r'{2})|\\u('+h+'{4})')
+ def unescape(value):
+ if not (value and \
+ (r'\x' in value or r'\u' in value)):
+ return value
+
+ return r.sub(\
+ lambda m: chr(int(m.group(1), 16)) \
+ if m.group(1) is not None else \
+ unichr(int(m.group(2), 16))\
+ .encode('utf-8'),\
+ value)
+ return unescape
+unescape = unescape_()
+
+def product(*args):
+ if args:
+ head, tail = args[0], args[1:]
+ for h in head:
+ for t in product(*tail):
+ yield (h,) + t
+
+ else:
+ yield ()
+
+class CrontabParserError(SyntaxError):
+ def __init__(self, message, lineno, expected=None):
+ if expected:
+ if isinstance(expected, (tuple, list)):
+ exp = ' (expected %s or %s)' % (', '.join(expected[:-1]), expected[-1])