Esempio n. 1
0
 def _callFUT(self, *args, **kw):
     from zope.hookable import hookable
     return hookable(*args, **kw)
 def _callFUT(self, *args, **kw):
     from zope.hookable import hookable, _py_hookable
     if hookable is _py_hookable: # pragma: no cover
         raise unittest.SkipTest("Hookable and PyHookable are the same")
     return hookable(*args, **kw)
 def _callFUT(self, *args, **kw):
     from zope.hookable import hookable, _py_hookable
     if hookable is _py_hookable:  # pragma: no cover
         raise unittest.SkipTest("Hookable and PyHookable are the same")
     return hookable(*args, **kw)
Esempio n. 4
0
def getGlobalSiteManager():
    return globalSiteManager

def getSiteManager(context=None):
    if context is None:
        return getGlobalSiteManager()
    else:
        # Use the global site manager to adapt context to `ISiteManager`
        # to avoid the recursion implied by using a local `getAdapter()` call.
        try:
            return ISiteManager(context)
        except TypeError, error:
            raise ComponentLookupError(*error.args)

getSiteManager = hookable(getSiteManager)


# Adapter API

def getAdapterInContext(object, interface, context):
    adapter = queryAdapterInContext(object, interface, context)
    if adapter is None:
        raise ComponentLookupError(object, interface)
    return adapter

def queryAdapterInContext(object, interface, context, default=None):
    conform = getattr(object, '__conform__', None)
    if conform is not None:
        try:
            adapter = conform(interface)
Esempio n. 5
0
 def _callFUT(self, *args, **kw):
     from zope.hookable import hookable
     return hookable(*args, **kw)
Esempio n. 6
0
        warnings.warn(
            "The concept of services has been deprecated. You probably want to "
            "use `getGlobalSiteManager()` or `getUtility()`.",
            DeprecationWarning, warningLevel())
    if context is None:
        return getGlobalServices()
    else:
        # Use the global service manager to adapt context to IServiceService
        # to avoid the recursion implied by using a local getAdapter call.
        try:
            return IServiceService(context)
        except TypeError, error:
            from zope.component.bbb.exceptions import ComponentLookupError
            raise ComponentLookupError(*error.args)

getServices = hookable(getServices)

def getService(name, context=None):
    if __warn__:
        warnings.warn(
            "The concept of services has been deprecated. You probably want to "
            "use `getGlobalSiteManager()` or `getUtility()`.",
            DeprecationWarning, warningLevel())
    return getServices(context).getService(name)

def getServiceDefinitions(context=None):
    if __warn__:
        warnings.warn(
            "The concept of services has been deprecated.",
            DeprecationWarning, warningLevel())
    return getServices(context).getServiceDefinitions()