def adapter(_context, factory, provides=None, for_=None, name=''): if for_ is None: if len(factory) == 1: for_ = adaptedBy(factory[0]) if for_ is None: raise TypeError("No for attribute was provided and can't " "determine what the factory adapts.") for_ = tuple(for_) if provides is None: if len(factory) == 1: p = list(implementedBy(factory[0])) if len(p) == 1: provides = p[0] if provides is None: raise TypeError("Missing 'provides' attribute") if name == '': if len(factory) == 1: name = getName(factory[0]) # Generate a single factory from multiple factories: factories = factory if len(factories) == 1: factory = factories[0] elif len(factories) < 1: raise ComponentConfigurationError("No factory specified") elif len(factories) > 1 and len(for_) != 1: raise ComponentConfigurationError( "Can't use multiple factories and multiple for") else: factory = _rolledUpFactory(factories) _context.action( discriminator=('adapter', for_, provides, name), callable=handler, args=('registerAdapter', factory, for_, provides, name)) _context.action( discriminator=None, callable=provide_interface, args=('', provides)) if for_: for iface in for_: if iface is not None: _context.action( discriminator=None, callable=provide_interface, args=('', iface))
def adapter(_context, factory, provides=None, for_=None, name=''): if for_ is None: if len(factory) == 1: for_ = adaptedBy(factory[0]) if for_ is None: raise TypeError("No for attribute was provided and can't " "determine what the factory adapts.") for_ = tuple(for_) if provides is None: if len(factory) == 1: p = list(implementedBy(factory[0])) if len(p) == 1: provides = p[0] if provides is None: raise TypeError("Missing 'provides' attribute") if name == '': if len(factory) == 1: name = getName(factory[0]) # Generate a single factory from multiple factories: factories = factory if len(factories) == 1: factory = factories[0] elif len(factories) < 1: raise ComponentConfigurationError("No factory specified") elif len(factories) > 1 and len(for_) != 1: raise ComponentConfigurationError( "Can't use multiple factories and multiple for") else: factory = _rolledUpFactory(factories) _context.action(discriminator=('adapter', for_, provides, name), callable=handler, args=('registerAdapter', factory, for_, provides, name)) _context.action(discriminator=None, callable=provideInterface, args=('', provides)) if for_: for iface in for_: if iface is not None: _context.action(discriminator=None, callable=provideInterface, args=('', iface))
def subscriber(_context, for_=None, factory=None, handler=None, provides=None): if factory is None: if handler is None: raise TypeError("No factory or handler provided") if provides is not None: raise TypeError("Cannot use handler with provides") factory = handler else: if handler is not None: raise TypeError("Cannot use handler with factory") if provides is None: raise TypeError( "You must specify a provided interface when registering " "a factory") if for_ is None: for_ = adaptedBy(factory) if for_ is None: raise TypeError("No for attribute was provided and can't " "determine what the factory (or handler) adapts.") for_ = tuple(for_) if handler is not None: _context.action( discriminator=None, callable=_handler, args=('registerHandler', handler, for_, _BLANK)) else: _context.action( discriminator=None, callable=_handler, args=('registerSubscriptionAdapter', factory, for_, provides, _BLANK)) if provides is not None: _context.action( discriminator=None, callable=provide_interface, args=('', provides)) # For each interface, state that the adapter provides that interface. for iface in for_: if iface is not None: _context.action( discriminator=None, callable=provide_interface, args=('', iface))
def subscriber(_context, for_=None, factory=None, handler=None, provides=None): if factory is None: if handler is None: raise TypeError("No factory or handler provided") if provides is not None: raise TypeError("Cannot use handler with provides") factory = handler else: if handler is not None: raise TypeError("Cannot use handler with factory") if provides is None: raise TypeError( "You must specify a provided interface when registering " "a factory") if for_ is None: for_ = adaptedBy(factory) if for_ is None: raise TypeError("No for attribute was provided and can't " "determine what the factory (or handler) adapts.") for_ = tuple(for_) if handler is not None: _context.action(discriminator=None, callable=_handler, args=('registerHandler', handler, for_, _BLANK)) else: _context.action(discriminator=None, callable=_handler, args=('registerSubscriptionAdapter', factory, for_, provides, _BLANK)) if provides is not None: _context.action(discriminator=None, callable=provideInterface, args=('', provides)) # For each interface, state that the adapter provides that interface. for iface in for_: if iface is not None: _context.action(discriminator=None, callable=provideInterface, args=('', iface))
def _callFUT(self, obj): from guillotina.component._declaration import adaptedBy return adaptedBy(obj)
def _callFUT(self, obj): from guillotina.component._declaration import adaptedBy return adaptedBy(obj)