[Zope3-checkins] CVS: Zope3/src/zope/app/interfaces/content - __init__.py:1.2 file.py:1.2 folder.py:1.2 i18nfile.py:1.2 i18nimage.py:1.2 image.py:1.2 sql.py:1.2

Jim Fulton jim@zope.com
Wed, 25 Dec 2002 09:14:00 -0500


Update of /cvs-repository/Zope3/src/zope/app/interfaces/content
In directory cvs.zope.org:/tmp/cvs-serv15352/src/zope/app/interfaces/content

Added Files:
	__init__.py file.py folder.py i18nfile.py i18nimage.py 
	image.py sql.py 
Log Message:
Grand renaming:

- Renamed most files (especially python modules) to lower case.

- Moved views and interfaces into separate hierarchies within each
  project, where each top-level directory under the zope package
  is a separate project.

- Moved everything to src from lib/python.

  lib/python will eventually go away. I need access to the cvs
  repository to make this happen, however.

There are probably some bits that are broken. All tests pass
and zope runs, but I haven't tried everything. There are a number
of cleanups I'll work on tomorrow.



=== Zope3/src/zope/app/interfaces/content/__init__.py 1.1 => 1.2 ===
--- /dev/null	Wed Dec 25 09:14:00 2002
+++ Zope3/src/zope/app/interfaces/content/__init__.py	Wed Dec 25 09:12:59 2002
@@ -0,0 +1,2 @@
+#
+# This file is necessary to make this directory a package.


=== Zope3/src/zope/app/interfaces/content/file.py 1.1 => 1.2 ===
--- /dev/null	Wed Dec 25 09:14:00 2002
+++ Zope3/src/zope/app/interfaces/content/file.py	Wed Dec 25 09:12:59 2002
@@ -0,0 +1,76 @@
+##############################################################################
+#
+# 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.
+#
+##############################################################################
+"""Basic File interfaces.
+
+$Id$
+"""
+import zope.schema
+
+from zope.interface import Interface
+
+
+class IReadFile(Interface):
+
+    contentType = zope.schema.BytesLine(
+        title = u'Content Type',
+        description=u'The content type identifies the type of data.',
+        default = 'text/plain',
+        )
+
+
+    data = zope.schema.Bytes(
+        title = u'Data',
+        description = u'The actual content of the object.',
+        )
+
+    def getData():
+        """Return the contained data of the object."""
+
+    def getContentType():
+        """Returns the content type of the file using mime-types syntax."""
+
+    def getSize():
+        """Return the byte-size of the data of the object."""
+
+
+class IWriteFile(Interface):
+
+    def edit(data, contentType=None):
+        """Sets the data and the content type for the object.
+
+           Since some implementations will provide their content type
+           through the data, it is good to leave the argument optional.
+        """
+
+    def setData(data):
+        """Rewrite the 'file'."""
+
+    def setContentType(contentType):
+        """Sets the content type of the file."""
+
+
+class IFile(IReadFile, IWriteFile):
+    """The basic methods that are required to implement
+       a file as a Zope Content object.
+
+    """
+
+
+class IFileContent(Interface):
+    """Marker interface for content that can be managed as files.
+
+    The default view for file content has effective URLs that don't end in
+    /.  In particular, if the content included HTML, relative links in
+    the HTML are relative to the container the content is in.
+    """


=== Zope3/src/zope/app/interfaces/content/folder.py 1.1 => 1.2 ===
--- /dev/null	Wed Dec 25 09:14:00 2002
+++ Zope3/src/zope/app/interfaces/content/folder.py	Wed Dec 25 09:12:59 2002
@@ -0,0 +1,31 @@
+##############################################################################
+#
+# 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$
+"""
+
+from zope.app.interfaces.container import IAdding
+from zope.app.interfaces.traversing.containmentroot import IContainmentRoot
+from zope.app.interfaces.container import IContainer
+from zope.app.interfaces.services.service import IServiceManagerContainer
+
+class IFolder(IContainer, IServiceManagerContainer):
+    """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/interfaces/content/i18nfile.py 1.1 => 1.2 ===
--- /dev/null	Wed Dec 25 09:14:00 2002
+++ Zope3/src/zope/app/interfaces/content/i18nfile.py	Wed Dec 25 09:12:59 2002
@@ -0,0 +1,26 @@
+##############################################################################
+#
+# 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 zope.app.interfaces.content.file import IFile
+from zope.interfaces.i18n import II18nAware
+
+class II18nFile(IFile, II18nAware):
+    """I18n aware file interface."""
+
+    def removeLanguage(language):
+        '''Remove translated content for a given language.'''


