[Zope3-checkins] CVS: Zope3/src/zope/app/folder -
__init__.py:1.1.2.1 configure.zcml:1.1.2.1 folder.py:1.1.2.1
fssync.py:1.1.2.1 interfaces.py:1.1.2.1
Philipp von Weitershausen
philikon at philikon.de
Fri Feb 20 14:37:50 EST 2004
Update of /cvs-repository/Zope3/src/zope/app/folder
In directory cvs.zope.org:/tmp/cvs-serv20744/folder
Added Files:
Tag: philikon-movecontent-branch
__init__.py configure.zcml folder.py fssync.py interfaces.py
Log Message:
Combined all folder stuff in zope.app.folder.
=== Added File Zope3/src/zope/app/folder/__init__.py ===
##############################################################################
#
# 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: __init__.py,v 1.1.2.1 2004/02/20 19:37:49 philikon Exp $
"""
from folder import Folder, rootFolder
=== Added File Zope3/src/zope/app/folder/configure.zcml ===
<configure
xmlns="http://namespaces.zope.org/zope"
xmlns:fssync='http://namespaces.zope.org/fssync'
i18n_domain="zope"
>
<!-- Module alias for backward compat -->
<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>
=== Added File Zope3/src/zope/app/folder/folder.py ===
##############################################################################
#
# 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: folder.py,v 1.1.2.1 2004/02/20 19:37:49 philikon Exp $
"""
from persistence import Persistent
from zodb.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
=== Added File Zope3/src/zope/app/folder/fssync.py ===
##############################################################################
#
# 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: fssync.py,v 1.1.2.1 2004/02/20 19:37:49 philikon Exp $
"""
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
=== Added File Zope3/src/zope/app/folder/interfaces.py ===
##############################################################################
#
# 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.
#
##############################################################################
"""
$Id: interfaces.py,v 1.1.2.1 2004/02/20 19:37:49 philikon Exp $
"""
from zope.interface import Interface
from zope.app.interfaces.container import IAdding
from zope.app.interfaces.traversing import IContainmentRoot
from zope.app.interfaces.container import IContainer, IContentContainer
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
More information about the Zope3-Checkins
mailing list