[Checkins] SVN: zf.zscp/trunk/src/zf/zscp/ Implemented doc tests

Roger Ineichen roger at projekt01.ch
Sat Apr 8 17:31:38 EDT 2006


Log message for revision 66695:
  Implemented doc tests
  Started adding ZSCPSite as a Site
  Added object added event handler which adds and setup PAU
  

Changed:
  U   zf.zscp/trunk/src/zf/zscp/certification.txt
  U   zf.zscp/trunk/src/zf/zscp/publication.py
  U   zf.zscp/trunk/src/zf/zscp/release.txt
  A   zf.zscp/trunk/src/zf/zscp/website/README.txt
  A   zf.zscp/trunk/src/zf/zscp/website/browser/
  A   zf.zscp/trunk/src/zf/zscp/website/browser/__init__.py
  A   zf.zscp/trunk/src/zf/zscp/website/browser/configure.zcml
  A   zf.zscp/trunk/src/zf/zscp/website/browser/zscp.py
  U   zf.zscp/trunk/src/zf/zscp/website/configure.zcml
  A   zf.zscp/trunk/src/zf/zscp/website/ftests.py
  U   zf.zscp/trunk/src/zf/zscp/website/interfaces.py
  U   zf.zscp/trunk/src/zf/zscp/website/zscp.py
  U   zf.zscp/trunk/src/zf/zscp/zscp.py

-=-
Modified: zf.zscp/trunk/src/zf/zscp/certification.txt
===================================================================
--- zf.zscp/trunk/src/zf/zscp/certification.txt	2006-04-08 21:31:23 UTC (rev 66694)
+++ zf.zscp/trunk/src/zf/zscp/certification.txt	2006-04-08 21:31:37 UTC (rev 66695)
@@ -84,7 +84,7 @@
   Traceback (most recent call last):
   ...
   RequiredElementsMissing: Required field(s) 'action', 'date' missing in
-                           `certification` (file "<string>", line 10, column 17)
+                           `certification` (file "<string>", line ...)
 
 And finally a full file of content:
 

