[Zope3-checkins] CVS: Zope3/src/zope/app/folder - __init__.py:1.2 configure.zcml:1.2 folder.py:1.2 fssync.py:1.2 interfaces.py:1.2 tests.py:1.2

Philipp von Weitershausen philikon at philikon.de
Tue Feb 24 11:50:30 EST 2004


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

Added Files:
	__init__.py configure.zcml folder.py fssync.py interfaces.py 
	tests.py 
Log Message:


Moved Folder to its own package below zope.app, including its
interfaces and browser views.




=== Zope3/src/zope/app/folder/__init__.py 1.1 => 1.2 ===
--- /dev/null	Tue Feb 24 11:50:30 2004
+++ Zope3/src/zope/app/folder/__init__.py	Tue Feb 24 11:49:59 2004
@@ -0,0 +1,18 @@
+##############################################################################
+#
+# 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.
+#
+##############################################################################
+"""
+$Id$
+"""
+
+from folder import Folder, rootFolder


=== Zope3/src/zope/app/folder/configure.zcml 1.1 => 1.2 ===
--- /dev/null	Tue Feb 24 11:50:30 2004
+++ Zope3/src/zope/app/folder/configure.zcml	Tue Feb 24 11:49:59 2004
@@ -0,0 +1,82 @@
+<configure
+    xmlns="http://namespaces.zope.org/zope"
+    xmlns:fssync='http://namespaces.zope.org/fssync'
+    i18n_domain="zope"
+    >
+
+  <!-- Module alias for backward compat
+       Will go away once we have a conversion script -->
+
+  <modulealias
+      module=".folder"
+      alias="zope.app.content.folder"
+      />
+
+  <modulealias
+      module=".interfaces"
+      alias="zope.app.interfaces.content.folder"
+      />
+
+
+
+  <interface 
+      interface=".interfaces.IFolder" 
+      type="zope.app.interfaces.content.IContentType"
+      /> 
+
+  <content class=".folder.Folder">
+    <factory
+        id="Folder"
+        permission="zope.ManageContent"
+        title="Folder"
+        description="Minimal folder"
+        />
+
+    <allow
+        attributes="getSiteManager"
+        />
+
+    <require
+        permission="zope.ManageServices"
+        attributes="setSiteManager"
+        />
+
+    <require
+        permission="zope.View"
+        interface="zope.app.interfaces.container.IReadContainer" 
+        />
+
+    <require
+        permission="zope.ManageContent"
+        interface="zope.app.interfaces.container.IWriteContainer"
+        />
+  </content>
+
+
+  <!-- fssync directives -->
+
+  <adapter
+      for=".interfaces.IFolder"
+      provides="zope.app.interfaces.file.IDirectoryFactory"
+      factory="zope.app.container.directory.Cloner"
+      permission="zope.ManageContent"
+      />
+
+  <adapter
+      for=".interfaces.IFolder"
+      provides="zope.app.interfaces.file.IReadDirectory"
+      factory=".fssync.ReadDirectory"
+      permission="zope.View"
+      />
+
+  <fssync:adapter
+      class=".folder.Folder"
+      factory=".fssync.FolderAdapter"
+      />
+
+
+  <!-- include browser package -->
+
+  <include package=".browser" />
+
+</configure>


