[Zope3-checkins] SVN: Zope3/trunk/src/zope/app/zapi/ Added 2 new methods to ztapi, getSite and principals.

Jim Fulton jim at zope.com
Fri Oct 22 15:14:38 EDT 2004


Log message for revision 28240:
  Added 2 new methods to ztapi, getSite and principals.
  
  The later returns the auth service (which one day won't be a service).
  

Changed:
  A   Zope3/trunk/src/zope/app/zapi/README.txt
  U   Zope3/trunk/src/zope/app/zapi/__init__.py
  U   Zope3/trunk/src/zope/app/zapi/interfaces.py
  A   Zope3/trunk/src/zope/app/zapi/tests.py

-=-
Added: Zope3/trunk/src/zope/app/zapi/README.txt
===================================================================
--- Zope3/trunk/src/zope/app/zapi/README.txt	2004-10-22 16:52:15 UTC (rev 28239)
+++ Zope3/trunk/src/zope/app/zapi/README.txt	2004-10-22 19:14:37 UTC (rev 28240)
@@ -0,0 +1,40 @@
+Zope Application Programming Interface
+======================================
+
+This package provides a collection of commonly used APIs to make
+imports simpler.
+
+Mostly, the APIs provided here are imported from elsewhere. A few are
+provided here.
+
+principals()
+------------
+
+The principals method returns the authentication service. If no
+service is defined, a ComponentLookupError is raised:
+
+  >>> from zope.app import zapi
+  >>> zapi.principals()
+  Traceback (most recent call last):
+  ...
+  ComponentLookupError: 'Authentication'
+
+But if we provide an authentication service:
+
+  >>> import zope.interface
+  >>> from zope.app.security.interfaces import IAuthenticationService
+  >>> class FakeAuthenticationService:
+  ...     zope.interface.implements(IAuthenticationService)
+  >>> fake = FakeAuthenticationService()
+  
+  >>> from zope.app.tests import ztapi
+  >>> ztapi.provideService(zapi.servicenames.Authentication, fake)
+
+Then we should be able to get the service back when we ask for the
+principals: 
+
+  >>> zapi.principals() is fake
+  True
+
+    
+


Property changes on: Zope3/trunk/src/zope/app/zapi/README.txt
___________________________________________________________________
Name: svn:eol-style
   + native

Modified: Zope3/trunk/src/zope/app/zapi/__init__.py
===================================================================
--- Zope3/trunk/src/zope/app/zapi/__init__.py	2004-10-22 16:52:15 UTC (rev 28239)
+++ Zope3/trunk/src/zope/app/zapi/__init__.py	2004-10-22 19:14:37 UTC (rev 28240)
@@ -36,3 +36,7 @@
 from zope.app.exception.interfaces import UserError
 
 name = getName
+
+def principals():
+    return getServices().getService(servicenames.Authentication)
+

Modified: Zope3/trunk/src/zope/app/zapi/interfaces.py
===================================================================
--- Zope3/trunk/src/zope/app/zapi/interfaces.py	2004-10-22 16:52:15 UTC (rev 28239)
+++ Zope3/trunk/src/zope/app/zapi/interfaces.py	2004-10-22 19:14:37 UTC (rev 28240)
@@ -76,3 +76,12 @@
         This function is useful because it works even if the instance
         is security proxied.
         """
+
+    def site():
+        """Return the current (thread-local) site
+        """
+
+    def principals():
+        """Return the authentication service (someday utility)
+        """
+        

Added: Zope3/trunk/src/zope/app/zapi/tests.py
===================================================================
--- Zope3/trunk/src/zope/app/zapi/tests.py	2004-10-22 16:52:15 UTC (rev 28239)
+++ Zope3/trunk/src/zope/app/zapi/tests.py	2004-10-22 19:14:37 UTC (rev 28240)
@@ -0,0 +1,39 @@
+##############################################################################
+#
+# Copyright (c) 2004 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.0 (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.
+#
+##############################################################################
+"""XXX short summary goes here.
+
+$Id$
+"""
+import unittest
+from zope.app.tests import placelesssetup
+from zope.app import zapi
+from zope.app.security.interfaces import IAuthenticationService
+
+
+def setUp(test):
+    placelesssetup.setUp()
+    services = zapi.getGlobalServices()
+    services.defineService(zapi.servicenames.Authentication,
+                           IAuthenticationService)
+
+def test_suite():
+    from zope.testing import doctest
+    return unittest.TestSuite((
+        doctest.DocFileSuite('README.txt',
+                             setUp=setUp, tearDown=placelesssetup.tearDown),
+        ))
+
+if __name__ == '__main__':
+    unittest.main(defaultTest='test_suite')
+


Property changes on: Zope3/trunk/src/zope/app/zapi/tests.py
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native



More information about the Zope3-Checkins mailing list