Modified: zf.zscp/trunk/src/zf/zscp/publication.py
===================================================================
--- zf.zscp/trunk/src/zf/zscp/publication.py	2006-04-08 21:31:23 UTC (rev 66694)
+++ zf.zscp/trunk/src/zf/zscp/publication.py	2006-04-08 21:31:37 UTC (rev 66695)
@@ -17,7 +17,6 @@
 """
 __docformat__ = "reStructuredText"
 import zope.interface
-import zope.schema
 
 from zf.zscp import interfaces, fileformat
 

Modified: zf.zscp/trunk/src/zf/zscp/release.txt
===================================================================
--- zf.zscp/trunk/src/zf/zscp/release.txt	2006-04-08 21:31:23 UTC (rev 66694)
+++ zf.zscp/trunk/src/zf/zscp/release.txt	2006-04-08 21:31:37 UTC (rev 66695)
@@ -78,7 +78,7 @@
   Traceback (most recent call last):
   ...
   RequiredElementsMissing: Required field(s) 'date', 'version' missing in
-                           `release` (file "<string>", line 7, column 11)
+                           `release` (file "<string>", line ...)
 
 If a required field is missing that has a default value, the default is simply
 used:
@@ -118,7 +118,7 @@
   Traceback (most recent call last):
   ...
   InvalidSubElement: `name` cannot have sub-elements
-                     (file "<string>", line 6, column 14)
+                     (file "<string>", line ...)
 
 
 Let's now have a look at a complex element within the release. The release

Added: zf.zscp/trunk/src/zf/zscp/website/README.txt
===================================================================
--- zf.zscp/trunk/src/zf/zscp/website/README.txt	2006-04-08 21:31:23 UTC (rev 66694)
+++ zf.zscp/trunk/src/zf/zscp/website/README.txt	2006-04-08 21:31:37 UTC (rev 66695)
@@ -0,0 +1,33 @@
+=========
+ZSCP Site
+=========
+
+Let's setup a ZSCP site:
+
+  >>> from zf.zscp.website import zscp
+  >>> zscp = zscp.ZSCPSite()
+
+  # Add the site to the root, so it is fully located.
+  >>> from zope.app.folder import rootFolder
+  >>> root = rootFolder()
+  >>> root[u'zscp'] = zscp
+
+  >>> from zf.zscp.website.zscp import addAuthenticationUtilityToSite
+  >>> addAuthenticationUtilityToSite(zscp, None)
+
+The object added event will normaly add the authentication utility:
+
+  >>> from zope.app.component import hooks
+  >>> hooks.setSite(zscp)
+
+we can get the authentication utility with a simple lookup:
+
+  >>> import zope.component
+  >>> from zope.app import security
+  >>> auth = zope.component.getUtility(security.interfaces.IAuthentication)
+
+Since this authentication utility is a pluggable authentication utility, we
+can ask it for all its authenticator plugins.
+
+  >>> sorted(auth.getAuthenticatorPlugins())
+  [(u'principals', <...principalfolder.PrincipalFolder ...>)]


Property changes on: zf.zscp/trunk/src/zf/zscp/website/README.txt
___________________________________________________________________
Name: svn:eol-style
   + native

Added: zf.zscp/trunk/src/zf/zscp/website/browser/__init__.py
===================================================================
--- zf.zscp/trunk/src/zf/zscp/website/browser/__init__.py	2006-04-08 21:31:23 UTC (rev 66694)
+++ zf.zscp/trunk/src/zf/zscp/website/browser/__init__.py	2006-04-08 21:31:37 UTC (rev 66695)
@@ -0,0 +1 @@
+# Make a pacakge.


Property changes on: zf.zscp/trunk/src/zf/zscp/website/browser/__init__.py
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Added: zf.zscp/trunk/src/zf/zscp/website/browser/configure.zcml
===================================================================
--- zf.zscp/trunk/src/zf/zscp/website/browser/configure.zcml	2006-04-08 21:31:23 UTC (rev 66694)
+++ zf.zscp/trunk/src/zf/zscp/website/browser/configure.zcml	2006-04-08 21:31:37 UTC (rev 66695)
@@ -0,0 +1,24 @@
+<configure
+   xmlns:zope="http://namespaces.zope.org/zope"
+   xmlns="http://namespaces.zope.org/browser"
+    i18n_domain="zf.zscp">
+
+  <addform
+      schema="zf.zscp.website.interfaces.IZSCPSite"
+      label="Add ZSCP Site"
+      content_factory="zf.zscp.website.zscp.ZSCPSite"
+      fields="certificationDir"
+      keyword_arguments="certificationDir"
+      name="AddZSCPSite.html"
+      permission="zope.ManageServices"
+      />
+
+  <addMenuItem
+       view="AddZSCPSite.html"
+       class="zf.zscp.website.zscp.ZSCPSite"
+       title="ZSCP website"
+       description="The ZSCP website"
+       permission="zope.ManageContent"
+       />
+
+</configure>


Property changes on: zf.zscp/trunk/src/zf/zscp/website/browser/configure.zcml
___________________________________________________________________
Name: svn:eol-style
   + native

Added: zf.zscp/trunk/src/zf/zscp/website/browser/zscp.py
===================================================================
--- zf.zscp/trunk/src/zf/zscp/website/browser/zscp.py	2006-04-08 21:31:23 UTC (rev 66694)
+++ zf.zscp/trunk/src/zf/zscp/website/browser/zscp.py	2006-04-08 21:31:37 UTC (rev 66695)
@@ -0,0 +1 @@
+# Make a pacakge.


Property changes on: zf.zscp/trunk/src/zf/zscp/website/browser/zscp.py
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Modified: zf.zscp/trunk/src/zf/zscp/website/configure.zcml
===================================================================
--- zf.zscp/trunk/src/zf/zscp/website/configure.zcml	2006-04-08 21:31:23 UTC (rev 66694)
+++ zf.zscp/trunk/src/zf/zscp/website/configure.zcml	2006-04-08 21:31:37 UTC (rev 66695)
@@ -1,6 +1,26 @@
 <configure
    xmlns="http://namespaces.zope.org/zope"
-  i18n_domain="zf.zscp"   
-   >
+   i18n_domain="zf.zscp">
 
+  <class class=".zscp.ZSCPSite">
+    <factory id="zf.zscp.website.interfaces.IZSCPSite" />
+    <require
+        permission="zope.Public"
+        interface=".interfaces.IZSCPSite"
+        />
+    <require
+        permission="zope.ManageContent"
+        set_schema=".interfaces.IZSCPSite"
+        />
+  </class>
+
+
+  <subscriber
+      for="zf.zscp.website.interfaces.IZSCPSite
+           zope.app.container.interfaces.IObjectAddedEvent"
+      handler=".zscp.addAuthenticationUtilityToSite"
+      />
+
+   <include package=".browser" />
+
 </configure>

Added: zf.zscp/trunk/src/zf/zscp/website/ftests.py
===================================================================
--- zf.zscp/trunk/src/zf/zscp/website/ftests.py	2006-04-08 21:31:23 UTC (rev 66694)
+++ zf.zscp/trunk/src/zf/zscp/website/ftests.py	2006-04-08 21:31:37 UTC (rev 66695)
@@ -0,0 +1,37 @@
+##############################################################################
+#
+# Copyright (c) 2005 Zope Corporation 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.
+#
+##############################################################################
+"""ZSCP Web Site
+
+$Id:$
+"""
+import unittest
+
+from zope.testing import doctest
+from zope.app.testing import functional
+
+def getRootFolder():
+    return functional.FunctionalTestSetup().getRootFolder()
+
+
+def test_suite():
+    return unittest.TestSuite((
+        functional.FunctionalDocFileSuite(
+            "README.txt",
+            optionflags=doctest.ELLIPSIS | doctest.NORMALIZE_WHITESPACE,
+            globs={'getRootFolder': getRootFolder}),
+        ))
+
+
+if __name__ == '__main__':
+    unittest.main(defaultTest='test_suite')


Property changes on: zf.zscp/trunk/src/zf/zscp/website/ftests.py
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Modified: zf.zscp/trunk/src/zf/zscp/website/interfaces.py
===================================================================
--- zf.zscp/trunk/src/zf/zscp/website/interfaces.py	2006-04-08 21:31:23 UTC (rev 66694)
+++ zf.zscp/trunk/src/zf/zscp/website/interfaces.py	2006-04-08 21:31:37 UTC (rev 66695)
@@ -16,10 +16,27 @@
 $Id$
 """
 __docformat__ = "reStructuredText"
