예제 #1
0
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_
예제 #2
0
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_
예제 #3
0
파일: _api.py 프로젝트: worasit/guillotina
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_
예제 #4
0
def getInterface(context, id):
    """Return interface or raise ComponentLookupError
    """
    iface = queryInterface(id, None)
    if iface is None:
        raise ComponentLookupError(id)
    return iface
예제 #5
0
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)
예제 #6
0
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)
예제 #7
0
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)
예제 #8
0
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_
예제 #9
0
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_
예제 #10
0
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_
예제 #11
0
def getAdapterInContext(object, interface, context):
    adapter_ = queryAdapterInContext(object, interface, context)
    if adapter_ is None:
        raise ComponentLookupError(object, interface)
    return adapter_
예제 #12
0
def getUtility(interface, name='', context=None):
    utility = queryUtility(interface, name, context=context)
    if utility is not None:
        return utility
    raise ComponentLookupError(interface, name)
예제 #13
0
 def _adapter_hook(interface, object, name, default):
     _called.append((interface, object, name, default))
     raise ComponentLookupError('testing')