[Zope-CVS] SVN: book/trunk/photodavns/ 'photo' WebDAV namespace;
product to webdavns chapter.
Stephan Richter
srichter at cosmos.phy.tufts.edu
Tue Aug 24 13:54:56 EDT 2004
Log message for revision 27247:
'photo' WebDAV namespace; product to webdavns chapter.
Changed:
A book/trunk/photodavns/
A book/trunk/photodavns/__init__.py
A book/trunk/photodavns/configure.zcml
A book/trunk/photodavns/ftests.py
A book/trunk/photodavns/interfaces.py
A book/trunk/photodavns/tests.py
-=-
Added: book/trunk/photodavns/__init__.py
===================================================================
--- book/trunk/photodavns/__init__.py 2004-08-24 15:57:59 UTC (rev 27246)
+++ book/trunk/photodavns/__init__.py 2004-08-24 17:54:56 UTC (rev 27247)
@@ -0,0 +1,96 @@
+##############################################################################
+#
+# Copyright (c) 2003, 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.
+#
+##############################################################################
+"""IPhoto implementations
+
+$Id: __init__.py,v 1.1.1.1 2004/02/18 18:07:08 srichter Exp $
+"""
+from persistent.dict import PersistentDict
+from zope.interface import implements
+from zope.schema import getFieldNames
+from zope.app.annotation.interfaces import IAnnotations
+from zope.app.file.interfaces import IImage
+from interfaces import IPhoto, photodavns
+
+
+class ImagePhotoNamespace(object):
+ """Implement IPhoto namespace for IImage.
+
+ Examples:
+
+ >>> from zope.app.file.image import Image
+ >>> image = Image()
+ >>> photo = IPhoto(image)
+
+ >>> photo.height is None
+ True
+ >>> photo.height = 768
+ >>> photo.height
+ 768
+ >>> photo.height = u'100'
+ Traceback (most recent call last):
+ ...
+ WrongType: (u'100', (<type 'int'>, <type 'long'>))
+
+ >>> photo.width is None
+ True
+ >>> photo.width = 1024
+ >>> photo.width
+ 1024
+
+ >>> photo.equivalent35mm is None
+ True
+ >>> photo.equivalent35mm = u'41 mm'
+ >>> photo.equivalent35mm
+ u'41 mm'
+
+ >>> photo.aperture is None
+ True
+ >>> photo.aperture = u'f/2.8'
+ >>> photo.aperture
+ u'f/2.8'
+
+ >>> photo.exposureTime is None
+ True
+ >>> photo.exposureTime = 0.031
+ >>> photo.exposureTime
+ 0.031
+
+ >>> photo.occasion
+ Traceback (most recent call last):
+ ...
+ AttributeError: 'ImagePhotoNamespace' object has no attribute 'occasion'
+ """
+
+ implements(IPhoto)
+ __used_for__ = IImage
+
+ def __init__(self, context):
+ self.context = context
+ self._annotations = IAnnotations(context)
+ if not self._annotations.get(photodavns):
+ self._annotations[photodavns] = PersistentDict()
+
+ def __getattr__(self, name):
+ if not name in getFieldNames(IPhoto):
+ raise AttributeError, "'%s' object has no attribute '%s'" %(
+ self.__class__.__name__, name)
+ # return super(ImagePhotoNamespace, self).__getattribute__(name)
+ return self._annotations[photodavns].get(name, None)
+
+ def __setattr__(self, name, value):
+ if not name in getFieldNames(IPhoto):
+ return super(ImagePhotoNamespace, self).__setattr__(name, value)
+ field = IPhoto[name]
+ field.validate(value)
+ self._annotations[photodavns][name] = value
Added: book/trunk/photodavns/configure.zcml
===================================================================
--- book/trunk/photodavns/configure.zcml 2004-08-24 15:57:59 UTC (rev 27246)
+++ book/trunk/photodavns/configure.zcml 2004-08-24 17:54:56 UTC (rev 27247)
@@ -0,0 +1,16 @@
+<configure
+ xmlns="http://namespaces.zope.org/zope"
+ xmlns:dav="http://namespaces.zope.org/dav">
+
+<dav:provideInterface
+ for="http://namespaces.zope.org/dav/photo/1.0"
+ interface=".interfaces.IPhoto" />
+
+<adapter
+ provides=".interfaces.IPhoto"
+ for="zope.app.file.interfaces.IImage"
+ permission="zope.Public"
+ factory=".ImagePhotoNamespace"
+ trusted="True"/>
+
+</configure>
Added: book/trunk/photodavns/ftests.py
===================================================================
--- book/trunk/photodavns/ftests.py 2004-08-24 15:57:59 UTC (rev 27246)
+++ book/trunk/photodavns/ftests.py 2004-08-24 17:54:56 UTC (rev 27247)
@@ -0,0 +1,74 @@
+##############################################################################
+#
+# Copyright (c) 2003, 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.
+#
+##############################################################################
+"""IPhoto Namespace functional tests
+
+$Id: ftests.py,v 1.1.1.1 2004/02/18 18:07:08 srichter Exp $
+"""
+import unittest
+from transaction import get_transaction
+from xml.dom.minidom import parseString as parseXML
+from zope.app.file.image import Image
+from zope.app.dav.ftests.dav import DAVTestCase
+from book.photodavns.interfaces import IPhoto
+from book.photodavns import ImagePhotoNamespace
+
+property_request = '''\
+<?xml version="1.0" encoding="utf-8" ?>
+<propfind xmlns="DAV:">
+ <prop xmlns:photo="http://namespaces.zope.org/dav/photo/1.0">
+ <photo:height />
+ <photo:width />
+ <photo:equivalent35mm />
+ <photo:aperture />
+ <photo:exposureTime />
+ </prop>
+</propfind>
+'''
+
+data = {'height': 768, 'width': 1024, 'equivalent35mm': u'41 mm',
+ 'aperture': u'f/2.8', 'exposureTime': 0.031}
+
+class IPhotoNamespaceTests(DAVTestCase):
+
+ def createImage(self):
+ img = Image()
+ photo = ImagePhotoNamespace(img)
+ for name, value in data.items():
+ setattr(photo, name, value)
+ root = self.getRootFolder()
+ root['img.jpg'] = img
+ get_transaction().commit()
+
+ def test_propfind_fields(self):
+ self.createImage()
+ response = self.publish(
+ '/img.jpg/',
+ env={'REQUEST_METHOD':'PROPFIND',
+ 'HTTP_Content_Type': 'text/xml'},
+ request_body=property_request)
+ self.assertEqual(response.getStatus(), 207)
+ xml = parseXML(response.getBody())
+ node = xml.documentElement.getElementsByTagName('prop')[0]
+
+ for name, value in data.items():
+ attr_node = node.getElementsByTagName(name)[0]
+ self.assertEqual(attr_node.firstChild.data, unicode(value))
+
+def test_suite():
+ return unittest.TestSuite((
+ unittest.makeSuite(IPhotoNamespaceTests),
+ ))
+
+if __name__ == '__main__':
+ unittest.main(defaultTest='test_suite')
Added: book/trunk/photodavns/interfaces.py
===================================================================
--- book/trunk/photodavns/interfaces.py 2004-08-24 15:57:59 UTC (rev 27246)
+++ book/trunk/photodavns/interfaces.py 2004-08-24 17:54:56 UTC (rev 27247)
@@ -0,0 +1,51 @@
+##############################################################################
+#
+# Copyright (c) 2003, 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.
+#
+##############################################################################
+"""IPhoto WebDAV namespace related interfaces.
+
+$Id: interfaces.py,v 1.1.1.1 2004/02/18 18:07:08 srichter Exp $
+"""
+from zope.interface import Interface
+from zope.schema import Text, TextLine, Int, Float
+
+photodavns = "http://namespaces.zope.org/dav/photo/1.0"
+
+class IPhoto(Interface):
+ """A WebDAV namespace to store photo-related meta data.
+
+ The 'IPhoto' schema/namespace can be used in WebDAV clients to determine
+ information about a particular picture. Obviously, this namespace makes
+ only sense on Image objects.
+ """
+
+ height = Int(
+ title=u"Height",
+ description=u"Specifies the height in pixels.",
+ min=1)
+
+ width = Int(
+ title=u"Width",
+ description=u"Specifies the width in pixels.",
+ min=1)
+
+ equivalent35mm = TextLine(
+ title=u"35mm equivalent",
+ description=u"The photo's size in 35mm is equivalent to this amount")
+
+ aperture = TextLine(
+ title=u"Aperture",
+ description=u"Size of the aperture.")
+
+ exposureTime = Float(
+ title=u"Exposure Time",
+ description=u"Specifies the exposure time in seconds.")
Added: book/trunk/photodavns/tests.py
===================================================================
--- book/trunk/photodavns/tests.py 2004-08-24 15:57:59 UTC (rev 27246)
+++ book/trunk/photodavns/tests.py 2004-08-24 17:54:56 UTC (rev 27247)
@@ -0,0 +1,41 @@
+##############################################################################
+#
+# 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.
+#
+##############################################################################
+"""Tests for the IPhoto namespace
+
+$Id: tests.py,v 1.1.1.1 2004/02/18 18:07:08 srichter Exp $
+"""
+import unittest
+from zope.interface import classImplements
+from zope.testing.doctestunit import DocTestSuite
+from zope.app.annotation.interfaces import IAttributeAnnotatable
+from zope.app.file.image import Image
+from zope.app.file.interfaces import IImage
+from zope.app.tests import ztapi, placelesssetup, setup
+from book.photodavns.interfaces import IPhoto
+from book.photodavns import ImagePhotoNamespace
+
+def setUp():
+ placelesssetup.setUp()
+ ztapi.provideAdapter(IImage, IPhoto, ImagePhotoNamespace)
+ setup.setUpAnnotations()
+ classImplements(Image, IAttributeAnnotatable)
+
+def test_suite():
+ return unittest.TestSuite((
+ DocTestSuite('book.photodavns',
+ setUp=setUp, tearDown=placelesssetup.tearDown),
+ ))
+
+if __name__ == '__main__':
+ unittest.main(defaultTest='test_suite')
More information about the Zope-CVS
mailing list