+import os.path
+import zope.schema
 from zope.app import folder
+from zf.zscp.i18n import MessageFactory as _
 
+
+def isDirectory(path):
+    if path:
+        return os.path.isdir(path)
+    else:
+        return True
+
+
 class IZSCPSite(folder.interfaces.IFolder):
     """The root object for the ZSCP site.
 
     The site mainly contains ZSCP repository objects.
     """
+
+    certificationDir = zope.schema.TextLine(title=_(u'Path'),
+        description=_(u'Path to the directory.'),
+        required=False,
+        constraint=isDirectory,
+        max_length=255)

Modified: zf.zscp/trunk/src/zf/zscp/website/zscp.py
===================================================================
--- zf.zscp/trunk/src/zf/zscp/website/zscp.py	2006-04-08 21:31:23 UTC (rev 66694)
+++ zf.zscp/trunk/src/zf/zscp/website/zscp.py	2006-04-08 21:31:37 UTC (rev 66695)
@@ -16,14 +16,139 @@
 $Id$
 """
 __docformat__ = "reStructuredText"
+
+from zope.schema.fieldproperty import FieldProperty
+import zope.component
 import zope.interface
+import zope.interface
+
+from zope.app import container
 from zope.app import folder
+from zope.app import security, zapi
+from zope.app import zapi
+from zope.app.authentication import principalfolder
+from zope.app.authentication import authentication
+from zope.app.component import site
+from zope.app.component.interfaces import ISite
+from zope.app.component.interfaces.registration import ActiveStatus
+from zope.app.component.site import SiteManagementFolder
+from zope.app.container.interfaces import INameChooser
+from zope.app.event import objectevent
+from zope.app.utility import UtilityRegistration
 
 from zf.zscp.website import interfaces
 
 
 class ZSCPSite(folder.folder.Folder):
-    zope.interface.implements(interface.IZSCPSite)
+    zope.interface.implements(interfaces.IZSCPSite)
 
+    certificationDir = FieldProperty(
+        interfaces.IZSCPSite['certificationDir'])
 
+    def __init__(self, certificationDir=u''):
+        super(ZSCPSite, self).__init__()
+        self.certificationDir = certificationDir
+        self.setSiteManager(site.LocalSiteManager(self))
 
+    def __repr__(self):
+        return '<%s %r>' % (self.__class__.__name__, self.__name__)
+
+
+_marker = object()
+
+def ensureUtility(site, name, interface, utility, package, key):
+    """Add and return the utility."""
+    # preconditions
+    name = unicode(name)
+
+    if not ISite.providedBy(site):
+        raise TypeError('ISite required.')
+
+    # get or create sitemanagement folder (package)
+    sitemanager = site.getSiteManager()
+    try:
+        default = sitemanager[package]
+    except:
+        sitemanager[package] = SiteManagementFolder()
+        default = sitemanager[package]
+
+    # choose class name as key if not given
+    if key == _marker:
+        chooser = container.interfaces.INameChooser(default)
+        key = chooser.chooseName(utility.__name__, utility)
+
+    # add utility to sitemanagement folder
+    default[key] = utility
+
+    # register utility
+    path = zapi.getPath(utility)
+    registration = UtilityRegistration(name, interface, utility)
+    choosenkey = default.registrationManager.addRegistration(registration)
+    component = zapi.traverse(default.registrationManager, choosenkey)
+    component.status = ActiveStatus
+
+    return zapi.traverse(sitemanager, path)
+
+
+# plugable authentication utility
+def addPluggableAuthentication(site, name='', package='default', key=_marker, 
+    prefix=''):
+    """Add a plugable authentication utility (pau) to a site
+
+    The pau is added to the package and activated.
+    This assumes the site has already a Utility Service.
+    """
+
+    interface = security.interfaces.IAuthentication
+    utility = authentication.PluggableAuthentication(prefix)
+
+    return ensureUtility(site, name, interface, utility, package, key)
+
+
+
+# add authenticator plugin
+def addAuthenticatorPlugin(pau, key, utility, name):
+    """Add authenticator plugin."""
+
+    pau.authenticatorPlugins += (name,)
+    package = pau.__name__
+    interface = authentication.interfaces.IAuthenticatorPlugin
+
+    return ensureAuthenticationPlugin(pau, name, interface, utility, key)
+
+
+def ensureAuthenticationPlugin(pau, name, interface, utility, key):
+    """Add and return the utility."""
+    # preconditions
+    name = unicode(name)
+
+    # choose class name as key if not given
+    if key == _marker:
+        chooser = INameChooser(default)
+        key = chooser.chooseName(utility.__name__, utility)
+
+    # add utility to sitemanagement folder
+    pau[key] = utility
+
+    # register utility
+    path = zapi.getPath(utility)
+    registration = UtilityRegistration(name, interface, utility)
+    choosenkey = pau.registrationManager.addRegistration(registration)
+    component = zapi.traverse(pau.registrationManager, choosenkey)
+    component.status = ActiveStatus
+
+    return zapi.traverse(pau, path)
+
+
+
+def addAuthenticationUtilityToSite(ob, event):
+    """Add a pluggable authentication utility to the zscp site."""
+
+    prefix = 'zscp.'
+    pau = addPluggableAuthentication(ob)
+
+    # setup 'principals' principal folder
+    principals = principalfolder.PrincipalFolder(prefix)
+    zope.event.notify(objectevent.ObjectCreatedEvent(principals))
+    principals = addAuthenticatorPlugin(
+        pau, u'principals', principals, u'principals')

Modified: zf.zscp/trunk/src/zf/zscp/zscp.py
===================================================================
--- zf.zscp/trunk/src/zf/zscp/zscp.py	2006-04-08 21:31:23 UTC (rev 66694)
+++ zf.zscp/trunk/src/zf/zscp/zscp.py	2006-04-08 21:31:37 UTC (rev 66695)
@@ -18,14 +18,16 @@
 __docformat__ = "reStructuredText"
 import os
 import os.path
+import persistent
 import pysvn
 import zope.event
 import zope.interface
+from zope.app.container.contained import Contained
 
 from zf.zscp import interfaces, package, publication, release, certification
 
 
-class ZSCPRepository(object):
+class ZSCPRepository(persistent.Persistent, Contained):
     """A ZSCP-compliant repository."""
     zope.interface.implements(interfaces.IZSCPRepository)
 



More information about the Checkins mailing list