[Zope3-checkins] CVS: Zope3/src/zope/app/content - configure.zcml:1.3 image.py:1.3

Steve Alexander steve@cat-box.net
Fri, 27 Dec 2002 14:19:40 -0500


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

Modified Files:
	configure.zcml image.py 
Log Message:
implemented a useful ISized adapter for images, which gives you the
size in bytes, and the width and height, and sorts on size in bytes.


=== Zope3/src/zope/app/content/configure.zcml 1.2 => 1.3 ===
--- Zope3/src/zope/app/content/configure.zcml:1.2	Wed Dec 25 09:12:48 2002
+++ Zope3/src/zope/app/content/configure.zcml	Fri Dec 27 14:19:09 2002
@@ -54,60 +54,65 @@
 
 </content>
 
-  <permission id="zope.AddImages" title="Add Images" />
+<permission id="zope.AddImages" title="Add Images" />
 
-  <content class="zope.app.content.image.Image">
+<content class="zope.app.content.image.Image">
 
-    <factory
-        id="Image"
-        permission="zope.ManageContent"
-        title="Image"
-        description="An Image" />
-
-    <require
-        permission="zope.View"
-        interface="zope.app.interfaces.content.file.IReadFile"
-        attributes="getImageSize"
-        />
-
-    <require
-        permission="zope.ManageContent"
-        interface="zope.app.interfaces.content.file.IWriteFile"
-        set_schema="zope.app.interfaces.content.file.IReadFile"
-        />
-
-    <implements
-       interface="zope.app.interfaces.annotation.IAttributeAnnotatable"
-       />
-
-  </content>
-
-  <content class="zope.app.content.i18nimage.I18nImage">
-    <factory
-        id="I18nImage"
-        permission="zope.ManageContent"
-        title="I18n Image"
-        description="An Internationalized Image" />
-    <require
-        permission="zope.View"
-        interface="zope.app.interfaces.content.file.IReadFile"
-        attributes="getImageSize"
-        />
-    <require
-        permission="zope.ManageContent"
-        interface="zope.app.interfaces.content.file.IWriteFile" />
-    <require
-        permission="zope.View"
-        attributes="getDefaultLanguage getAvailableLanguages" />
-    <require
-        permission="zope.ManageContent"
-        attributes="setDefaultLanguage removeLanguage" />
-
-    <implements
-       interface="zope.app.interfaces.annotation.IAttributeAnnotatable"
-       />
+  <factory
+      id="Image"
+      permission="zope.ManageContent"
+      title="Image"
+      description="An Image" />
+
+  <require
+      permission="zope.View"
+      interface="zope.app.interfaces.content.file.IReadFile"
+      attributes="getImageSize"
+      />
+
+  <require
+      permission="zope.ManageContent"
+      interface="zope.app.interfaces.content.file.IWriteFile"
+      set_schema="zope.app.interfaces.content.file.IReadFile"
+      />
+
+  <implements
+     interface="zope.app.interfaces.annotation.IAttributeAnnotatable"
+     />
+</content>
+
+<adapter
+    factory="zope.app.content.image.ImageSized"
+    provides="zope.app.interfaces.size.ISized"
+    for="zope.app.interfaces.content.image.IImage"
+    />
+
+<content class="zope.app.content.i18nimage.I18nImage">
+  <factory
+      id="I18nImage"
+      permission="zope.ManageContent"
+      title="I18n Image"
+      description="An Internationalized Image" />
+  <require
+      permission="zope.View"
+      interface="zope.app.interfaces.content.file.IReadFile"
+      attributes="getImageSize"
+      />
+  <require
+      permission="zope.ManageContent"
+      interface="zope.app.interfaces.content.file.IWriteFile" />
+  <require
+      permission="zope.View"
+      attributes="getDefaultLanguage getAvailableLanguages" />
+  <require
+      permission="zope.ManageContent"
+      attributes="setDefaultLanguage removeLanguage" />
+
+  <implements
+     interface="zope.app.interfaces.annotation.IAttributeAnnotatable"
+     />
 
-  </content>
+</content>
 
 
 <content class="zope.app.content.zpt.ZPTPage">
@@ -143,136 +148,138 @@
   <implements
       interface="zope.app.interfaces.annotation.IAttributeAnnotatable" />
 
-  </content>
+</content>
 
