Esempio n. 1
0
    def __init__(self, name=None, element=None, exported=None,
                 context=None):
        if name    is None: name    = self.__class__.__name__
        if context is None: context = self.context

        # Complex handling of exported, because of clashing use of the
        #  exported name at the class level: property & class-value.
        if exported is not None:
            pass
        elif (hasattr(self.__class__, "exported")
              and not isinstance(self.__class__.exported, property)):
            exported = self.__class__.exported
        else:
            exported = self._default_exported

        # Similar complex handling of element.
        if element is not None:
            pass
        elif (hasattr(self.__class__, "element")
              and not isinstance(self.__class__.element, property)):
            element = self.__class__.element

        # Type checking of initialization values.
        assert isinstance(name, string_types)
        assert isinstance(element, ElementBase)

        self._name     = name

        Rule.__init__(self, self._name, element, exported=exported,
                      context=context)
Esempio n. 2
0
    def __init__(self,
                 name=None,
                 mapping=None,
                 extras=None,
                 defaults=None,
                 exported=None,
                 context=None):
        # pylint: disable=too-many-branches

        if name is None: name = self.__class__.__name__
        if mapping is None: mapping = self.mapping
        if extras is None: extras = self.extras
        if defaults is None: defaults = self.defaults
        if context is None: context = self.context

        # Complex handling of exported, because of clashing use of the
        #  exported name at the class level: property & class-value.
        if exported is not None:
            pass
        elif (hasattr(self.__class__, "exported")
              and not isinstance(self.__class__.exported, property)):
            exported = self.__class__.exported
        else:
            exported = self._default_exported

        # Type checking of initialization values.
        assert isinstance(name, string_types)
        assert isinstance(mapping, dict)
        for key, value in mapping.items():
            assert isinstance(key, string_types)
        assert isinstance(extras, (list, tuple))
        for item in extras:
            assert isinstance(item, ElementBase)
        assert exported in (True, False)

        self._name = name
        self._mapping = mapping
        self._extras = {element.name: element for element in extras}
        self._defaults = defaults

        children = []
        for spec, value in self._mapping.items():
            c = Compound(spec, elements=self._extras, value=value)
            children.append(c)

        if children: element = Alternative(children)
        else: element = None
        Rule.__init__(self,
                      self._name,
                      element,
                      exported=exported,
                      context=context)
Esempio n. 3
0
    def __init__(self,
                 name=None,
                 spec=None,
                 extras=None,
                 defaults=None,
                 exported=None,
                 context=None):
        if name is None: name = self._name or self.__class__.__name__
        if spec is None: spec = self.spec
        if extras is None: extras = self.extras
        if defaults is None: defaults = self.defaults
        if context is None: context = self.context

        # Complex handling of exported, because of clashing use of the
        #  exported name at the class level: property & class-value.
        if exported is not None:
            pass
        elif (hasattr(self.__class__, "exported")
              and not isinstance(self.__class__.exported, property)):
            exported = self.__class__.exported
        else:
            exported = self._default_exported

        assert isinstance(name, string_types)
        assert isinstance(spec, string_types)
        assert isinstance(extras, (list, tuple))
        for item in extras:
            assert isinstance(item, ElementBase)
        assert exported in (True, False)

        self._name = name
        self._spec = spec
        self.spec = spec
        self._extras = dict((element.name, element) for element in extras)
        self._defaults = dict(defaults)

        child = Compound(spec, extras=self._extras)
        Rule.__init__(self, name, child, exported=exported, context=context)