예제 #1
0
    def _getset_transformer(self, *args): #{{{
        mval = self._mval()
        if not args:
            func = mval._tfunc
            return func
        func = args[0]
        if not iscallable(func):
            raise TypeError("Transform function is not callable")
#        object.__setattr__(mval, '_tfunc', func)
        osetattr(mval, '_tfunc', func)
예제 #2
0
    def _getset_eqfunc(self, *args): #{{{
        mval = self._mval()
        if not args:
            func = mval._eqfunc
            return func
        func = args[0]
        if not iscallable(func):
            raise TypeError("Equals function is not callable")
#        object.__setattr__(mval, '_eqfunc', func)
        osetattr(mval, '_eqfunc', func)
예제 #3
0
    def __init__(self, *anon, **mval): #{{{
        prop, values = self.p, self.v
        if not isinstance(prop, MultiValueProperties):
            raise TypeError("%s object is not a valid properties object" %prop.__class__.__name__)
        elif not isinstance(values, MultiValueValues):
            raise TypeError("%s object is not a valid values object" %values.__class__.__name__)

        if not anon and not mval:
            raise ValueError("Cannot create empty mval")
        block = ['__get__', '__getitem__']
        reserved = [n for n in mval if n in block + dir(object)]
        if reserved:
            raise AttributeError("The following attribute names are reserved: %s" %', '.join(reserved))
        tfunc, eqfunc = self._mktfunc(), self._mkeqfunc()
        if [a for a in (tfunc, eqfunc) if not iscallable(a)]:
            raise TypeError("Attempt to set transform or equals function to a non-callable")
        anon = ((k, v) for k, v in enumerate(anon))
        mval = mdict(anon, mval)
        mval.clearmerged()
#        object.__setattr__(self, '_mval', mval)
#        object.__setattr__(self, '_tfunc', tfunc)
#        object.__setattr__(self, '_eqfunc', eqfunc)
        osetattr(self, '_mval', mval)
        osetattr(self, '_tfunc', tfunc)
        osetattr(self, '_eqfunc', eqfunc)
예제 #4
0
    def __init__(self, mval=None): #{{{
        if mval is not None:
            if not isinstance(mval, MultiValue) or not isinstance(self, mval.__class__.v.__class__):
                raise TypeError("Cannot use %s object as an multivalue" %mval.__class__.__name__)
#            object.__setattr__(self, '_mval', ref(mval))
            osetattr(self, '_mval', ref(mval))