Exemple #1
0
 def declareProvides(self,protocol,adapter=NO_ADAPTER_NEEDED,depth=1):
     registry = self.__dict__.get('__protocols_provided__')
     if registry is None:
         self.__protocols_provided__ = registry = {}
     if updateWithSimplestAdapter(registry,protocol,adapter,depth):
         adapt(protocol,IOpenProtocol).addImplicationListener(self)
         return True
Exemple #2
0
    def registerObject(self, ob, adapter=NO_ADAPTER_NEEDED,depth=1):
        # Object needs to be able to handle registration
        if api.adapt(ob,IOpenProvider).declareProvides(self,adapter,depth):
            if adapter is DOES_NOT_SUPPORT:
                return  # non-support doesn't imply non-support of implied

            # Handle implied protocols
            for proto, (extender,d) in self.getImpliedProtocols():
                api.declareAdapterForObject(
                    proto, composeAdapters(adapter,self,extender), ob, depth+d
                )
Exemple #3
0
def ADAPT_SEQUENCE(ob, proto):
    """Convert iterable 'ob' into list of objects implementing 'proto'"""

    marker = object()
    out = []
    proto = proto.baseProtocol  # get the protocol to adapt to
    for item in ob:
        item = adapt(item, proto, marker)
        if item is marker:
            return None  # can't adapt unless all members adapt
        out.append(item)
    return out
Exemple #4
0
def ADAPT_SEQUENCE ( ob, proto ):

    """Convert iterable 'ob' into list of objects implementing 'proto'"""

    marker = object()
    out = [ ]
    proto = proto.baseProtocol  # get the protocol to adapt to
    for item in ob:
        item = adapt( item, proto, marker )
        if item is marker:
            return None     # can't adapt unless all members adapt
        out.append( item )
    return out
Exemple #5
0
 def declareProvides(self, protocol, adapter=NO_ADAPTER_NEEDED, depth=1):
     if updateWithSimplestAdapter(self.reg, protocol, adapter, depth):
         adapt(protocol,IOpenProtocol).addImplicationListener(self.reg)
         return True
Exemple #6
0
 def __call__(self, ob, default=api._marker):
     """Adapt to this protocol"""
     return api.adapt(ob,self,default)
Exemple #7
0
 def __adapt__(self, obj):
     return adapt(self,IOpenProtocol).__adapt__(obj)
Exemple #8
0
 def __adapt__(self, obj):
     return adapt(self, IOpenProtocol).__adapt__(obj)