-  <adapter factory="zope.app.content.zpt.SearchableText"
+<adapter factory="zope.app.content.zpt.SearchableText"
          provides="zope.app.interfaces.index.text.interfaces.ISearchableText"
          for="zope.app.content.zpt.IZPTPage" />
 
 
-  <content class="zope.app.content.dtmlpage.DTMLPage">
+<content class="zope.app.content.dtmlpage.DTMLPage">
 
-    <factory
-        id="DTMLPage"
-        permission="zope.ManageContent"
-        title="DTML Page"
-        description="A simple, content-based Page Template" />
+  <factory
+      id="DTMLPage"
+      permission="zope.ManageContent"
+      title="DTML Page"
+      description="A simple, content-based Page Template" />
 
-    <require permission="zope.View"
-                      attributes="__call__" />
+  <require permission="zope.View"
+           attributes="__call__" />
 
-    <require permission="zope.ManageContent"
-                      interface="zope.app.content.dtmlpage.IDTMLPage" />
+  <require permission="zope.ManageContent"
+           interface="zope.app.content.dtmlpage.IDTMLPage" />
 
-    <require permission="zope.View"
-                      interface="zope.app.content.dtmlpage.IRenderDTMLPage" />
+  <require permission="zope.View"
+           interface="zope.app.content.dtmlpage.IRenderDTMLPage" />
 
 
-    <implements interface="zope.app.interfaces.annotation.IAttributeAnnotatable" />
+  <implements
+      interface="zope.app.interfaces.annotation.IAttributeAnnotatable" />
 
-  </content>
+</content>
 
 
-  <content class="zope.app.content.file.File">
+<content class="zope.app.content.file.File">
 
-    <factory
-        id="File"
-        permission="zope.ManageContent"
-        title="File"
-        description="A File" />
+  <factory
+      id="File"
+      permission="zope.ManageContent"
+      title="File"
+      description="A File" />
 
-    <require
-        permission="zope.View"
-        interface="zope.app.interfaces.content.file.IReadFile" />
+  <require
+      permission="zope.View"
+      interface="zope.app.interfaces.content.file.IReadFile" />
 
-    <require
-        permission="zope.ManageContent"
-        interface="zope.app.interfaces.content.file.IWriteFile"
-        set_schema="zope.app.interfaces.content.file.IReadFile"
-        />
+  <require
+      permission="zope.ManageContent"
+      interface="zope.app.interfaces.content.file.IWriteFile"
+      set_schema="zope.app.interfaces.content.file.IReadFile"
+      />
 
-    <implements
-       interface="zope.app.interfaces.annotation.IAttributeAnnotatable"
-       />
+  <implements
+     interface="zope.app.interfaces.annotation.IAttributeAnnotatable"
+     />
 
-  </content>
+</content>
 
-  <content class="zope.app.content.i18nfile.I18nFile">
+<content class="zope.app.content.i18nfile.I18nFile">
 
-     <factory
-         id="zope.app.content.I18nFile"
-         permission="zope.ManageContent"
-         title="I18n File"
-         description="An Internationalized File" />
-     <require
-         permission="zope.View"
-         interface="zope.app.interfaces.content.file.IReadFile" />
-     <require
-         permission="zope.ManageContent"
-         interface="zope.app.interfaces.content.file.IWriteFile" />
-     <require
-         permission="zope.View"
-         attributes="getDefaultLanguage getAvailableLanguages" />
-     <require
-         permission="zope.ManageContent"
-         attributes="setDefaultLanguage removeLanguage" />
+  <factory
+      id="zope.app.content.I18nFile"
+      permission="zope.ManageContent"
+      title="I18n File"
+      description="An Internationalized File" />
+  <require
+      permission="zope.View"
+      interface="zope.app.interfaces.content.file.IReadFile" />
+  <require
+      permission="zope.ManageContent"
+      interface="zope.app.interfaces.content.file.IWriteFile" />
+  <require
+      permission="zope.View"
+      attributes="getDefaultLanguage getAvailableLanguages" />
+  <require
+      permission="zope.ManageContent"
+      attributes="setDefaultLanguage removeLanguage" />
 
-    <implements
-       interface="zope.app.interfaces.annotation.IAttributeAnnotatable"
-       />
+  <implements
+     interface="zope.app.interfaces.annotation.IAttributeAnnotatable"
+     />
 
