[Zope3-checkins] CVS: Zope3/src/zope/app/content - configure.zcml:1.11 file.py:1.5 folder.py:1.6 image.py:1.5 zpt.py:1.6
Jim Fulton
jim@zope.com
Mon, 3 Feb 2003 10:09:35 -0500
Update of /cvs-repository/Zope3/src/zope/app/content
In directory cvs.zope.org:/tmp/cvs-serv15846/src/zope/app/content
Modified Files:
configure.zcml file.py folder.py image.py zpt.py
Log Message:
Refactored the ftp framework to make it much simpler, less general,
and easier to maintain. This included ripping out the vfs framework.
=== Zope3/src/zope/app/content/configure.zcml 1.10 => 1.11 ===
--- Zope3/src/zope/app/content/configure.zcml:1.10 Sun Jan 26 07:13:50 2003
+++ Zope3/src/zope/app/content/configure.zcml Mon Feb 3 10:08:32 2003
@@ -40,6 +40,27 @@
</content>
+<adapter
+ for="zope.app.interfaces.content.folder.IFolder"
+ provides="zope.app.interfaces.file.IDirectoryFactory"
+ factory="zope.app.container.directory.Cloner"
+ permission="zope.ManageContent"
+ />
+
+<adapter
+ for="zope.app.interfaces.content.folder.IFolder"
+ provides="zope.app.interfaces.file.IFileFactory"
+ factory="zope.app.content.image.FileFactory"
+ permission="zope.ManageContent"
+ />
+
+<adapter
+ for="zope.app.interfaces.content.folder.IFolder"
+ provides="zope.app.interfaces.file.IReadDirectory"
+ factory="zope.app.content.folder.ReadDirectory"
+ permission="zope.View"
+ />
+
<!-- XXX Do we really need RootFolder? -->
<content class="zope.app.content.folder.RootFolder">
@@ -140,6 +161,28 @@
</content>
+<adapter
+ for="zope.app.interfaces.content.folder.IFolder"
+ provides="zope.app.interfaces.file.IFileFactory"
+ name=".pt"
+ factory=".zpt.ZPTFactory"
+ permission="zope.ManageContent"
+ />
+
+<adapter
+ for="zope.app.interfaces.content.zpt.IZPTPage"
+ provides="zope.app.interfaces.file.IReadFile"
+ factory=".zpt.ZPTReadFile"
+ permission="zope.ManageContent"
+ />
+
+<adapter
+ for="zope.app.interfaces.content.zpt.IZPTPage"
+ provides="zope.app.interfaces.file.IWriteFile"
+ factory=".zpt.ZPTWriteFile"
+ permission="zope.ManageContent"
+ />
+
<adapter factory="zope.app.content.zpt.SearchableText"
provides="zope.app.interfaces.index.text.ISearchableText"
for="zope.app.interfaces.content.zpt.IZPTPage" />
@@ -195,6 +238,21 @@
/>
</content>
+
+<adapter
+ for="zope.app.interfaces.content.file.IFile"
+ provides="zope.app.interfaces.file.IReadFile"
+ factory=".file.FileReadFile"
+ permission="zope.View"
+ />
+
+<adapter
+ for="zope.app.interfaces.content.file.IFile"
+ provides="zope.app.interfaces.file.IWriteFile"
+ factory=".file.FileWriteFile"
+ permission="zope.ManageContent"
+ />
+
<content class="zope.app.content.i18nfile.I18nFile">
=== Zope3/src/zope/app/content/file.py 1.4 => 1.5 ===
--- Zope3/src/zope/app/content/file.py:1.4 Tue Dec 31 15:15:02 2002
+++ Zope3/src/zope/app/content/file.py Mon Feb 3 10:08:32 2003
@@ -27,7 +27,6 @@
from zope.app.interfaces.dublincore import IZopeDublinCore
from zope.app.interfaces.content.file import IFile, IReadFile
-
# set the size of the chunks
MAXCHUNKSIZE = 1 << 16
@@ -226,3 +225,24 @@
next = self.next
return ''.join(result)
+
+# Adapters for file-system style access
+
+class FileReadFile:
+
+ def __init__(self, context):
+ self.context = context
+
+ def read(self):
+ return self.context.getData()
+
+ def size(self):
+ return len(self.context.getData())
+
+class FileWriteFile:
+
+ def __init__(self, context):
+ self.context = context
+
+ def write(self, data):
+ self.context.setData(data)
=== Zope3/src/zope/app/content/folder.py 1.5 => 1.6 ===
--- Zope3/src/zope/app/content/folder.py:1.5 Fri Jan 17 14:17:32 2003
+++ Zope3/src/zope/app/content/folder.py Mon Feb 3 10:08:32 2003
@@ -102,3 +102,50 @@
"""The standard Zope root Folder implementation."""
__implements__ = Folder.__implements__, IRootFolder
+
+
+# Adapter to provide a file-system rendition of folders
+
+class ReadDirectory:
+
+ def __init__(self, context):
+ self.context = context
+
+ def keys(self):
+ keys = self.context.keys()
+ if self.context.hasServiceManager():
+ return list(keys) + ['++etc++Services']
+ return keys
+
+ def get(self, key, default=None):
+ if key == '++etc++Services' and self.context.hasServiceManager():
+ return self.context.getServiceManager()
+
+ 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 self.context.hasServiceManager():
+ 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
+
+
=== Zope3/src/zope/app/content/image.py 1.4 => 1.5 ===
--- Zope3/src/zope/app/content/image.py:1.4 Mon Dec 30 09:02:56 2002
+++ Zope3/src/zope/app/content/image.py Mon Feb 3 10:08:32 2003
@@ -21,6 +21,8 @@
from zope.app.interfaces.size import ISized
from zope.app.size import byteDisplay
+from zope.app.content_types import guess_content_type
+
__metaclass__ = type
class Image(File):
@@ -130,3 +132,20 @@
pass
return content_type, width, height
+
+
+class FileFactory:
+
+ def __init__(self, context):
+ self.context = context
+
+ def __call__(self, name, content_type, data):
+ if not content_type and data:
+ content_type, width, height = getImageInfo(data)
+ if not content_type:
+ content_type, encoding = guess_content_type(name, data, '')
+
+ if content_type.startswith('image/'):
+ return Image(data)
+
+ return File(data, content_type)
=== Zope3/src/zope/app/content/zpt.py 1.5 => 1.6 ===
--- Zope3/src/zope/app/content/zpt.py:1.5 Mon Dec 30 11:41:21 2002
+++ Zope3/src/zope/app/content/zpt.py Mon Feb 3 10:08:32 2003
@@ -29,6 +29,8 @@
from zope.app.interfaces.size import ISized
from zope.app.interfaces.content.zpt import IZPTPage, IRenderZPTPage
+from zope.app.interfaces.file import IReadFile, IWriteFile, IFileFactory
+
__metaclass__ = type
class ZPTPage(AppPT, PageTemplate, Persistent):
@@ -114,3 +116,42 @@
return '1 line'
return '%s lines' % self.num_lines
+# File-system access adapters
+
+class ZPTReadFile:
+
+ __implements__ = IReadFile
+
+ def __init__(self, context):
+ self.context = context
+
+ def read(self):
+ return self.context.getSource()
+
+ def size(self):
+ return len(self.read())
+
+class ZPTWriteFile:
+
+ __implements__ = IWriteFile
+
+ def __init__(self, context):
+ self.context = context
+
+ def write(self, data):
+ # XXX Hm, how does one figure out an ftp encoding. Waaa.
+ self.context.setSource(unicode(data), None)
+
+class ZPTFactory:
+
+ __implements__ = IFileFactory
+
+
+ def __init__(self, context):
+ self.context = context
+
+ def __call__(self, name, content_type, data):
+ r = ZPTPage()
+ # XXX Hm, how does one figure out an ftp encoding. Waaa.
+ r.setSource(unicode(data), content_type or 'text/html')
+ return r