=== Zope3/src/zope/app/folder/folder.py 1.1 => 1.2 ===
--- /dev/null	Tue Feb 24 11:50:30 2004
+++ Zope3/src/zope/app/folder/folder.py	Tue Feb 24 11:49:59 2004
@@ -0,0 +1,112 @@
+##############################################################################
+#
+# Copyright (c) 2001, 2002 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.
+#
+##############################################################################
+"""
+$Id$
+"""
+
+from persistent import Persistent
+from BTrees.OOBTree import OOBTree
+from zope.exceptions import DuplicationError
+from zope.interface import implements, directlyProvides
+
+from zope.app.interfaces.services.service import ISite
+from zope.app.container.contained import Contained, setitem, uncontained
+from zope.app.services.servicecontainer import ServiceManagerContainer
+
+from interfaces import IFolder, IRootFolder
+
+__metaclass__ = type
+
+class Folder(Persistent, ServiceManagerContainer, Contained):
+    """The standard Zope Folder implementation.
+    """
+
+    implements(IFolder)
+
+    def __init__(self):
+        self.data = OOBTree()
+
+    def keys(self):
+        """Return a sequence-like object containing the names
+           associated with the objects that appear in the folder
+        """
+        return self.data.keys()
+
+    def __iter__(self):
+        return iter(self.data.keys())
+
+    def values(self):
+        """Return a sequence-like object containing the objects that
+           appear in the folder.
+        """
+        return self.data.values()
+
+    def items(self):
+        """Return a sequence-like object containing tuples of the form
+           (name, object) for the objects that appear in the folder.
+        """
+        return self.data.items()
+
+    def __getitem__(self, name):
+        """Return the named object, or the value of the default
+           argument if given and the named object is not found.
+           If no default is given and the object is not found a
+           KeyError is raised.
+        """
+        return self.data[name]
+
+    def get(self, name, default=None):
+        """Return the named object, or the value of the default
+           argument if given and the named object is not found.
+           If no default is given and the object is not found a
+           KeyError is raised.
+        """
+        return self.data.get(name, default)
+
+    def __contains__(self, name):
+        """Return true if the named object appears in the folder."""
+        return self.data.has_key(name)
+
+    def __len__(self):
+        """Return the number of objects in the folder."""
+        return len(self.data)
+
+    def __setitem__(self, name, object):
+        """Add the given object to the folder under the given name."""
+
+        if not (isinstance(name, str) or isinstance(name, unicode)):
+            raise TypeError("Name must be a string rather than a %s" %
+                            name.__class__.__name__)
+        try:
+            unicode(name)
+        except UnicodeError:
+            raise TypeError("Non-unicode names must be 7-bit-ascii only")
+        if not name:
+            raise TypeError("Name must not be empty")
+
+        if name in self.data:
+            raise DuplicationError("name, %s, is already in use" % name)
+
+        setitem(self, self.data.__setitem__, name, object)
+
+    def __delitem__(self, name):
+        """Delete the named object from the folder. Raises a KeyError
+           if the object is not found."""
+        uncontained(self.data[name], self, name)
+        del self.data[name]
+
+def rootFolder():
+    f = Folder()
+    directlyProvides(f, IRootFolder)
+    return f


=== Zope3/src/zope/app/folder/fssync.py 1.1 => 1.2 ===
--- /dev/null	Tue Feb 24 11:50:30 2004
+++ Zope3/src/zope/app/folder/fssync.py	Tue Feb 24 11:49:59 2004
@@ -0,0 +1,87 @@
+##############################################################################
+#
+# Copyright (c) 2002 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.
+# 
+##############################################################################
+"""Filesystem synchronization support.
+
+$Id$
+"""
+
+from zope.interface import implements
+from zope.fssync.server.entryadapter import ObjectEntryAdapter, \
+     DirectoryAdapter, AttrMapping
+from zope.fssync.server.interfaces import IContentDirectory
+
+__metaclass__ = type
+
+class RootDirectoryFactory:
+
+    def __init__(self, context):
+        pass
+
+    def __call__(self, name):
+        return Folder()
+
+class ReadDirectory:
+    """Adapter to provide a file-system rendition of folders
+    """
+
+    def __init__(self, context):
+        self.context = context
+
+    def keys(self):
+        keys = self.context.keys()
+        if ISite.isImplementedBy(self.context):
+            return list(keys) + ['++etc++site']
+        return keys
+
+    def get(self, key, default=None):
+        if key == '++etc++site' and ISite.isImplementedBy(self.context):
+            return self.context.getSiteManager()
+
+        return self.context.get(key, default)
+
+    def __iter__(self):
+        return iter(self.keys())
+
+    def __getitem__(self, key):
+        v = self.get(key, self)
+        if v is self:
+            raise KeyError, key
+        return v
+
+    def values(self):
+        return map(self.get, self.keys())
+
+    def __len__(self):
+        l = len(self.context)
+        if ISite.isImplementedBy(self.context):
+            l += 1
+        return l
+
+    def items(self):
+        get = self.get
+        return [(key, get(key)) for key in self.keys()]
+
+    def __contains__(self, key):
+        return self.get(key) is not None
+
+class FolderAdapter(DirectoryAdapter):
+    """Adapter to provide an fssync interpretation of folders
+    """
+
+    def contents(self):
+        result = super(FolderAdapter, self).contents()
+        if ISite.isImplementedBy(self.context):
+            sm = self.context.getSiteManager()
+            result.append(('++etc++site', sm))
+        return result


