[Zope3-checkins] CVS: Zope3/src/zope/app/interfaces/content - 18nfile.py:1.1.2.1 __init__.py:1.1.2.1 file.py:1.1.2.1 folder.py:1.1.2.1 sql.py:1.1.2.1

Jim Fulton jim@zope.com
Mon, 23 Dec 2002 14:31:49 -0500


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

Added Files:
      Tag: NameGeddon-branch
	18nfile.py __init__.py file.py folder.py sql.py 
Log Message:
Initial renaming before debugging

=== Added File Zope3/src/zope/app/interfaces/content/18nfile.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: 18nfile.py,v 1.1.2.1 2002/12/23 19:31:48 jim Exp $
"""

import persistence
from zope.app.interfaces.content.file import IFile
from zope.interfaces.i18n import II18nAware
from zope.app.content.file import File
from zope.publisher.browser import FileUpload


class II18nFile(IFile, II18nAware):
    """I18n aware file interface."""

    def removeLanguage(language):
        '''Remove translated content for a given language.'''


class I18nFile(Persistence.Persistent):
    """I18n aware file object.  It contains a number of File objects --
    one for each language.
    """

    __implements__ = II18nFile

    def __init__(self, data='', contentType=None, defaultLanguage='en'):
        """ """

        self._data = {}
        self.defaultLanguage = defaultLanguage
        self.setData(data, language=defaultLanguage)

        if contentType is None:
            self.setContentType('')
        else:
            self.setContentType(contentType)


    def __len__(self):
        return self.getSize()


    def _create(self, data):
        """Create a new subobject of the appropriate type.  Should be
        overriden in subclasses.
        """
        return File(data)


    def _get(self, language):
        """Helper function -- return a subobject for a given language,
        and if it does not exist, return a subobject for the default
        language.
        """
        file = self._data.get(language)
        if not file:
            file = self._data[self.defaultLanguage]
        return file


    def _get_or_add(self, language, data=''):
        """Helper function -- return a subobject for a given language,
        and if it does not exist, create and return a new subobject.
        """
        if language is None:
            language = self.defaultLanguage
        file = self._data.get(language)
        if not file:
            self._data[language] = file = self._create(data)
            self._p_changed = 1
        return file


    ############################################################
    # Implementation methods for interface
    # Zope.App.OFS.IFile.IFile

    def setContentType(self, contentType):
        '''See interface IFile'''
        self._contentType = contentType


    def getContentType(self):
        '''See interface IFile'''
        return self._contentType


    contentType = property(getContentType, setContentType)

    def edit(self, data, contentType=None, language=None):
        '''See interface IFile'''

        # XXX This seems broken to me, as setData can override the
        # content type explicitly passed in.

        if contentType is not None:
            self.setContentType(contentType)
        if hasattr(data, '__class__') and data.__class__ is FileUpload \
           and not data.filename:
           data = None          # Ignore empty files
        if data is not None:
            self.setData(data, language)


    def getData(self, language=None):
        '''See interface IFile'''
        return self._get(language).getData()


    def setData(self, data, language=None):
        '''See interface IFile'''
        self._get_or_add(language).setData(data)

    data = property(getData, setData)

    def getSize(self, language=None):
        '''See interface IFile'''
        return self._get(language).getSize()

    #
    ############################################################

    ############################################################
    # Implementation methods for interface
    # II18nAware.py

    def getDefaultLanguage(self):
        'See Zope.I18n.II18nAware.II18nAware'
        return self.defaultLanguage

    def setDefaultLanguage(self, language):
        'See Zope.I18n.II18nAware.II18nAware'
        if not self._data.has_key(language):
            raise ValueError, \
                  'cannot set nonexistent language (%s) as default' % language
        self.defaultLanguage = language

    def getAvailableLanguages(self):
        'See Zope.I18n.II18nAware.II18nAware'
        return self._data.keys()

    #
    ############################################################


    ############################################################
    # Implementation methods for interface
    # II18nFile.py
    def removeLanguage(self, language):
        '''See interface II18nFile'''

        if language == self.defaultLanguage:
            raise ValueError, 'cannot remove default language (%s)' % language
        if self._data.has_key(language):
            del self._data[language]
            self._p_changed = 1




=== Added File Zope3/src/zope/app/interfaces/content/__init__.py ===
#
# This file is necessary to make this directory a package.


=== Added File Zope3/src/zope/app/interfaces/content/file.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.
# 
##############################################################################
"""Basic File interfaces.

$Id: file.py,v 1.1.2.1 2002/12/23 19:31:48 jim Exp $
"""
from zope.interface import Interface
import zope.schema

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.

    """
        


"""
$Id: file.py,v 1.1.2.1 2002/12/23 19:31:48 jim Exp $
"""
from zope.interface import Interface


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.
    """



        


=== Added File Zope3/src/zope/app/interfaces/content/folder.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: folder.py,v 1.1.2.1 2002/12/23 19:31:48 jim Exp $
"""

from zope.app.interfaces.container import IAdding

class IFolderAdding(IAdding):
    pass


=== Added File Zope3/src/zope/app/interfaces/content/sql.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: sql.py,v 1.1.2.1 2002/12/23 19:31:48 jim Exp $
"""
from zope.app.interfaces.rdb import ISQLCommand
from zope.interface.element import Attribute
from zope.component import getService
from zope.proxy.context import ContextProperty
import zope.schema

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."""