def decorate(func): def wrapper(*args, **kwargs): return func(*args, **kwargs) wrapper.__name__ = func.__name__ if priority in signal.CallbackPriority.levels: wrapper.priority = signal.CallbackPriority(priority) else: if not isinstance(priority, int): msg = 'Invalid priorty "{}"; must be an int or one of {}' raise ValueError(msg.format(priority, signal.CallbackPriority.values)) wrapper.priority = level('custom', priority) return wrapper
def cast_level(value, cur): # pylint: disable=unused-argument """Generic Level caster for psycopg2""" if not InterfaceError: raise ImportError('There was a problem importing psycopg2.') if value is None: return None m = re.match(r"([^\()]*)\((\d*)\)", value) name = str(m.group(1)) number = int(m.group(2)) if m: return level(name, number) else: raise InterfaceError("Bad level representation: {}".format(value))
def try_parse_object(v): if isinstance(v, basestring): if v.startswith('REGEX:'): _, flags, pattern = v.split(':', 2) return re.compile(pattern, int(flags or 0)) elif v.startswith('DATET:'): _, pattern = v.split(':', 1) return dateutil.parser.parse(pattern) elif v.startswith('LEVEL:'): _, name, value = v.split(':', 2) return level(name, value) elif v.startswith('CPUMASK:'): _, value = v.split(':', 1) return cpu_mask(value) return v
def test_serialize_level(self): l = level('test', 1) s = l.to_pod() l2 = level.from_pod(s) assert_equal(l, l2)
def _wa_level_constructor(loader, node): value = loader.construct_scalar(node) name, value = value.split(':', 1) return level(name, value)