[Checkins] SVN: grokcore.site/trunk/src/grokcore/site/ Move IApplication and getApplication from grok itself.

Sylvain Viollon sylvain at infrae.com
Thu Nov 4 09:41:17 EDT 2010


Log message for revision 118203:
  Move IApplication and getApplication from grok itself.
  

Changed:
  U   grokcore.site/trunk/src/grokcore/site/interfaces.py
  A   grokcore.site/trunk/src/grokcore/site/util.py

-=-
Modified: grokcore.site/trunk/src/grokcore/site/interfaces.py
===================================================================
--- grokcore.site/trunk/src/grokcore/site/interfaces.py	2010-11-04 13:28:33 UTC (rev 118202)
+++ grokcore.site/trunk/src/grokcore/site/interfaces.py	2010-11-04 13:41:16 UTC (rev 118203)
@@ -15,6 +15,7 @@
 from zope.interface import Interface, Attribute
 from grokcore.component.interfaces import IGrokcoreComponentAPI
 
+
 class IUtilityInstaller(Interface):
     """This install an utility in a site. Let you have different
     'installation' method if you want (one for Zope2 / Zope3).
@@ -26,6 +27,11 @@
         """
 
 
+class IApplication(Interface):
+    """Interface to mark the local site used as application root.
+    """
+
+
 class IBaseClasses(Interface):
     Site = Attribute("Mixin class for sites.")
     LocalUtility = Attribute("Base class for local utilities.")

Added: grokcore.site/trunk/src/grokcore/site/util.py
===================================================================
--- grokcore.site/trunk/src/grokcore/site/util.py	                        (rev 0)
+++ grokcore.site/trunk/src/grokcore/site/util.py	2010-11-04 13:41:16 UTC (rev 118203)
@@ -0,0 +1,35 @@
+##############################################################################
+#
+# Copyright (c) 2006-2009 Zope Foundation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+
+from grokcore.site.interfaces import IApplication
+from zope.component.hooks import getSite
+
+
+def getApplication(self):
+    """Return the nearest enclosing `grok.Application`.
+
+    Raises ValueError if no Application can be found.
+    """
+    site = getSite()
+    if IApplication.providedBy(site):
+        return site
+    # Another sub-site is within the application. Walk up the object
+    # tree until we get to the an application.
+    obj = site
+    while obj is not None:
+        if IApplication.providedBy(obj):
+            return obj
+        obj = obj.__parent__
+    raise ValueError("No application found.")
+



More information about the checkins mailing list