コード例 #1
0
    def __add__(self, right):
        """
            >>> plb1 = plumb(1)
            >>> plb1 + plumb(1) is plb1
            True

            >>> plb1 + Instruction(1)
            Traceback (most recent call last):
              ...
            PlumbingCollision:
                <plumb 'None' of None payload=1>
              with:
                <Instruction 'None' of None payload=1>

            >>> plumb(lambda x: None) + plumb(property(lambda x: None))
            Traceback (most recent call last):
              ...
            PlumbingCollision:
                <plumb 'None' of None payload=<function <lambda> at 0x...>>
              with:
                <plumb 'None' of None payload=<property object at 0x...>>
        """
        if self == right:
            return self
        if not isinstance(right, plumb):
            raise PlumbingCollision(self, right)
        if not self.ok(self.payload, right.payload):
            raise PlumbingCollision(self, right)
        return plumb(self.plumb(plumbingfor, self.payload, right.payload),
                     name=self.name)
コード例 #2
0
 def __add__(self, right):
     if self == right:
         return self
     if not isinstance(right, _implements):
         raise PlumbingCollision(self, right)
     ifaces = self.payload + right.payload
     return _implements(ifaces)
コード例 #3
0
 def __call__(self, cls):
     # Check for a method on the plumbing class itself.
     _next = getattr(cls, self.name)
     if not self.ok(self.payload, _next):
         raise PlumbingCollision(self, cls)
     entrance = self.plumb(entrancefor, self.payload, _next)
     setattr(cls, self.name, entrance)
コード例 #4
0
    def __add__(self, right):
        """
        First default wins from left to right::

            >>> def1 = default(1)
            >>> def1 + def1 is def1
            True
            >>> def2 = default(2)
            >>> def1 + def2 is def1
            True
            >>> def2 + def1 is def2
            True

        Override wins over default::

            >>> ext3 = override(3)
            >>> def1 + ext3 is ext3
            True

        Finalize wins over default::

            >>> fin4 = finalize(4)
            >>> def1 + fin4 is fin4
            True

        Adding with something else than default/override, raises
        ``PlumbingCollision``::

            >>> def1 + Instruction('foo')
            Traceback (most recent call last):
              ...
            PlumbingCollision:
                <default 'None' of None payload=1>
              with:
                <Instruction 'None' of None payload='foo'>
        """
        if self == right:
            return self
        if isinstance(right, default):
            return self
        if isinstance(right, override):
            return right
        if isinstance(right, finalize):
            return right
        raise PlumbingCollision(self, right)
コード例 #5
0
    def __add__(self, right):
        """
        First override wins against following equal overrides and arbitrary
        defaults::

            >>> fin1 = finalize(1)
            >>> fin1 + fin1 is fin1
            True
            >>> fin1 + finalize(1) is fin1
            True
            >>> fin1 + default(2) is fin1
            True
            >>> fin1 + override(2) is fin1
            True

        Two unequal finalize collide::

            >>> fin1 + finalize(2)
            Traceback (most recent call last):
              ...
            PlumbingCollision:
                <finalize 'None' of None payload=1>
              with:
                <finalize 'None' of None payload=2>

        Everything except default/override collides::

            >>> fin1 + Instruction(1)
            Traceback (most recent call last):
              ...
            PlumbingCollision:
                <finalize 'None' of None payload=1>
              with:
                <Instruction 'None' of None payload=1>
        """
        if self == right:
            return self
        if isinstance(right, default):
            return self
        if isinstance(right, override):
            return self
        raise PlumbingCollision(self, right)
コード例 #6
0
 def __call__(self, dct, bases):
     if self.name in dct:
         raise PlumbingCollision('Plumbing class', self)
     dct[self.name] = self.payload
コード例 #7
0
 def __call__(self, dct, bases):
     if dct.has_key(self.name):
         raise PlumbingCollision('Plumbing class', self)
     dct[self.name] = self.payload