当前位置: 首页>>代码示例>>Python>>正文


Python interfaces.ISite类代码示例

本文整理汇总了Python中zope.location.interfaces.ISite的典型用法代码示例。如果您正苦于以下问题:Python ISite类的具体用法?Python ISite怎么用?Python ISite使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了ISite类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: unregisterService

def unregisterService(service, interface):
    """Unregister the service using the given interface.
    """
    site = service.aq_parent
    if not ISite.providedBy(site):
        raise ValueError("Service parent is not a site.")
    sm = ISite(site).getSiteManager()
    sm.unregisterUtility(service, interface)
开发者ID:silvacms,项目名称:silva.core.conf,代码行数:8,代码来源:utils.py

示例2: getNearestSite

 def getNearestSite(self):
     """See ILocationInfo
     """
     if ISite.providedBy(self.context):
         return self.context
     for parent in self.getParents():
         if ISite.providedBy(parent):
             return parent
     return self.getRoot()
开发者ID:felixonmars,项目名称:zope.location,代码行数:9,代码来源:traversing.py

示例3: delete_site

 def delete_site(self):
     if not self.is_site():
         raise ValueError(_(u'Not a local site.'))
     if interfaces.IRoot.providedBy(self.context):
         raise ValueError(_(u"Can't disable local site on Silva Root."))
     sm = ISite(self.context).getSiteManager()
     if list(sm.registeredAdapters()):
         raise ValueError(_(u'Still have registered customizations.'))
     if list(sm.registeredUtilities()):
         raise ValueError(_(u'Still have registered services.'))
     disableSite(self.context)
开发者ID:silvacms,项目名称:Products.Silva,代码行数:11,代码来源:localsite.py

示例4: ensure_site

def ensure_site(context):
    """Ensure the given context implements ISite.  The importance of
    this method is that it will ensure the given context is an ISite
    regardless of the Zope version (Zope 2.9 had a really hacked up
    SiteManager mechanism we have to account for).

      >>> from zope.location.interfaces import ISite, IPossibleSite
      >>> from OFS.Folder import Folder
      >>> if not IPossibleSite.implementedBy(Folder):
      ...    from zope import interface
      ...    from Products.Five.site.metaconfigure import (FiveSite,
      ...                                                  classSiteHook)
      ...    classSiteHook(Folder, FiveSite)
      ...    interface.classImplements(Folder, IPossibleSite)
      >>> om = Folder('foo')

      >>> ISite.providedBy(om)
      False

      >>> try:
      ...     ensure_site(om)
      ... except TypeError:
      ...     # not supposed to do anything unless enableLocalSiteHook was found
      ...     if enableLocalSiteHook is None:
      ...         True
      True
    """

    if not IPossibleSite.providedBy(context):
        if hasattr(context, 'getPhysicalPath'):
            p = '/'.join(context.getPhysicalPath())
        elif hasattr(context, 'getId'):
            p = context.getId()
        elif hasattr(context, 'id'):
            p = id
        else:
            p = str(context)

        raise TypeError('The object, "%s", is not an IPossibleSite' % p)

    if not ISite.providedBy(context):
        if enableLocalSiteHook is not None:
            enableLocalSiteHook(context)
            setSite(context)
        else:
            raise TypeError('"%s" is not configured as an ISite' %
                            '/'.join(context.getPhysicalPath()))

    if not ISite.providedBy(context):
        raise TypeError('Somehow trying to configure "%s" as an ISite '
                        'has failed' % '/'.join(context.getPhysicalPath()))
开发者ID:collective,项目名称:p4a.common,代码行数:51,代码来源:site.py

示例5: registerService

def registerService(context, id, service, interface):
    """Set and register the service id, using interface.
    """
    if not ISite.providedBy(context.aq_base):
        site = context.Destination()
        if not ISite.providedBy(site):
            raise BadRequest("A service can only be created in a local site")
    else:
        site = context
    site._setObject(id, service)
    service = site._getOb(id)
    sm = site.getSiteManager()
    sm.registerUtility(service, interface)
    return service
开发者ID:silvacms,项目名称:silva.core.conf,代码行数:14,代码来源:utils.py

示例6: silva_session_arg_generator

def silva_session_arg_generator(parent):
    root, options = parent.next()

    if not hasattr(options, 'paths') or not len(options.paths):
        fail(u"specifiy at least one Silva root path")

    for path in options.paths:
        try:
            silva = root.unrestrictedTraverse(path)
        except KeyError:
            fail("%s is not a valid Zope path" % path)
        if not IRoot.providedBy(silva):
            fail("%s is not a valid Silva root" % path)
        if ISite.providedBy(silva):
            setSite(silva)
        else:
            setSite(None)
        setHooks()

        if hasattr(options, 'username') and options.username:
            user = zope_find_user(silva, options.username)
            newSecurityManager(None, user)

        yield silva, options

    try:
        parent.next()
    except StopIteration:
        pass
    else:
        fail(u"internal error")
开发者ID:silvacms,项目名称:silva.system.utils,代码行数:31,代码来源:script.py

示例7: test_enable_site

 def test_enable_site(self):
     """Event handler should have configured local sitemanager."""
     mnet = self.portal['maastricht']
     self.assertTrue(ISite.providedBy(mnet))
     self.assertTrue(IObjectManagerSite.providedBy(mnet))
     self.assertNotEquals(self.portal.getSiteManager(),
                          mnet.getSiteManager())