=== Zope3/src/zope/app/folder/interfaces.py 1.1 => 1.2 ===
--- /dev/null	Tue Feb 24 11:50:30 2004
+++ Zope3/src/zope/app/folder/interfaces.py	Tue Feb 24 11:49:59 2004
@@ -0,0 +1,32 @@
+##############################################################################
+#
+# Copyright (c) 2002 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.
+#
+##############################################################################
+"""Folder interfaces
+
+$Id$
+"""
+from zope.app.interfaces.container import IAdding
+from zope.app.interfaces.container import IContainer, IContentContainer
+from zope.app.interfaces.traversing import IContainmentRoot
+from zope.app.interfaces.services.service import IPossibleSite
+from zope.app.interfaces.annotation import IAttributeAnnotatable
+
+class IFolder(IContainer, IContentContainer, IPossibleSite,
+              IAttributeAnnotatable):
+    """The standard Zope Folder object interface."""
+
+class IRootFolder(IFolder, IContainmentRoot):
+    """The standard Zope root Folder object interface."""
+
+class IFolderAdding(IAdding):
+    pass


=== Zope3/src/zope/app/folder/tests.py 1.1 => 1.2 ===
--- /dev/null	Tue Feb 24 11:50:30 2004
+++ Zope3/src/zope/app/folder/tests.py	Tue Feb 24 11:49:59 2004
@@ -0,0 +1,66 @@
+##############################################################################
+#
+# Copyright (c) 2001, 2002 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.
+#
+##############################################################################
+"""
+$Id$
+"""
+
+from unittest import TestCase, TestSuite, main, makeSuite
+
+from zope.testing.doctestunit import DocTestSuite
+from zope.component import getAdapter
+
+from zope.app.tests import ztapi
+from zope.app.traversing import traverse
+from zope.app.interfaces.dublincore import IZopeDublinCore
+from zope.app.folder.interfaces import IFolder
+from zope.app.dublincore.annotatableadapter import ZDCAnnotatableAdapter
+from zope.app.services.tests.placefulsetup import PlacefulSetup
+from zope.app.component.tests.test_servicemanagercontainer \
+     import BaseTestServiceManagerContainer
+from zope.app.container.tests.test_icontainer import BaseTestIContainer
+from zope.app.container.tests.test_icontainer import DefaultTestData
+
+
+class Test(BaseTestIContainer, BaseTestServiceManagerContainer, TestCase):
+
+    def makeTestObject(self):
+        from zope.app.folder import Folder
+        return Folder()
+
+    def makeTestData(self):
+        return DefaultTestData()
+
+    def getUnknownKey(self):
+        return '10'
+
+    def getBadKeyTypes(self):
+        return [None, ['foo'], 1, '\xf3abc']
+
+
+class FolderMetaDataTest(PlacefulSetup, TestCase):
+
+    def setUp(self):
+        PlacefulSetup.setUp(self)
+        PlacefulSetup.buildFolders(self)
+        ztapi.provideAdapter(IFolder, IZopeDublinCore, ZDCAnnotatableAdapter)
+
+def test_suite():
+    return TestSuite((
+        makeSuite(Test),
+        makeSuite(FolderMetaDataTest),
+        DocTestSuite('zope.app.content'),
+        ))    
+
+if __name__=='__main__':
+    main(defaultTest='test_suite')




More information about the Zope3-Checkins mailing list