Ejemplo n.º 1
0
 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
Ejemplo n.º 2
0
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))
Ejemplo n.º 3
0
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))
Ejemplo n.º 4
0
        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
Ejemplo n.º 5
0
        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
Ejemplo n.º 6
0
 def test_serialize_level(self):
     l = level('test', 1)
     s = l.to_pod()
     l2 = level.from_pod(s)
     assert_equal(l, l2)
Ejemplo n.º 7
0
def _wa_level_constructor(loader, node):
    value = loader.construct_scalar(node)
    name, value = value.split(':', 1)
    return level(name, value)
Ejemplo n.º 8
0
def _wa_level_constructor(loader, node):
    value = loader.construct_scalar(node)
    name, value = value.split(':', 1)
    return level(name, value)
Ejemplo n.º 9
0
 def test_serialize_level(self):
     l = level('test', 1)
     s = l.to_pod()
     l2 = level.from_pod(s)
     assert_equal(l, l2)