Exemplo n.º 1
0
    def __new__(cls, priority, function, *args, **kwargs):
        """
        Creates a Hook with the given:
          priority: some comparable object. only used if you place the
                    hook in a HookList.
          function: can be any callable
                    if the given argument for function is not a callable,
                    it will be wrapped to a function which always returns
                    that argument (a constant of sorts)
          args:     arguments that will be passed to function
                    when this hook is called

        Examples:
          h1 = Hook(0.0, lambda a, b: a + b, (1, 4))
          h1() # 5
          h2 = Hook(0.0, 27, ())
          h2() # 27
          h3 = Hook(7.2, lambda a, b, c: a + b + c, (1, 4))
          h3(8) # 13
        """
        if not callable(function):
            function = util.always(function)
        self = partial.__new__(cls, function, *args, **kwargs)
        self.priority = priority
        return self
Exemplo n.º 2
0
 def __new__(cls, func, *args, **kw):
     assert not isinstance(func, Handler)
     obj = partial.__new__(cls, func, *args, **kw)
     obj._cancelled = False
     return obj
Exemplo n.º 3
0
 def __new__(cls, name, call, *args, **kwds):
     check = partial.__new__(cls, call, *args, **kwds)
     check.__name__ = name
     return check
Exemplo n.º 4
0
 def __new__(cls, name, typeobj):
     obj = partial.__new__(cls, typeobj.__instancecheck__)
     obj.__name__ = name or (typeobj.__name__ + "?")
     return obj
Exemplo n.º 5
0
 def __new__(cls, func, *args, **kw):
     assert not isinstance(func, Handler)
     obj = partial.__new__(cls, func, *args, **kw)
     obj._cancelled = False
     return obj
Exemplo n.º 6
0
 def __new__(cls, target, kwargs):
     """
     Just pass the arguments to underlying ``functools.partial``.
     """
     return partial.__new__(cls, target, **kwargs)
Exemplo n.º 7
0
 def __new__(cls, *funcs):
     funcs = (func if isinstance(func, cls) else [func] for func in funcs)
     funcs = tuple(itertools.chain(*funcs))
     return partial.__new__(cls,
                            *(funcs if len(funcs) == 1 else (pipe, funcs)))
Exemplo n.º 8
0
 def __new__(cls, name, typeobj):
     obj = partial.__new__(cls, typeobj.__instancecheck__)
     obj.__name__ = name or (typeobj.__name__ + "?")
     return obj
Exemplo n.º 9
0
 def __new__(cls, name, call, *args, **kwds):
     check = partial.__new__(cls, call, *args, **kwds)
     check.__name__ = name
     return check
Exemplo n.º 10
0
 def __new__(cls, target, kwargs):
     """
     Just pass the arguments to underlying ``functools.partial``.
     """
     return partial.__new__(cls, target, **kwargs)