Example #1
0
    def __init__(self, default, ro=False,  index=None,  value=None,
                 name=None, doc=None, **kwargs):
        """Specify a Parameter with a default value and arbitrary
        number of additional attributes.

        Parameters
        ----------
        name : str
          Name of the parameter under which it should be available in its
          respective collection.
        doc : str
          Documentation about the purpose of this parameter.
        index : int or None
          Index of parameter among the others.  Determines order of listing
          in help.  If None, order of instantiation determines the index.
        ro : bool
          Either value which will be assigned in the constructor is read-only and
          cannot be changed
        value
          Actual value of the parameter to be assigned
        """
        # XXX probably is too generic...
        # and potentially dangerous...
        # let's at least keep track of what is passed
        self._additional_props = []
        for k, v in kwargs.iteritems():
            self.__setattr__(k, v)
            self._additional_props.append(k)

        self.__default = default
        self._ro = ro

        # needs to come after kwargs processing, since some debug statements
        # rely on working repr()
        # value is not passed since we need to invoke _set with init=True
        # below
        IndexedCollectable.__init__(self, index=index, # value=value,
                                    name=name, doc=doc)
        self._isset = False
        if value is None:
            self._set(self.__default, init=True)
        else:
            self._set(value, init=True)

        if __debug__:
            if kwargs.has_key('val'):
                raise ValueError, "'val' property name is illegal."
Example #2
0
 def __reduce__(self):
     icr = IndexedCollectable.__reduce__(self)
     # Collect all possible additional properties which were passed
     # to the constructor
     state = dict([(k, getattr(self, k)) for k in self._additional_props])
     state['_additional_props'] = self._additional_props
     state.update(icr[2])
     res = (self.__class__, (self.__default, self._ro) + icr[1], state)
     #if __debug__ and 'COL_RED' in debug.active:
     #    debug('COL_RED', 'Returning %s for %s' % (res, self))
     return res
Example #3
0
 def __str__(self):
     res = IndexedCollectable.__str__(self)
     # it is enabled but no value is assigned yet
     res += '=%s' % (self.value,)
     return res
Example #4
0
 def __reduce__(self):
     icr = IndexedCollectable.__reduce__(self)
     res = (self.__class__, (self.__default, self._ro) + icr[1], icr[2])
     #if __debug__ and 'COL_RED' in debug.active:
     #    debug('COL_RED', 'Returning %s for %s' % (res, self))
     return res