Example #1
0
    def __init__(self,ob):
        obs = list(getMRO(ob))
        for item in obs:
            try:
                reg = item.__dict__.get('__conform__')
                if reg is None and obs==[ob]:
                    # Make sure we don't obscure a method from the class!
                    reg = getattr(item,'__conform__',None)
            except AttributeError:
                raise TypeError(
                    "Only objects with dictionaries can use this adapter",
                    ob
                )
            if reg is not None and not isinstance(reg,conformsRegistry):
                raise TypeError(
                    "Incompatible __conform__ on adapted object", ob, reg
                )

        reg = ob.__dict__.get('__conform__')

        if reg is None:
            reg = ob.__conform__ = self.newRegistry(ob)

        self.ob = ob
        self.reg = reg
Example #2
0
    def findImplementation(self, subject, protocol, checkSelf=True):

        for cls in getMRO(subject):

            conf = cls.__dict__.get('__conform__')

            if conf is None:
                continue

            if not isinstance(conf,conformsRegistry):
                raise TypeError(
                    "Incompatible __conform__ in base class", conf, cls
                )

            if protocol in conf:
                return conf[protocol][0](subject)
Example #3
0
    def __conform__(self,protocol):

        for cls in getMRO(self):
            conf = cls.__dict__.get('__protocols_provided__',())
            if protocol in conf:
                return conf[protocol][0](self)