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)
def _func_settings(self, func): #{{{ global_settings = self._vars['global_settings'] mk_sig = global_settings.pop('MAKE_SIGNAL', 0) s = self._csettings() options = self._func_settings_options(s, global_settings) block = self._blocked_func_settings() custom_block = self._custom_blocked_func_settings news = dict((k, v) for k, v in s.iteritems() if k not in block and not custom_block(k)) ism = bool(s.get('ismethod', False)) istup = isinstance(func, tuple) meth_app = self._vars['methods'].append # Add to methods var so callfunc can process both # conditional callables and target callables if ism: callmeth = bool(s.get('callmethod', False)) if callmeth and not mk_sig: if options['overload']: raise ValueError("Keywords 'overload' and 'callmethod' cannot be True at the same time") func_obj = func[1] if istup else func name, vardict = func_obj.__name__, dict() # Low-level function creation to avoid use of exec # which allows turning this class into a builtin type args, vargs, vkeys, defaults = spec = cgetargspec(func_obj) code_args = args + [v for v in (vargs, vkeys) if v != None] fcode = Code(CodeList(), (), code_args, bool(vargs), bool(vkeys), True, 'f', '<dyn>', 1, None) fcode.code[:] = ([(SetLineno, 2), (LOAD_GLOBAL, 'getattr'), (LOAD_FAST, 'self'), (LOAD_CONST, name), (CALL_FUNCTION, 2), ] + bp_call_args(callmethod=True, *spec) + [(RETURN_VALUE, None)]) f = newfunction(fcode.to_code(), dict(getattr=getattr), 'f', default_argvals(args, defaults)) func = (func[0], f) if istup else f if istup: for f in func: meth_app(f) else: meth_app(func) return func, news, options