=== Zope3/src/zope/app/interfaces/content/i18nimage.py 1.1 => 1.2 ===
--- /dev/null	Wed Dec 25 09:14:00 2002
+++ Zope3/src/zope/app/interfaces/content/i18nimage.py	Wed Dec 25 09:12:59 2002
@@ -0,0 +1,59 @@
+##############################################################################
+#
+# 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.
+#
+##############################################################################
+"""
+Revision Information:
+$Id$
+"""
+
+from zope.app.content.image import IImage, Image, getImageInfo
+from zope.app.interfaces.content.i18nfile import II18nFile
+from zope.app.content.i18nfile import I18nFile
+from zope.app.interfaces.annotation import IAnnotatable
+
+
+class II18nImage(II18nFile, IImage):
+    """I18n aware image interface."""
+
+
+class I18nImage(I18nFile):
+    """An internationalized Image object.  Note that images of all
+    languages share the same content type.
+    """
+
+    __implements__ = (
+        II18nImage,
+        IAnnotatable,
+        )
+
+
+    def _create(self, data):
+        return Image(data)
+
+
+    def setData(self, data, language=None):
+        '''See interface IFile'''
+        super(I18nImage, self).setData(data, language)
+
+        if language is None or language == self.getDefaultLanguage():
+            # Uploading for the default language only overrides content
+            # type.  Note: do not use the argument data here, it doesn't
+            # work.
+            contentType = getImageInfo(self.getData(language))[0]
+            if contentType:
+                self.setContentType(contentType)
+
+
+    def getImageSize(self, language=None):
+        '''See interface IImage'''
+        return self._get(language).getImageSize()


