def get_multi_adapter( objects, interface=Interface, name=_BLANK, context=None, args: Optional[List[Any]] = None, kwargs: Optional[Dict[str, Any]] = None, ): """ Get a registered multi adapter :param objects: Objects to get adapter for :param interface: What interface should the adapter provide :param name: if it is a named adapter :param args: args to provide the adapter constructor :param kwargs: kwargs to provide the adapter constructor :raises ComponentLookupError: """ args = args or [] kwargs = kwargs or {} adapter_ = query_multi_adapter(objects, interface, name, context=context, args=args, kwargs=kwargs) if adapter_ is None: raise ComponentLookupError(objects, interface, name) return adapter_
def get_adapter( object, interface=Interface, name=_BLANK, context=None, args: Optional[List[Any]] = None, kwargs: Optional[Dict[str, Any]] = None, ): """ Get a registered adapter :param object: Object to get adapter for :param interface: What interface should the adapter provide :param name: if it is a named adapter :param args: args to provide the adapter constructor :param kwargs: kwargs to provide the adapter constructor :raises ComponentLookupError: """ args = args or [] kwargs = kwargs or {} adapter_ = query_adapter(object, interface=interface, name=name, default=_MISSING, context=context, args=args, kwargs=kwargs) if adapter_ is _MISSING: # result from get_adapter can be None and still be valid raise ComponentLookupError(object, interface, name) return adapter_
def get_multi_adapter(objects, interface=Interface, name=_BLANK, context=None, args=[], kwargs={}): ''' Get a registered multi adapter :param objects: Objects to get adapter for :param interface: What interface should the adapter provide :param name: if it is a named adapter :param args: args to provide the adapter constructor :param kwargs: kwargs to provide the adapter constructor :raises ComponentLookupError: ''' adapter_ = query_multi_adapter(objects, interface, name, context=context, args=args, kwargs=kwargs) if adapter_ is None: raise ComponentLookupError(objects, interface, name) return adapter_
def getInterface(context, id): """Return interface or raise ComponentLookupError """ iface = queryInterface(id, None) if iface is None: raise ComponentLookupError(id) return iface
def get_component_registry(context=None): """ See IComponentArchitecture. """ if context is None: return globalregistry.base else: # Use the global site manager to adapt context to `IComponentLookup` # to avoid the recursion implied by using a local `get_adapter()` call. try: return IComponentLookup(context) except TypeError as error: raise ComponentLookupError(*error.args)
def get_utility(interface, name="", context=None): """ Get a registered utility :param interface: What interface should the utility provide :param name: if it is a named adapter :raises ComponentLookupError: """ utility = query_utility(interface, name, context=context) if utility is not None: return utility raise ComponentLookupError(interface, name)
def getSiteManager(context=None): """ See IComponentArchitecture. """ global base if context is None: if base is None: from guillotina.component.globalregistry import base return base else: # Use the global site manager to adapt context to `IComponentLookup` # to avoid the recursion implied by using a local `getAdapter()` call. try: return IComponentLookup(context) except TypeError as error: raise ComponentLookupError(*error.args)
def get_multi_adapter(objects, interface=Interface, name=_BLANK, context=None, args=[], kwargs={}): adapter_ = query_multi_adapter(objects, interface, name, context=context, args=args, kwargs=kwargs) if adapter_ is None: raise ComponentLookupError(objects, interface, name) return adapter_
def get_adapter(object, interface=Interface, name=_BLANK, context=None, args=[], kwargs={}): adapter_ = query_adapter(object, interface=interface, name=name, default=_MISSING, context=context, args=args, kwargs=kwargs) if adapter_ is _MISSING: # result from get_adapter can be None and still be valid raise ComponentLookupError(object, interface, name) return adapter_
def getAdapter(object, interface=Interface, name=_BLANK, context=None): adapter_ = queryAdapter(object, interface, name, None, context) if adapter_ is None: raise ComponentLookupError(object, interface, name) return adapter_
def getAdapterInContext(object, interface, context): adapter_ = queryAdapterInContext(object, interface, context) if adapter_ is None: raise ComponentLookupError(object, interface) return adapter_
def getUtility(interface, name='', context=None): utility = queryUtility(interface, name, context=context) if utility is not None: return utility raise ComponentLookupError(interface, name)
def _adapter_hook(interface, object, name, default): _called.append((interface, object, name, default)) raise ComponentLookupError('testing')