Пример #1
0
 def clone():
     """Return a simple generic function that "inherits" from this one"""
     f = _mkGeneric(oldfunc,argname)
     protocols.declareAdapter(
         protocols.NO_ADAPTER_NEEDED,[f.protocol],forProtocols=[protocol]
     )
     return f
Пример #2
0
    def checkImplicationBug(self):
        class I1(Interface):
            pass

        class I2(I1):
            pass

        declareAdapter(lambda o: o, provides=[I1], forProtocols=[I2])
Пример #3
0
    def checkImplicationBug(self):
        class I1(Interface):
            pass

        class I2(I1):
            pass

        declareAdapter(lambda o: o, provides=[I1], forProtocols=[I2])
Пример #4
0
 def clone():
     """Return a simple generic function that "inherits" from this one"""
     f = _mkGeneric(oldfunc, argname)
     protocols.declareAdapter(protocols.NO_ADAPTER_NEEDED, [f.protocol],
                              forProtocols=[protocol])
     return f
Пример #5
0
def declareForProto(pro, proto, factory):
    protocols.declareAdapter(factory, provides=[proto], forProtocols=[pro])
Пример #6
0
def declareForType(typ, proto, factory):
    protocols.declareAdapter(factory, provides=[proto], forTypes=[typ])
Пример #7
0
def declareForProto(pro,proto,factory):
    protocols.declareAdapter(factory,provides=[proto],forProtocols=[pro])
Пример #8
0
def declareForType(typ,proto,factory):
    protocols.declareAdapter(factory,provides=[proto],forTypes=[typ])
Пример #9
0
                return self.items[0] | sig
            return Predicate(self.items + [sig])

        return Predicate(list(self) + list(other))

    def __eq__(self, other):
        return self is other or self.items == list(other)

    def __ne__(self, other):
        return not self.__eq__(other)

    def __repr__(self):
        return repr(self.items)


protocols.declareAdapter(lambda ob: Predicate([ob]), [IDispatchPredicate],
                         forProtocols=[ISignature])


class Signature(object):
    """A set of criteria (in conjunctive normal form) applied to expressions"""

    protocols.advise(instancesProvide=[ISignature])

    __slots__ = 'data', 'keys'

    def __init__(self, __id_to_test=(), **kw):
        items = list(__id_to_test) + [(Argument(name=k), v)
                                      for k, v in list(kw.items())]
        self.data = data = {}
        self.keys = keys = []
        for k, v in items:
Пример #10
0
                return self.items[0] | sig
            return Predicate(self.items+[sig])

        return Predicate(list(self)+list(other))

    def __eq__(self,other):
        return self is other or self.items==list(other)

    def __ne__(self,other):
        return not self.__eq__(other)

    def __repr__(self):
        return repr(self.items)

protocols.declareAdapter(
    lambda ob: Predicate([ob]), [IDispatchPredicate], forProtocols=[ISignature]
)

class Signature(object):
    """A set of criteria (in conjunctive normal form) applied to expressions"""

    protocols.advise(instancesProvide=[ISignature])

    __slots__ = 'data','keys'

    def __init__(self, __id_to_test=(), **kw):
        items = list(__id_to_test)+[(Argument(name=k),v) for k,v in list(kw.items())]
        self.data = data = {}; self.keys = keys = []
        for k,v in items:
            v = ICriterion(v)
            k = k,v.node_type
Пример #11
0
        """Parse 'input' at 'startState', call 'produce(result)', return state

        Return a 'ParseError' instance if no match"""

    def format(data, write):
        """Pass formatted 'data' to 'write()'"""

    def withTerminators(terminators, memo):
        """Return a version of this syntax using the specified terminators"""

    def getOpening(closing, memo):
        """Possible opening characters for this match, based on 'closing'"""


protocols.declareAdapter(lambda o: Optional(*o),
                         provides=[IRule],
                         forTypes=[tuple])


class Rule(object):
    """Production rule protocol for translation between data and strings"""

    protocols.advise(instancesProvide=[IRule])

    __slots__ = ()

    def parse(self, input, produce, startState):
        raise NotImplementedError

    def format(self, data, write):
        raise NotImplementedError