Exemplo n.º 1
0
 def mkdeco(f, opt): #{{{
     if 'overload' in opt:
         sigopt['weak'] = False
     signature = []
     sigapp = signature.append
     for ext in decoext:
         if not isclass(ext) or not issubclass(ext, CustomDecoSignal):
             raise TypeError("The 'decoext' argument expected CustomDecoSignal classes, got %s instead" %ext.__name__)
         sigapp(ext)
     sigapp(DecoSignalExtension)
     for ext in sigext:
         if not isclass(ext) or not issubclass(ext, SignalExtension):
             raise TypeError("The 'sigext' argument expected SignalExtension classes, got %s instead" %ext.__name__)
         sigapp(ext)
     sigapp(BaseSignal)
     _NewDecoSignal = newclass('_NewDecoSignal', tuple(signature), 
                               dict(__slots__ = ()))
     return _NewDecoSignal(f, **sigopt)
Exemplo n.º 2
0
 def mkdeco(f, kwargs): #{{{
     sigkw = kwargs.pop('sigkw_', {})
     if 'overload' in kwargs:
         sigkw['weak'] = False
     signature = []
     sigapp = signature.append
     for ext in kwargs.pop('decoext_', ()):
         if not isclass(ext) or not issubclass(ext, CustomDecoSignal):
             raise TypeError("The 'decoext' keyword expected CustomDecoSignal classes, got %s instead" %ext.__name__)
         sigapp(ext)
     sigapp(DecoSignalExtension)
     for ext in kwargs.pop('sigext_', ()):
         if not isclass(ext) or not issubclass(ext, SignalExtension):
             raise TypeError("The 'sigext' keyword expected SignalExtension classes, got %s instead" %ext.__name__)
         sigapp(ext)
     sigapp(BaseSignal)
     _NewDecoSignal = newclass('_NewDecoSignal', tuple(signature), 
                               dict(__slots__ = ()))
     return _NewDecoSignal(f, **sigkw)
Exemplo n.º 3
0
    def mkdeco(f, kwargs): #{{{
        signature = []
        sigapp = signature.append
        for ext in kwargs.pop('decoext', ()):
            if not isclass(ext) or not issubclass(ext, CustomDecoSignal):
                raise TypeError("The 'decoext' keyword expected CustomDecoSignal classes, got %s instead" %ext.__name__)
            sigapp(ext)
        sigapp(DecoSignalExtension)
        for ext in kwargs.pop('sigext', ()):
            if not isclass(ext) or not issubclass(ext, SignalExtension):
                raise TypeError("The 'sigext' keyword expected SignalExtension classes, got %s instead" %ext.__name__)
            sigapp(ext)
        sigapp(BaseSignal)
#        signature = list(kwargs.pop('decoext', ()))
#        signature.extend([DecoSignalExtension] + list(kwargs.pop('sigext', ())) + [BaseSignal])
        cstr = """
        class _NewDecoSignal(%s):
            __slots__ = ()
        """ %', '.join('signature[%i]' %i for i in xrange(len(signature)))
        exec compile(cstr.strip(), '<string>', 'exec') in locals()
        return _NewDecoSignal(f)
Exemplo n.º 4
0
 def settings(func): #{{{
     signal = getattr(func, 'signal', None)
     if isinstance(signal, DecoSignalExtension) and isinstance(signal, BaseSignal):
         DecoSignalFunction = func
     elif not _isf(func) and not isclass(func):
         raise TypeError('argument must be a python function or a python class')
     else:
         signal = mkdeco(func, opt)
         args, vargs, vkeys, defaults = spec = cgetargspec(func)
         code_args = args + [v for v in (vargs, vkeys) if v != None]
         fcode = Code(CodeList(), (), code_args, bool(vargs), bool(vkeys), True, 'f', '<dynamic decorator signal function>', 1, None)
         fcode.code[:] = ([(SetLineno, 2), (LOAD_GLOBAL, 'signal')] + bp_call_args(*spec) + 
                         [(RETURN_VALUE, None)])
         DecoSignalFunction = newfunction(fcode.to_code(), locals(), 'DecoSignalFunction', default_argvals(args, defaults))
     d = DecoSignalFunction
     d = wraps(func)(d)
     d.signal = signal
     signal.signalfunc = d
     for n in signal.decorators:
         setattr(d, n, getattr(signal, n))
     opt['MAKE_SIGNAL'] = 1
     return global_settings(d, **opt)(d)
Exemplo n.º 5
0
 def settings(func): #{{{
     signal = getattr(func, 'signal', None)
     if isinstance(signal, DecoSignalExtension) and isinstance(signal, BaseSignal):
         locals().update(DecoSignalFunction=func)
     elif not _isf(func) and not isclass(func):
         raise TypeError('argument must be a python function or a python class')
     else:
         defstr, callstr = cargdefstr(func)
         signal = mkdeco(func, kwargs)
         fstr = """
         def DecoSignalFunction(%s):
             return signal(%s)
         """ %(defstr, callstr)
         exec compile(fstr.strip(), '<string>', 'exec') in locals()
     d = DecoSignalFunction
     d = wraps(func)(d)
     d.signal = signal
     for n in signal.decorators:
         setattr(d, n, getattr(signal, n))
     kwargs.pop('decoext', ())
     kwargs.pop('sigext', ())
     kwargs['MAKE_SIGNAL'] = 1
     return global_settings(d, **kwargs)(d)
Exemplo n.º 6
0
 def mk_itype(o): #{{{
     if autotype:
         if not isclass(o):
             o = o.__class__
         return InstanceType(o)
     return o