def _restrict_block_resize(self, block, poll_sec): block._old_set_block_size = block.set_block_size @_doxtend(type(block), func_name='set_block_size') def _inj_set_block_size(instance, sz): if sz < self._min_block_size: raise TOSDB_Error("setting a block size < %i has been restricted " "by TOSDB_FixedTimeIntervals" % self._min_block_size) block._old_set_block_size(sz) block.set_block_size = _MethodType(_inj_set_block_size, block)
def _constructMethod(cls, name, self): """ Construct a bound method. @param cls: The class that the method should be bound to. @type cls: L{types.ClassType} or L{type}. @param name: The name of the method. @type name: native L{str} @param self: The object that the method is bound to. @type self: any object @return: a bound method @rtype: L{types.MethodType} """ func = cls.__dict__[name] if _PY3: return _MethodType(func, self) return _MethodType(func, self, cls)
def _restrict_block_resize(self, block, poll_sec): block._old_set_block_size = block.set_block_size @_doxtend(type(block), func_name='set_block_size') def _inj_set_block_size(instance, sz): if sz < self._min_block_size: raise TOSDB_Error( "setting a block size < %i has been restricted " "by TOSDB_FixedTimeIntervals" % self._min_block_size) block._old_set_block_size(sz) block.set_block_size = _MethodType(_inj_set_block_size, block)
def copy(function, **kargs): """ Make a copy of the node `function`, with optional change of node attribute If `function` is a function, it makes a new function object (which links to the same function content) that has an independant set of node parameters. `**kargs` can be used to replace values of node attributes:: @rwf.node('x_square') def square(a): return a**2 x_square = node.copy(square, inputs=['x']) """ f = function # copy function instance ntype = node.get_attribute(f, 'type') if ntype == 'function': g = _FunctionType(f.func_code, f.func_globals, name=f.func_name, argdefs=f.func_defaults, closure=f.func_closure) g.__dict__.update(f.__dict__) else: from copy import copy g = copy(function) # copy function's methods from inspect import ismethod for name in [ name for name, attrib in g.__dict__.iteritems() if ismethod(attrib) and attrib.im_self is f ]: setattr(g, name, _MethodType(getattr(g, name).im_func, g)) # copy/replace node attribute g.__node__ = g.__node__.copy() for key, value in kargs.iteritems(): node.set_attribute(g, key, value) return g
def __get__(self, instance, parent): if instance is None: return self return _MethodType(self, instance)