Exemplo n.º 1
0
    def __init__(self, klass = object, allow_none = True, factory = None, 
                 args = None, kw = None, **metadata):
        try:
            iszopeiface = issubclass(klass, zope.interface.Interface)
        except TypeError:
            iszopeiface = False
        
        metadata.setdefault( 'copy', 'deep' )

        self._allow_none = allow_none
        self.klass = klass
        default_value = None
        
        if has_interface(klass, IContainer) or (isclass(klass) and IContainer.implementedBy(klass)):
            self._is_container = True
        else:
            self._is_container = False

        if iszopeiface:
            self._instance = None
            self.factory = factory
            self.args = args
            self.kw = kw
        else:
            self._instance = Instance(klass=klass, allow_none=allow_none, 
                                      factory=factory, args=args, kw=kw,
                                      **metadata)
            default_value = self._instance.default_value
        super(Slot, self).__init__(default_value, **metadata)
Exemplo n.º 2
0
    def __init__(self,
                 klass=object,
                 allow_none=True,
                 factory=None,
                 args=None,
                 kw=None,
                 **metadata):

        default_value = None
        try:
            iszopeiface = issubclass(klass, zope.interface.Interface)
        except TypeError:
            iszopeiface = False
            if not isclass(klass):
                default_value = klass
                klass = klass.__class__

        metadata.setdefault('copy', 'deep')

        self._allow_none = allow_none
        self.klass = klass

        if has_interface(klass, IContainer) or \
                (isclass(klass) and IContainer.implementedBy(klass)):
            self._is_container = True
        else:
            self._is_container = False

        if iszopeiface:
            self._instance = None
            self.factory = factory
            self.args = args
            self.kw = kw
        else:
            self._instance = traits.api.Instance(klass=klass,
                                                 allow_none=allow_none,
                                                 factory=factory,
                                                 args=args,
                                                 kw=kw,
                                                 **metadata)
            if default_value:
                self._instance.default_value = default_value
            else:
                default_value = self._instance.default_value

            if klass.__name__ == 'VariableTree':
                raise TypeError('Slotting of VariableTrees is not supported,'
                                ' please use VarTree instead')

        super(Base, self).__init__(default_value, **metadata)
Exemplo n.º 3
0
    def __init__(self, klass=object, allow_none=True, factory=None,
                 args=None, kw=None, **metadata):

        default_value = None
        try:
            iszopeiface = issubclass(klass, zope.interface.Interface)
        except TypeError:
            iszopeiface = False
            if not isclass(klass):
                default_value = klass
                klass = klass.__class__

        metadata.setdefault('copy', 'deep')

        self._allow_none = allow_none
        self.klass = klass

        if has_interface(klass, IContainer) or \
           (isclass(klass) and IContainer.implementedBy(klass)):
            self._is_container = True
        else:
            self._is_container = False

        if iszopeiface:
            self._instance = None
            self.factory = factory
            self.args = args
            self.kw = kw
        else:
            self._instance = traits.api.Instance(klass=klass, allow_none=allow_none,
                                      factory=factory, args=args, kw=kw,
                                      **metadata)
            if default_value:
                self._instance.default_value = default_value
            else:
                default_value = self._instance.default_value

            if klass.__name__ == 'VariableTree':
                raise TypeError('Slotting of VariableTrees is not supported,'
                                ' please use VarTree instead')

        super(Base, self).__init__(default_value, **metadata)