[Zope3-checkins]
SVN: Zope3/branches/jhauser-filefieldwidget/src/zope/app/i18nimage/
Move image part from zope.app.i18nfile to zope.app.i18nimage
Roger Ineichen
roger at projekt01.ch
Thu Jan 20 11:54:51 EST 2005
Log message for revision 28889:
Move image part from zope.app.i18nfile to zope.app.i18nimage
Changed:
A Zope3/branches/jhauser-filefieldwidget/src/zope/app/i18nimage/DEPENDENCIES.cfg
A Zope3/branches/jhauser-filefieldwidget/src/zope/app/i18nimage/SETUP.cfg
A Zope3/branches/jhauser-filefieldwidget/src/zope/app/i18nimage/__init__.py
A Zope3/branches/jhauser-filefieldwidget/src/zope/app/i18nimage/browser/__init__.py
A Zope3/branches/jhauser-filefieldwidget/src/zope/app/i18nimage/browser/configure.zcml
A Zope3/branches/jhauser-filefieldwidget/src/zope/app/i18nimage/browser/i18nimage.py
A Zope3/branches/jhauser-filefieldwidget/src/zope/app/i18nimage/browser/image_edit.pt
A Zope3/branches/jhauser-filefieldwidget/src/zope/app/i18nimage/configure.zcml
A Zope3/branches/jhauser-filefieldwidget/src/zope/app/i18nimage/i18nimage-configure.zcml
A Zope3/branches/jhauser-filefieldwidget/src/zope/app/i18nimage/i18nimage.py
A Zope3/branches/jhauser-filefieldwidget/src/zope/app/i18nimage/interfaces.py
A Zope3/branches/jhauser-filefieldwidget/src/zope/app/i18nimage/tests/__init__.py
A Zope3/branches/jhauser-filefieldwidget/src/zope/app/i18nimage/tests/test_i18nimage.py
-=-
Added: Zope3/branches/jhauser-filefieldwidget/src/zope/app/i18nimage/DEPENDENCIES.cfg
===================================================================
--- Zope3/branches/jhauser-filefieldwidget/src/zope/app/i18nimage/DEPENDENCIES.cfg 2005-01-20 16:53:52 UTC (rev 28888)
+++ Zope3/branches/jhauser-filefieldwidget/src/zope/app/i18nimage/DEPENDENCIES.cfg 2005-01-20 16:54:50 UTC (rev 28889)
@@ -0,0 +1,7 @@
+persistent
+zope.app.file
+zope.i18n
+zope.app.i18nfile
+zope.app.image
+zope.interface
+zope.publisher
Property changes on: Zope3/branches/jhauser-filefieldwidget/src/zope/app/i18nimage/DEPENDENCIES.cfg
___________________________________________________________________
Name: svn:eol-style
+ native
Added: Zope3/branches/jhauser-filefieldwidget/src/zope/app/i18nimage/SETUP.cfg
===================================================================
--- Zope3/branches/jhauser-filefieldwidget/src/zope/app/i18nimage/SETUP.cfg 2005-01-20 16:53:52 UTC (rev 28888)
+++ Zope3/branches/jhauser-filefieldwidget/src/zope/app/i18nimage/SETUP.cfg 2005-01-20 16:54:50 UTC (rev 28889)
@@ -0,0 +1,5 @@
+# Tell zpkg how to install the ZCML slugs.
+
+<data-files zopeskel/etc/package-includes>
+ i18nimage-*.zcml
+</data-files>
Property changes on: Zope3/branches/jhauser-filefieldwidget/src/zope/app/i18nimage/SETUP.cfg
___________________________________________________________________
Name: svn:eol-style
+ native
Added: Zope3/branches/jhauser-filefieldwidget/src/zope/app/i18nimage/__init__.py
===================================================================
--- Zope3/branches/jhauser-filefieldwidget/src/zope/app/i18nimage/__init__.py 2005-01-20 16:53:52 UTC (rev 28888)
+++ Zope3/branches/jhauser-filefieldwidget/src/zope/app/i18nimage/__init__.py 2005-01-20 16:54:50 UTC (rev 28889)
@@ -0,0 +1,20 @@
+##############################################################################
+#
+# Copyright (c) 2004 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (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.
+#
+##############################################################################
+"""I18n-aware Image Package
+
+$Id: __init__.py 26890 2004-08-04 04:17:33Z pruggera $
+"""
+__docformat__ = 'restructuredtext'
+
+from i18nimage import I18nImage
Property changes on: Zope3/branches/jhauser-filefieldwidget/src/zope/app/i18nimage/__init__.py
___________________________________________________________________
Name: svn:eol-style
+ native
Added: Zope3/branches/jhauser-filefieldwidget/src/zope/app/i18nimage/browser/__init__.py
===================================================================
--- Zope3/branches/jhauser-filefieldwidget/src/zope/app/i18nimage/browser/__init__.py 2005-01-20 16:53:52 UTC (rev 28888)
+++ Zope3/branches/jhauser-filefieldwidget/src/zope/app/i18nimage/browser/__init__.py 2005-01-20 16:54:50 UTC (rev 28889)
@@ -0,0 +1,2 @@
+#
+# This file is necessary to make this directory a package.
Property changes on: Zope3/branches/jhauser-filefieldwidget/src/zope/app/i18nimage/browser/__init__.py
___________________________________________________________________
Name: svn:eol-style
+ native
Added: Zope3/branches/jhauser-filefieldwidget/src/zope/app/i18nimage/browser/configure.zcml
===================================================================
--- Zope3/branches/jhauser-filefieldwidget/src/zope/app/i18nimage/browser/configure.zcml 2005-01-20 16:53:52 UTC (rev 28888)
+++ Zope3/branches/jhauser-filefieldwidget/src/zope/app/i18nimage/browser/configure.zcml 2005-01-20 16:54:50 UTC (rev 28889)
@@ -0,0 +1,46 @@
+<configure
+ xmlns='http://namespaces.zope.org/zope'
+ xmlns:browser='http://namespaces.zope.org/browser'
+ i18n_domain='zope'
+ >
+
+ <browser:page
+ name="index.html"
+ for="zope.app.i18nimage.interfaces.II18nImage"
+ permission="zope.View"
+ allowed_attributes="__call__ tag"
+ class=".i18nimage.I18nImageData"
+ />
+
+ <browser:pages
+ for="zope.app.i18nimage.interfaces.II18nImage"
+ permission="zope.ManageContent"
+ class=".i18nimage.I18nImageEdit">
+
+ <browser:page name="upload.html" template="image_edit.pt" />
+ <browser:page name="uploadAction.html" attribute="action" />
+
+ </browser:pages>
+
+ <browser:menuItems
+ menu="zmi_views"
+ for="zope.app.i18nimage.interfaces.II18nImage"
+ >
+
+ <!-- Keep the old "edit" form -->
+ <browser:menuItem title="Edit" action="upload.html"/>
+
+ <!-- Suppress upload form (from IFile) -->
+ <browser:menuItem title="Upload" action="upload.html"
+ filter="python: False" />
+
+ </browser:menuItems>
+
+ <browser:addMenuItem
+ class="zope.app.i18nimage.I18nImage"
+ title="I18n Image"
+ description="A multi-locale version of an Image."
+ permission="zope.ManageContent"
+ />
+
+</configure>
Property changes on: Zope3/branches/jhauser-filefieldwidget/src/zope/app/i18nimage/browser/configure.zcml
___________________________________________________________________
Name: svn:eol-style
+ native
Added: Zope3/branches/jhauser-filefieldwidget/src/zope/app/i18nimage/browser/i18nimage.py
===================================================================
--- Zope3/branches/jhauser-filefieldwidget/src/zope/app/i18nimage/browser/i18nimage.py 2005-01-20 16:53:52 UTC (rev 28888)
+++ Zope3/branches/jhauser-filefieldwidget/src/zope/app/i18nimage/browser/i18nimage.py 2005-01-20 16:54:50 UTC (rev 28889)
@@ -0,0 +1,82 @@
+##############################################################################
+#
+# 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.1 (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.
+#
+##############################################################################
+"""Define view component for image editing.
+
+$Id: i18nimage.py 26890 2004-08-04 04:17:33Z pruggera $
+"""
+__docformat__ = 'restructuredtext'
+
+from urllib import quote
+
+from zope.i18n.negotiator import negotiator
+
+from zope.app.i18n import ZopeMessageIDFactory as _
+from zope.app.image.browser.image import ImageData
+from zope.app.size import byteDisplay
+
+class I18nImageEdit(object):
+
+ name = 'editForm'
+ title = _('Edit Form')
+ description = _('This edit form allows you to make changes to the ' +
+ 'properties of this image.')
+
+ def size(self, language=None):
+ sized = ISized(self.context._get(language))
+ return sized.sizeForDisplay()
+
+ def action(self, contentType, data, language, defaultLanguage,
+ selectLanguage=None, removeLanguage=None,
+ addLanguage=None, newLanguage=None):
+ if selectLanguage:
+ pass
+ elif removeLanguage:
+ self.context.removeLanguage(language)
+ language = self.context.getDefaultLanguage()
+ else:
+ if addLanguage:
+ language = newLanguage
+ self.context.setDefaultLanguage(defaultLanguage)
+ self.context.setData(data, language)
+ self.context.contentType = contentType
+ return self.request.response.redirect(self.request.URL[-1] +
+ "/upload.html?language=%s" % quote(language, ''))
+
+
+class I18nImageData(ImageData):
+
+ def __call__(self):
+ image = self.context
+ language = None
+ if self.request is not None:
+ langs = self.context.getAvailableLanguages()
+ language = negotiator.getLanguage(langs, self.request)
+ self.request.response.setHeader('content-type', image.contentType)
+ return image.getData(language)
+
+
+ def tag(self, height=None, width=None, **args):
+ """See `ImageData.tag.`"""
+
+ language = None
+ if self.request is not None and \
+ (width is None or height is None):
+ langs = self.context.getAvailableLanguages()
+ language = negotiator.getLanguage(langs, self.request)
+
+ if width is None:
+ width = self.context.getImageSize(language)[0]
+ if height is None:
+ height = self.context.getImageSize(language)[1]
+ return ImageData.tag(self, width=width, height=height, **args)
Property changes on: Zope3/branches/jhauser-filefieldwidget/src/zope/app/i18nimage/browser/i18nimage.py
___________________________________________________________________
Name: svn:eol-style
+ native
Added: Zope3/branches/jhauser-filefieldwidget/src/zope/app/i18nimage/browser/image_edit.pt
===================================================================
--- Zope3/branches/jhauser-filefieldwidget/src/zope/app/i18nimage/browser/image_edit.pt 2005-01-20 16:53:52 UTC (rev 28888)
+++ Zope3/branches/jhauser-filefieldwidget/src/zope/app/i18nimage/browser/image_edit.pt 2005-01-20 16:54:50 UTC (rev 28889)
@@ -0,0 +1,103 @@
+<html metal:use-macro="context/@@standard_macros/view">
+<head>
+ <style metal:fill-slot="headers" type="text/css">
+ <!--
+ .ContentIcon {
+ width: 20px;
+ }
+
+ .ContentTitle {
+ text-align: left;
+ }
+ -->
+ </style>
+</head>
+
+<body>
+<div metal:fill-slot="body">
+
+
+ <p tal:content="options/msg | nothing">
+ Message will go here.
+ </p>
+
+ <p tal:content="view/description">
+ Description of the Form.
+ </p>
+
+ <form action="uploadAction.html" method="post"
+ enctype="multipart/form-data">
+
+ <div class="row">
+ <div class="label" i18n:translate="">Content Type</div>
+ <div class="field">
+ <input name="contentType" type="text" size="20"
+ tal:attributes="value context/contentType" />
+ </div>
+ </div>
+
+ <div class="row">
+ <div class="label" i18n:translate="">Default Language</div>
+ <div class="field">
+ <select name="defaultLanguage">
+ <span tal:repeat="lang context/getAvailableLanguages"
+ tal:omit-tag="">
+ <option tal:attributes="
+ value lang;
+ selected python:context.getDefaultLanguage() == lang"
+ tal:content="lang" />
+ </span>
+ </select>
+ </div>
+ </div>
+ <hr />
+ <div class="row">
+ <div class="label" i18n:translate="">Language</div>
+ <div class="field">
+ <select name="language">
+ <span tal:repeat="lang context/getAvailableLanguages"
+ tal:omit-tag="">
+ <option tal:attributes="
+ value lang;
+ selected python:request.get('language',
+ context.getDefaultLanguage()) == lang"
+ tal:content="lang" />
+ </span>
+ </select>
+ <input type="submit" name="selectLanguage" value="Show"
+ i18n:attributes="value show-button"/>
+ <input type="submit" name="removeLanguage" value="Remove"
+ i18n:attributes="value remove-button"/>
+
+ <input type="submit" name="addLanguage"
+ value="Add new language"
+ i18n:attributes="value" />
+ <input type="text" name="newLanguage" size="10" />
+ </div>
+ </div>
+ <div class="row">
+ <div class="label" i18n:translate="">Data</div>
+ <div class="field">
+ <input type="file" name="data" size="20" />
+ </div>
+ </div>
+ <div class="row">
+ <div class="label" i18n:translate="">Dimensions</div>
+ <div class="field"
+ tal:content="python:view.size(request.get('language'))">
+ 40 x 40 pixels, 10 kB
+ </div>
+ </div>
+
+ <div class="row">
+ <div class="controls">
+ <input type="submit" name="edit" value="Save Changes"
+ i18n:attributes="value save-changes-button"/>
+ </div>
+ </div>
+
+ </form>
+
+</div>
+</body>
+</html>
Property changes on: Zope3/branches/jhauser-filefieldwidget/src/zope/app/i18nimage/browser/image_edit.pt
___________________________________________________________________
Name: svn:eol-style
+ native
Added: Zope3/branches/jhauser-filefieldwidget/src/zope/app/i18nimage/configure.zcml
===================================================================
--- Zope3/branches/jhauser-filefieldwidget/src/zope/app/i18nimage/configure.zcml 2005-01-20 16:53:52 UTC (rev 28888)
+++ Zope3/branches/jhauser-filefieldwidget/src/zope/app/i18nimage/configure.zcml 2005-01-20 16:54:50 UTC (rev 28889)
@@ -0,0 +1,49 @@
+<configure
+ xmlns='http://namespaces.zope.org/zope'
+ i18n_domain='zope'
+ >
+
+ <!-- setting up content types -->
+
+ <interface
+ interface=".interfaces.II18nImage"
+ type="zope.app.content.interfaces.IContentType"
+ />
+
+
+ <!-- content classes -->
+
+ <content class=".i18nimage.I18nImage">
+ <factory
+ id="zope.app.content.I18nImage"
+ title="I18n Image"
+ description="An Internationalized Image"
+ />
+ <require
+ permission="zope.View"
+ interface="zope.app.file.interfaces.IFile"
+ attributes="getImageSize"
+ />
+ <require
+ permission="zope.ManageContent"
+ set_schema="zope.app.file.interfaces.IFile"
+ />
+ <require
+ permission="zope.View"
+ attributes="getDefaultLanguage getAvailableLanguages getData"
+ />
+ <require
+ permission="zope.ManageContent"
+ attributes="setDefaultLanguage removeLanguage setData"
+ />
+ <implements
+ interface="zope.app.annotation.interfaces.IAttributeAnnotatable"
+ />
+ </content>
+
+
+ <!-- include browser package -->
+
+ <include package=".browser" />
+
+</configure>
Property changes on: Zope3/branches/jhauser-filefieldwidget/src/zope/app/i18nimage/configure.zcml
___________________________________________________________________
Name: svn:eol-style
+ native
Added: Zope3/branches/jhauser-filefieldwidget/src/zope/app/i18nimage/i18nimage-configure.zcml
===================================================================
--- Zope3/branches/jhauser-filefieldwidget/src/zope/app/i18nimage/i18nimage-configure.zcml 2005-01-20 16:53:52 UTC (rev 28888)
+++ Zope3/branches/jhauser-filefieldwidget/src/zope/app/i18nimage/i18nimage-configure.zcml 2005-01-20 16:54:50 UTC (rev 28889)
@@ -0,0 +1 @@
+<include package="zope.app.i18nimage"/>
Property changes on: Zope3/branches/jhauser-filefieldwidget/src/zope/app/i18nimage/i18nimage-configure.zcml
___________________________________________________________________
Name: svn:eol-style
+ native
Added: Zope3/branches/jhauser-filefieldwidget/src/zope/app/i18nimage/i18nimage.py
===================================================================
--- Zope3/branches/jhauser-filefieldwidget/src/zope/app/i18nimage/i18nimage.py 2005-01-20 16:53:52 UTC (rev 28888)
+++ Zope3/branches/jhauser-filefieldwidget/src/zope/app/i18nimage/i18nimage.py 2005-01-20 16:54:50 UTC (rev 28889)
@@ -0,0 +1,50 @@
+##############################################################################
+#
+# 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.1 (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.
+#
+##############################################################################
+"""I18n-aware Image Content Component
+
+$Id: i18nimage.py 26890 2004-08-04 04:17:33Z pruggera $
+"""
+__docformat__ = 'restructuredtext'
+
+from zope.interface import implements
+from zope.app.image.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 `II18nFile`'''
+ 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.contentType = contentType
+
+ def getImageSize(self, language=None):
+ '''See interface `II18nImage`'''
+ return self._get(language).getImageSize()
Property changes on: Zope3/branches/jhauser-filefieldwidget/src/zope/app/i18nimage/i18nimage.py
___________________________________________________________________
Name: svn:eol-style
+ native
Added: Zope3/branches/jhauser-filefieldwidget/src/zope/app/i18nimage/interfaces.py
===================================================================
--- Zope3/branches/jhauser-filefieldwidget/src/zope/app/i18nimage/interfaces.py 2005-01-20 16:53:52 UTC (rev 28888)
+++ Zope3/branches/jhauser-filefieldwidget/src/zope/app/i18nimage/interfaces.py 2005-01-20 16:54:50 UTC (rev 28889)
@@ -0,0 +1,31 @@
+##############################################################################
+#
+# 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.1 (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.
+#
+##############################################################################
+"""I18n-aware image interfaces.
+
+$Id: interfaces.py 26890 2004-08-04 04:17:33Z pruggera $
+"""
+__docformat__ = 'restructuredtext'
+
+from zope.i18n.interfaces import II18nAware
+from zope.app.i18nfile.interfaces import II18nFile
+from zope.app.image.interfaces import IImage
+
+
+class II18nImage(II18nFile, IImage):
+ """I18n aware image interface."""
+
+ def getImageSize(language=None):
+ """Return a tuple (x, y) that describes the dimensions of the object
+ for a given language or for the default language.
+ """
Property changes on: Zope3/branches/jhauser-filefieldwidget/src/zope/app/i18nimage/interfaces.py
___________________________________________________________________
Name: svn:eol-style
+ native
Added: Zope3/branches/jhauser-filefieldwidget/src/zope/app/i18nimage/tests/__init__.py
===================================================================
--- Zope3/branches/jhauser-filefieldwidget/src/zope/app/i18nimage/tests/__init__.py 2005-01-20 16:53:52 UTC (rev 28888)
+++ Zope3/branches/jhauser-filefieldwidget/src/zope/app/i18nimage/tests/__init__.py 2005-01-20 16:54:50 UTC (rev 28889)
@@ -0,0 +1,2 @@
+#
+# This file is necessary to make this directory a package.
Property changes on: Zope3/branches/jhauser-filefieldwidget/src/zope/app/i18nimage/tests/__init__.py
___________________________________________________________________
Name: svn:eol-style
+ native
Added: Zope3/branches/jhauser-filefieldwidget/src/zope/app/i18nimage/tests/test_i18nimage.py
===================================================================
--- Zope3/branches/jhauser-filefieldwidget/src/zope/app/i18nimage/tests/test_i18nimage.py 2005-01-20 16:53:52 UTC (rev 28888)
+++ Zope3/branches/jhauser-filefieldwidget/src/zope/app/i18nimage/tests/test_i18nimage.py 2005-01-20 16:54:50 UTC (rev 28889)
@@ -0,0 +1,113 @@
+##############################################################################
+#
+# 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.1 (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.
+#
+##############################################################################
+"""I18n Image Tests
+
+$Id: test_i18nimage.py 25177 2004-06-02 13:17:31Z jim $
+"""
+
+import unittest
+from zope.interface.verify import verifyClass
+from zope.i18n.tests.testii18naware import TestII18nAware
+
+from zope.app.i18nimage.i18nimage import I18nImage
+
+def sorted(list):
+ list.sort()
+ return list
+
+class Test(TestII18nAware):
+
+ def _makeImage(self, *args, **kw):
+ return I18nImage(*args, **kw)
+
+ def _createObject(self):
+ obj = self._makeImage(defaultLanguage='fr')
+ obj.setData('', 'lt')
+ obj.setData('', 'en')
+ return obj
+
+ def testEmpty(self):
+ file = self._makeImage()
+
+ self.assertEqual(file.contentType, '')
+ self.assertEqual(file.getData(), '')
+ self.assertEqual(file.getDefaultLanguage(), 'en')
+
+
+ def testConstructor(self):
+ file = self._makeImage('Data')
+ self.assertEqual(file.contentType, '')
+ self.assertEqual(file.getData(), 'Data')
+ self.assertEqual(file.getData('en'), 'Data')
+ self.assertEqual(file.getData('nonexistent'), 'Data')
+ self.assertEqual(file.getDefaultLanguage(), 'en')
+ self.assertEqual(sorted(file.getAvailableLanguages()), ['en'])
+
+ file = self._makeImage('Data', defaultLanguage='fr')
+ self.assertEqual(file.contentType, '')
+ self.assertEqual(file.getData(), 'Data')
+ self.assertEqual(file.getData('en'), 'Data')
+ self.assertEqual(file.getData('nonexistent'), 'Data')
+ self.assertEqual(file.getDefaultLanguage(), 'fr')
+ self.assertEqual(sorted(file.getAvailableLanguages()), ['fr'])
+
+ def testMutators(self):
+ image = self._makeImage()
+
+ # Check that setData updates content type only when updating the
+ # default language. Need some real images or at least headers
+ # for that.
+
+ gifHdr = 'GIF87a\x20\x00\x10\x00'
+ image.setData(gifHdr)
+ self.assertEqual(image.contentType, 'image/gif')
+
+ pngHdr = '\211PNG\r\n\032\n\0\0\0\x20\0\0\0\x10'
+ image.setData(pngHdr, 'fr')
+ self.assertEqual(image.contentType, 'image/gif')
+
+ image.setData(pngHdr, 'en')
+ self.assertEqual(image.contentType, 'image/png')
+
+ def testInterface(self):
+ from zope.app.file.interfaces import IImage
+ from zope.app.i18nfile.interfaces import II18nFile
+ from zope.i18n.interfaces import II18nAware
+
+ self.failUnless(IImage.implementedBy(I18nImage))
+ self.failUnless(verifyClass(IImage, I18nImage))
+
+ self.failUnless(II18nAware.implementedBy(I18nImage))
+ self.failUnless(verifyClass(II18nAware, I18nImage))
+
+ self.failUnless(II18nFile.implementedBy(I18nImage))
+ self.failUnless(verifyClass(II18nFile, I18nImage))
+
+ def testSetDefaultLanguage(self):
+ # getDefaultLanguage and getAvailableLanguages are tested in the
+ # above tests
+
+ file = self._makeImage()
+
+ file.setData('', language='lt')
+ file.setDefaultLanguage('lt')
+ self.assertEqual(file.getDefaultLanguage(), 'lt')
+
+
+def test_suite():
+ loader = unittest.TestLoader()
+ return loader.loadTestsFromTestCase(Test)
+
+if __name__=='__main__':
+ unittest.TextTestRunner().run(test_suite())
Property changes on: Zope3/branches/jhauser-filefieldwidget/src/zope/app/i18nimage/tests/test_i18nimage.py
___________________________________________________________________
Name: svn:eol-style
+ native
More information about the Zope3-Checkins
mailing list