Пример #1
0
def purge(event):
    """Asynchronously send PURGE requests
    """
    request = event.request
    context = event.object

    annotations = IAnnotations(request, None)
    if annotations is None:
        return

    paths = annotations.get(KEY, None)
    if paths is None or not paths:
        return

    setSite(getattr(IComponentLookup(context, None), '__parent__'))

    if not isCachePurgingEnabled(context):
        return

    purger = queryUtility(IPurger, context=context)
    if purger is None:
        return

    settings = getUtility(ICachePurgingConfiglet, context=context)
    for path in paths:
        for url in getURLsToPurge(path, settings.cachingProxies):
            purger.purgeAsync(url)

    setSite(None)
Пример #2
0
 def test_nested(self):
     from zope.component import getGlobalSiteManager
     from zope.component.interfaces import IComponentLookup
     from zope.interface.registry import Components
     gsm = getGlobalSiteManager()
     gutil = _makeMyUtility('global', gsm)
     gsm.registerUtility(gutil, IMyUtility, 'myutil')
     sm1 = Components('sm1', bases=(gsm, ))
     sm1_1 = Components('sm1_1', bases=(sm1, ))
     util1 = _makeMyUtility('one', sm1)
     sm1.registerUtility(util1, IMyUtility, 'myutil')
     self.assertTrue(IComponentLookup(util1) is sm1)
     self.assertTrue(self._callFUT(util1, IMyUtility, 'myutil') is gutil)
     util1_1 = _makeMyUtility('one-one', sm1_1)
     sm1_1.registerUtility(util1_1, IMyUtility, 'myutil')
     self.assertTrue(IComponentLookup(util1_1) is sm1_1)
     self.assertTrue(self._callFUT(util1_1, IMyUtility, 'myutil') is util1)
Пример #3
0
def getSiteManager(context=None):
    global base
    if context is None:
        if base is None:
            from zope.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, error:
            raise ComponentLookupError(*error.args)
Пример #4
0
    def setSiteManager(self, sm):
        #if interfaces.ISite.providedBy(self):
        #    raise TypeError("Already a site")

        if IComponentLookup.providedBy(sm):
            self._sm = sm
            sm.__name__ = '++etc++site'
            sm.__parent__ = self
        else:
            raise ValueError('setSiteManager requires an IComponentLookup')

        interface.directlyProvides(
            self, interface.directlyProvidedBy(self), interfaces.ISite)

        event.notify(interfaces.NewLocalSite(sm))
Пример #5
0
def getSiteManager(context=None):
    """A special hook for getting the site manager.

    Here we take the currently set site into account to find the appropriate
    site manager.
    """
    if context is None:
        return siteinfo.sm

    # We remove the security proxy because there's no way for
    # untrusted code to get at it without it being proxied again.

    # We should really look look at this again though, especially
    # once site managers do less.  There's probably no good reason why
    # they can't be proxied.  Well, except maybe for performance.
    sm = IComponentLookup(context, getGlobalSiteManager())
    sm = removeSecurityProxy(sm)
    return sm
    def testSiteManagerSetup(self):
        clearSite()
        # The portal should be an ISite
        self.assertTrue(ISite.providedBy(self.portal))
        # There should be a IComponentRegistry
        comp = IComponentLookup(self.portal)
        IComponentRegistry.providedBy(comp)

        # Test if we get the right site managers
        gsm = getGlobalSiteManager()
        sm = getSiteManager()
        # Without setting the site we should get the global site manager
        self.assertTrue(sm is gsm)

        # Now we set the site, as it is done in url traversal normally
        setSite(self.portal)
        # And should get the local site manager
        sm = getSiteManager()
        self.assertTrue(aq_base(sm) is aq_base(comp))
Пример #7
0
 def test_gsm_is_IComponentLookup(self):
     from zope.component.globalregistry import base
     from zope.component.interfaces import IComponentLookup
     gsm = self._callFUT()
     self.assertTrue(gsm is base)
     self.assertTrue(IComponentLookup.providedBy(gsm))
Пример #8
0
 def test_gsm_is_IComponentLookup(self):
     from zope.component.globalregistry import base
     from zope.component.interfaces import IComponentLookup
     gsm = self._callFUT()
     self.assertTrue(gsm is base)
     self.assertTrue(IComponentLookup.providedBy(gsm))
Пример #9
0
 def test_sm_is_IComponentLookup(self):
     from zope.component.interfaces import IComponentLookup
     sm = self._callFUT()
     self.assertTrue(IComponentLookup.providedBy(sm))
Пример #10
0
 def test_sm_is_IComponentLookup(self):
     from zope.component.interfaces import IComponentLookup
     sm = self._callFUT()
     self.assertTrue(IComponentLookup.providedBy(sm))