[Zope3-checkins] CVS: Zope3/src/zope/app/i18nfile - __init__.py:1.1.2.1 configure.zcml:1.1.2.1 i18nfile.py:1.1.2.1 i18nimage.py:1.1.2.1 interfaces.py:1.1.2.1

Philipp von Weitershausen philikon at philikon.de
Fri Feb 20 14:41:03 EST 2004


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

Added Files:
      Tag: philikon-movecontent-branch
	__init__.py configure.zcml i18nfile.py i18nimage.py 
	interfaces.py 
Log Message:
i18nfile and i18nimage live in zope.app.i18nfile now.


=== Added File Zope3/src/zope/app/i18nfile/__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:41:02 philikon Exp $
"""

from i18nfile import I18nFile
from i18nimage import I18nImage


=== Added File Zope3/src/zope/app/i18nfile/configure.zcml ===
<configure
    xmlns='http://namespaces.zope.org/zope'
    i18n_domain='zope'
    >

  <!-- Module alias for backward compat -->

  <modulealias
      module=".i18nfile"
      alias="zope.app.content.i18nfile"
      />

  <modulealias
      module=".interfaces"
      alias="zope.app.interfaces.content.i18nfile"
      />

  <modulealias
      module=".i18nimage"
      alias="zope.app.content.i18nimage"
      />

  <modulealias
      module=".interfaces"
      alias="zope.app.interfaces.content.i18nimage"
      />


  <!-- setting up content types -->

  <interface 
      interface=".i18nfile.II18nFile" 
      type="zope.app.interfaces.content.IContentType"
      />

  <interface 
      interface=".interfaces.II18nImage" 
      type="zope.app.interfaces.content.IContentType"
      />


  <!-- content classes -->

  <content class=".i18nfile.I18nFile">
    <factory
        id="zope.app.i18nfile.I18nFile"
        permission="zope.ManageContent"
        title="I18n File"
        description="An Internationalized File"
        />

    <require
        permission="zope.View"
        interface="zope.app.file.interfaces.IReadFile"
        />

    <require
        permission="zope.ManageContent"
        interface="zope.app.file.interfaces.IWriteFile"
        />

    <require
        permission="zope.View"
        attributes="getDefaultLanguage getAvailableLanguages"
        />

    <require
        permission="zope.ManageContent"
        attributes="setDefaultLanguage removeLanguage"
        />

    <implements
       interface="zope.app.interfaces.annotation.IAttributeAnnotatable"
       />
  </content>

  <content class=".i18nimage.I18nImage">
    <factory
        id="I18nImage"
        permission="zope.ManageContent"
        title="I18n Image"
        description="An Internationalized Image"
        />

    <require
        permission="zope.View"
        interface="zope.app.file.interfaces.IReadFile"
        attributes="getImageSize"
        />

    <require
        permission="zope.ManageContent"
        interface="zope.app.file.interfaces.IWriteFile"
        />

    <require
        permission="zope.View"
        attributes="getDefaultLanguage getAvailableLanguages"
        />

    <require
        permission="zope.ManageContent"
        attributes="setDefaultLanguage removeLanguage" />

    <implements
       interface="zope.app.interfaces.annotation.IAttributeAnnotatable"
       />
  </content>


  <!-- include browser package -->

  <include package=".browser" />

</configure>


=== Added File Zope3/src/zope/app/i18nfile/i18nfile.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: i18nfile.py,v 1.1.2.1 2004/02/20 19:41:02 philikon Exp $
"""

import persistence
from zope.interface import implements
from zope.publisher.browser import FileUpload
from zope.app.file.file import File

from interfaces import II18nFile

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

    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 isinstance(data, 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()

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

    def setDefaultLanguage(self, language):
        'See 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 II18nAware'
        return self._data.keys()

    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 = True


=== Added File Zope3/src/zope/app/i18nfile/i18nimage.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: i18nimage.py,v 1.1.2.1 2004/02/20 19:41:02 philikon Exp $
"""

from zope.interface import implements
from zope.app.file.image import Image, getImageInfo
from zope.app.i18nfile.i18nfile import I18nFile

from interfaces import II18nImage

class I18nImage(I18nFile):
    """An internationalized Image object.  Note that images of all
    languages share the same content type.
    """

    implements(II18nImage)

    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()


=== Added File Zope3/src/zope/app/i18nfile/interfaces.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: interfaces.py,v 1.1.2.1 2004/02/20 19:41:02 philikon Exp $
"""

from zope.i18n.interfaces import II18nAware
from zope.app.file.interfaces import IFile, IImage

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

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

class II18nImage(II18nFile, IImage):
    """I18n aware image interface."""




More information about the Zope3-Checkins mailing list