-   </content>
+</content>
 
-  <adapter factory="zope.app.content.file.SearchableText"
-           provides="zope.app.interfaces.index.text.interfaces.ISearchableText"
-           for="zope.app.interfaces.content.file.IReadFile" />
+<adapter factory="zope.app.content.file.SearchableText"
+         provides="zope.app.interfaces.index.text.interfaces.ISearchableText"
+         for="zope.app.interfaces.content.file.IReadFile" />
 
-  <!-- SQL Script Directives -->
+<!-- SQL Script Directives -->
 
-  <permission id="zope.AddSQLScripts" title="Add SQL Scripts" />
+<permission id="zope.AddSQLScripts" title="Add SQL Scripts" />
 
-  <content class="zope.app.content.sql.SQLScript">
+<content class="zope.app.content.sql.SQLScript">
 
-    <factory
-        id="SQLScript"
-        permission="zope.ManageContent"
-        title="SQL Script"
-        description="Dynamic SQL Script" />
+  <factory
+      id="SQLScript"
+      permission="zope.ManageContent"
+      title="SQL Script"
+      description="Dynamic SQL Script" />
 
-    <require
-        permission = "zope.ManageContent"
-        interface = "zope.app.interfaces.content.sql.ISQLScript."
-        set_schema = "zope.app.interfaces.content.sql.ISQLScript."
-        />
+  <require
+      permission = "zope.ManageContent"
+      interface = "zope.app.interfaces.content.sql.ISQLScript."
+      set_schema = "zope.app.interfaces.content.sql.ISQLScript."
+      />
 
-    <require
-        permission="zope.ManageContent"
-        interface="zope.app.interfaces.content.file.IFileContent" />
+  <require
+      permission="zope.ManageContent"
+      interface="zope.app.interfaces.content.file.IFileContent" />
 
-    <implements interface="zope.app.interfaces.annotation.IAttributeAnnotatable" />
+  <implements
+      interface="zope.app.interfaces.annotation.IAttributeAnnotatable" />
 
-  </content>
+</content>
 
 
-  <!-- Arguments Directives -->
+<!-- Arguments Directives -->
 
-  <content class="zope.app.content.sql.Arguments">
-    <require
-        permission="zope.ManageContent"
-        interface="zope.interface.common.mapping.IEnumerableMapping" />
-  </content>
+<content class="zope.app.content.sql.Arguments">
+  <require
+      permission="zope.ManageContent"
+      interface="zope.interface.common.mapping.IEnumerableMapping" />
+</content>
 
 
-  <!-- SQL DTML Directives -->
+<!-- SQL DTML Directives -->
 
-  <content class="zope.app.content.sql.SQLDTML">
-    <require
-        permission="zope.ManageContent"
-        attributes="__call__" />
-  </content>
+<content class="zope.app.content.sql.SQLDTML">
+  <require
+      permission="zope.ManageContent"
+      attributes="__call__" />
+</content>
 
 
-  <!-- Further Directives -->
+<!-- Further Directives -->
 
 
 </zopeConfigure>


=== Zope3/src/zope/app/content/image.py 1.2 => 1.3 ===
--- Zope3/src/zope/app/content/image.py:1.2	Wed Dec 25 09:12:48 2002
+++ Zope3/src/zope/app/content/image.py	Fri Dec 27 14:19:09 2002
@@ -18,6 +18,10 @@
 from zope.app.content.file import File
 from cStringIO import StringIO
 from zope.app.interfaces.content.image import IImage
+from zope.app.interfaces.size import ISized
+from zope.app.size import byteDisplay
+
+__metaclass__ = type
 
 class Image(File):
     __implements__ = IImage
@@ -47,6 +51,23 @@
                     """Contains the data of the file.""")
 
 
+class ImageSized:
+
+    __implements__ = ISized
+
+    def __init__(self, image):
+        self._image = image
+
+    def sizeForSorting(self):
+        'See ISized'
+        return ('byte', self._image.getSize())
+
+    def sizeForDisplay(self):
+        'See ISized'
+        w, h = self._image.getImageSize()
+        bytes = self._image.getSize()
+        return '%s %rx%r' % (byteDisplay(bytes), w, h)
+    
 def getImageInfo(data):
     data = str(data)
     size = len(data)