=== Zope3/src/zope/app/interfaces/content/image.py 1.1 => 1.2 ===
--- /dev/null	Wed Dec 25 09:14:00 2002
+++ Zope3/src/zope/app/interfaces/content/image.py	Wed Dec 25 09:12:59 2002
@@ -0,0 +1,117 @@
+##############################################################################
+#
+# 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$
+"""
+import struct
+
+from zope.app.content.file import File
+from zope.app.interfaces.content.file import IFile
+from zope.app.interfaces.annotation import IAnnotatable
+from cStringIO import StringIO
+
+
+class IImage(IFile):
+    """This interface defines an Image that can be displayed."""
+
+    def getImageSize():
+        """Return a tuple (x, y) that describes the dimensions of
+        the object."""
+
+class Image(File):
+    __implements__ = IImage, IAnnotatable
+
+    def __init__(self, data=None):
+        '''See interface IFile'''
+        self.contentType, self._width, self._height = getImageInfo(data)
+        self.data = data
+
+
+    def setData(self, data):
+
+        super(Image, self).setData(data)
+
+        if data is not None:
+            contentType = None
+            contentType, self._width, self._height = getImageInfo(self.data)
+            if contentType:
+                self.contentType = contentType
+
+
+    def getImageSize(self):
+        '''See interface IImage'''
+        return (self._width, self._height)
+
+    data = property(File.getData, setData, None,
+                    """Contains the data of the file.""")
+
+
+def getImageInfo(data):
+    data = str(data)
+    size = len(data)
+    height = -1
+    width = -1
+    content_type = ''
+
+    # handle GIFs
+    if (size >= 10) and data[:6] in ('GIF87a', 'GIF89a'):
+        # Check to see if content_type is correct
+        content_type = 'image/gif'
+        w, h = struct.unpack("<HH", data[6:10])
+        width = int(w)
+        height = int(h)
+
+    # See PNG v1.2 spec (http://www.cdrom.com/pub/png/spec/)
+    # Bytes 0-7 are below, 4-byte chunk length, then 'IHDR'
+    # and finally the 4-byte width, height
+    elif ((size >= 24) and data.startswith('\211PNG\r\n\032\n')
+          and (data[12:16] == 'IHDR')):
+        content_type = 'image/png'
+        w, h = struct.unpack(">LL", data[16:24])
+        width = int(w)
+        height = int(h)
+
+    # Maybe this is for an older PNG version.
+    elif (size >= 16) and data.startswith('\211PNG\r\n\032\n'):
+        # Check to see if we have the right content type
+        content_type = 'image/png'
+        w, h = struct.unpack(">LL", data[8:16])
+        width = int(w)
+        height = int(h)
+
+    # handle JPEGs
+    elif (size >= 2) and data.startswith('\377\330'):
+        content_type = 'image/jpeg'
+        jpeg = StringIO(data)
+        jpeg.read(2)
+        b = jpeg.read(1)
+        try:
+            while (b and ord(b) != 0xDA):
+                while (ord(b) != 0xFF): b = jpeg.read(1)
+                while (ord(b) == 0xFF): b = jpeg.read(1)
+                if (ord(b) >= 0xC0 and ord(b) <= 0xC3):
+                    jpeg.read(3)
+                    h, w = struct.unpack(">HH", jpeg.read(4))
+                    break
+                else:
+                    jpeg.read(int(struct.unpack(">H", jpeg.read(2))[0])-2)
+                b = jpeg.read(1)
+            width = int(w)
+            height = int(h)
+        except struct.error:
+            pass
+        except ValueError:
+            pass
+
+    return content_type, width, height


=== Zope3/src/zope/app/interfaces/content/sql.py 1.1 => 1.2 ===
--- /dev/null	Wed Dec 25 09:14:00 2002
+++ Zope3/src/zope/app/interfaces/content/sql.py	Wed Dec 25 09:12:59 2002
@@ -0,0 +1,79 @@
+##############################################################################
+#
+# 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$
+"""
+import zope.schema
+
+from zope.app.interfaces.rdb import ISQLCommand
+from zope.component import getService
+from zope.interface import Attribute
+from zope.proxy.context import ContextProperty
+
+
+class SQLConnectionName(zope.schema.TextLine):
+    """SQL Connection Name"""
+
+    def __allowed(self):
+        """Note that this method works only if the Field is context wrapped."""
+        connection_service = getService(self.context, "SQLDatabaseConnections")
+        connections = connection_service.getAvailableConnections()
+        return connections
+
+    allowed_values = ContextProperty(__allowed)
+
+class ISQLScript(ISQLCommand):
+    """A persistent script that can execute SQL."""
+
+    connectionName = SQLConnectionName(
+        title=u"Connection Name",
+        description=u"The Connection Name for the connection to be used.",
+        required=False)
+
+    arguments = zope.schema.BytesLine(
+        title=u"Arguments",
+        description=u"A set of attributes that can be used during the DTML "
+                    u"rendering process to provide dynamic data.",
+        required=False)
+
+    source = zope.schema.Bytes(
+        title=u"Source",
+        description=u"The source of the page template.",
+        required=True)
+
+    def setArguments(arguments):
+        """Processes the arguments (which could be a dict, string or whatever)
+        to arguments as they are needed for the rendering process."""
+
+    def getArguments():
+        """Get the arguments. A method is preferred here, since some argument
+        evaluation might be done."""
+
+    def getArgumentsString():
+        """This method returns the arguments string."""
+
+    def setSource(source):
+        """Save the source of the page template."""
+
+    def getSource():
+        """Get the source of the page template."""
+
+    def getTemplate():
+        """Get the SQL DTML Template object."""
+
+    def setConnectionName(name):
+        """Save the connection name for this SQL Script."""
+
+    def getConnectionName():
+        """Get the connection name for this SQL Script."""