[Zope3-checkins] CVS: Zope3/src/zope/app/services - configure.zcml:1.30 folder.py:1.8 pagefolder.py:1.8 zpt.py:1.11

Guido van Rossum guido@python.org
Thu, 29 May 2003 15:55:43 -0400


Update of /cvs-repository/Zope3/src/zope/app/services
In directory cvs.zope.org:/tmp/cvs-serv12071

Modified Files:
	configure.zcml folder.py pagefolder.py zpt.py 
Log Message:
Add fssync support for page folders and zpt templates, and to allow
creation of page folders.


=== Zope3/src/zope/app/services/configure.zcml 1.29 => 1.30 ===
--- Zope3/src/zope/app/services/configure.zcml:1.29	Thu May 15 17:30:44 2003
+++ Zope3/src/zope/app/services/configure.zcml	Thu May 29 15:55:42 2003
@@ -491,4 +491,29 @@
     factory="zope.app.content.fssync.DirectoryAdapter"
     />
 
+<fssync:adapter
+    class=".pagefolder.PageFolder"
+    factory=".pagefolder.PageFolderAdapter"
+    />
+
+<fssync:adapter
+    class=".zpt.ZPTTemplate"
+    factory=".zpt.ZPTPageAdapter"
+    />
+
+<adapter 
+  for="zope.app.interfaces.services.service.IServiceManager"
+  provides="zope.app.interfaces.file.IDirectoryFactory"
+  factory=".folder.SMFolderFactory"
+  permission="zope.ManageContent"
+  />
+
+<adapter 
+  for="zope.app.interfaces.services.folder.ISiteManagementFolder"
+  provides="zope.app.interfaces.file.IDirectoryFactory"
+  factory=".pagefolder.PageFolderFactory"
+  permission="zope.ManageContent"
+  />
+
+
 </zopeConfigure>


=== Zope3/src/zope/app/services/folder.py 1.7 => 1.8 ===
--- Zope3/src/zope/app/services/folder.py:1.7	Tue May 27 10:18:24 2003
+++ Zope3/src/zope/app/services/folder.py	Thu May 29 15:55:42 2003
@@ -23,6 +23,7 @@
 from zope.app.interfaces.services.folder import ISiteManagementFolders
 from zope.app.interfaces.services.folder import ISiteManagementFolder
 from zope.app.interfaces.services.service import IComponentManager
+from zope.app.interfaces.file import IDirectoryFactory
 from zope.app.services.configuration import ConfigurationManagerContainer
 from zope.app.traversing import getPath
 from zope.context import ContextMethod, ContextWrapper
@@ -69,6 +70,16 @@
         if not ISiteManagementFolder.isImplementedBy(obj):
             raise TypeError("Can only add packages")
         return super(SiteManagementFolders, self).setObject(name, obj)
+
+class SMFolderFactory(object):
+
+    __implements__ = IDirectoryFactory
+
+    def __init__(self, context):
+        self.context = context
+
+    def __call__(self, name):
+        return SiteManagementFolder()
 
 # XXX Backward compatability. This is needed to support old pickles.
 Package = SiteManagementFolder


=== Zope3/src/zope/app/services/pagefolder.py 1.7 => 1.8 ===
--- Zope3/src/zope/app/services/pagefolder.py:1.7	Wed May 28 11:46:11 2003
+++ Zope3/src/zope/app/services/pagefolder.py	Thu May 29 15:55:42 2003
@@ -31,6 +31,9 @@
 from zope.app.services.view import PageConfiguration
 from zope.app.interfaces.services.pagefolder import IPageFolder
 from zope.app.interfaces.services.configuration import IConfigurationManager
+from zope.app.interfaces.file import IDirectoryFactory
+from zope.app.fssync.classes import ObjectEntryAdapter, AttrMapping
+from zope.app.interfaces.fssync import IObjectDirectory
 
 class PageFolder(ConfigurationManagerContainer, BTreeContainer):
 
@@ -84,6 +87,36 @@
 
     def deactivated(self):
         "See IConfiguration"
+
+
+_attrNames = (
+    'factoryName',
+    'forInterface',
+    'layer',
+    'permission',
+    )
+
+class PageFolderAdapter(ObjectEntryAdapter):
+    """ObjectFile adapter for PageFolder objects."""
+
+    __implements__ =  IObjectDirectory
+
+    def contents(self):
+        return self.context.items()
+
+    def extra(self):
+        return AttrMapping(self.context, _attrNames)
+
+
+class PageFolderFactory(object):
+
+    __implements__ = IDirectoryFactory
+
+    def __init__(self, context):
+        self.context = context
+
+    def __call__(self, name):
+        return PageFolder()
 
 # XXX Backward compatibility. This is needed to support old pickles.
 ViewPackage = PageFolder


=== Zope3/src/zope/app/services/zpt.py 1.10 => 1.11 ===
--- Zope3/src/zope/app/services/zpt.py:1.10	Thu May  1 15:35:34 2003
+++ Zope3/src/zope/app/services/zpt.py	Thu May 29 15:55:42 2003
@@ -25,6 +25,8 @@
 from zope.app.interfaces.services.view import IZPTTemplate
 from zope.app.interfaces.index.text import ISearchableText
 from zope.app.interfaces.file import IReadFile, IWriteFile, IFileFactory
+from zope.app.fssync.classes import ObjectEntryAdapter, AttrMapping
+from zope.app.interfaces.fssync import IObjectFile
 
 class ZPTTemplate(AppPT, PageTemplate, Persistent):
 
@@ -129,3 +131,21 @@
         r = ZPTTemplate()
         r.source = data
         return r
+
+
+class ZPTPageAdapter(ObjectEntryAdapter):
+    """ObjectFile adapter for ZPTTemplate objects."""
+
+    __implements__ =  IObjectFile
+
+    def getBody(self):
+        return self.context.source
+
+    def setBody(self, data):
+        # Convert the data to Unicode, since that's what ZPTTemplate
+        # wants; it's normally read from a file so it'll be bytes.
+        # XXX This will die if it's not ASCII.  Guess encoding???
+        self.context.source = unicode(data)
+
+    def extra(self):
+        return AttrMapping(self.context, ('contentType',))