开发者ID:cosent,项目名称:cultact.subsite,代码行数:7,代码来源:test_subsite.py

示例8: enableZope3Site

def enableZope3Site(context):
    portal = getToolByName(context, 'portal_url').getPortalObject()
    if not ISite.providedBy(portal):
        make_objectmanager_site(portal)
        logger.info('Made the portal a Zope3 site.')
    try:
        components = portal.getSiteManager()
    except ComponentLookupError:
        next = find_next_sitemanager(portal)
        if next is None:
            next = base
        name = '/'.join(portal.getPhysicalPath())
        components = PersistentComponents(name, (next,))
        components.__parent__ = portal
        portal.setSiteManager(components)
        logger.info("Site manager '%s' added." % name)
    else:
        if components.utilities.LookupClass != FiveVerifyingAdapterLookup:
            # for CMF 2.1 beta instances
            components.__parent__ = portal
            components.utilities.LookupClass = FiveVerifyingAdapterLookup
            components.utilities._createLookup()
            components.utilities.__parent__ = components
            logger.info('LookupClass replaced.')
    # Make sure to set the new site as the new active one
    setSite(portal)
开发者ID:gbastien,项目名称:plone.app.upgrade,代码行数:26,代码来源:alphas.py

示例9: findSite

def findSite(container):
    """Return the nearest site.
    """

    if ISite.providedBy(container):
        return container
    return findNextSite(container)
开发者ID:silvacms,项目名称:silva.core.layout,代码行数:7,代码来源:utils.py

示例10: SilvaZMIFilter

    def SilvaZMIFilter(container, filter_addable=False):
        if filter_addable and not zmi_addable:
            return False
        try:
            inside_silva = interfaces.IRoot.providedBy(container.get_root())
        except AttributeError:
            inside_silva = False
        if not inside_silva:
            # Outsite of Silva, you can only add a Silva Root.
            return interfaces.IRoot.implementedBy(content)

        if interfaces.IZMIObject.implementedBy(content):
            if interfaces.ISilvaLocalService.implementedBy(content):
                # Add local service in a site.
                return ISite.providedBy(container)
            # ZMIObject are addable, but not the non-local services
            # (they must be installed).
            return not interfaces.ISilvaService.implementedBy(content)

        if interfaces.IRoot.implementedBy(content):
            # Silva Root are not addable inside Silva.
            return False

        if interfaces.IContainer.providedBy(container):
            # In a Container, you can add content.
            return interfaces.ISilvaObject.implementedBy(content)

        if interfaces.IVersionedObject.providedBy(container):
            # In a Versioned object, you can add version.
            return interfaces.IVersion.implementedBy(content)

        return False
开发者ID:silvacms,项目名称:silva.core.conf,代码行数:32,代码来源:utils.py

示例11: validate

    def validate(self, context):
        if context is self.startpoint:
            return False

        if ISite.providedBy(context):
            for obj in context.objectValues():
                if IFilesService.providedBy(obj):
                    raise StopIteration()
        return False
开发者ID:silvacms,项目名称:Products.Silva,代码行数:9,代码来源:service.py

示例12: activate

def activate(context):
    """Change the context to a local site.
    """
    if not ISite.providedBy(context):
        create_new_sm(context)
    sm = context.getSiteManager()
    if IFiveSiteManager is not None and IFiveSiteManager.providedBy(sm):
        clean_old_five_sm(context, create=True)
    setup_intid(context)
开发者ID:Acidburn0zzz,项目名称:silva.core.upgrade,代码行数:9,代码来源:localsite.py

示例13: closest_short_url_service

def closest_short_url_service(location):
    # XXX Why not use getUtility ?
    while location:
        if ISite.providedBy(location):
            service = location._getOb(SERVICE_NAME, None)
            if service is not None and \
                    IShortURLService.providedBy(service):
                return service
        location = aq_parent(location)
    return None
开发者ID:silvacms,项目名称:silva.app.shorturl,代码行数:10,代码来源:service.py

示例14: test_utility_only_in_local_site

    def test_utility_only_in_local_site(self):
        # A service_customization can be added only in a local site.
        self.assertTrue(ISite.providedBy(self.root))

        factory = self.root.manage_addProduct['Silva']
        factory.manage_addPublication('publication', 'Publication')
        self.publication = self.root.publication

        self.assertFalse(ISite.providedBy(self.publication))
        factory = self.publication.manage_addProduct['silva.core.layout']
        self.assertRaises(BadRequest,
                          factory.manage_addCustomizationService,
                          'service_customization')

        # Now our publication become a local site.
        make_objectmanager_site(self.publication)
        self.assertTrue(ISite.providedBy(self.publication))
        factory = self.publication.manage_addProduct['silva.core.layout']
        factory.manage_addCustomizationService('service_customization')
        self.assertTrue(hasattr(self.publication, 'service_customization'))
开发者ID:silvacms,项目名称:silva.core.layout,代码行数:20,代码来源:test_customization.py

示例15: find_next_sitemanager

def find_next_sitemanager(site):
    """Find the closest sitemanager that is not the specified site's
    sitemanager.
    """
    while True:
        site = get_parent(site, default=None)
        if site is None:
            return None

        if ISite.providedBy(site):
            return site.getSiteManager()
开发者ID:CGTIC,项目名称:Plone_SP,代码行数:11,代码来源:__init__.py


注:本文中的zope.location.interfaces.ISite类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。