[Zope3-checkins] CVS: Zope3/src/zope/app - size.py:1.3

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


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

Modified Files:
	size.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/size.py 1.2 => 1.3 ===
--- Zope3/src/zope/app/size.py:1.2	Fri Dec 27 13:22:57 2002
+++ Zope3/src/zope/app/size.py	Fri Dec 27 14:19:09 2002
@@ -41,11 +41,15 @@
         """See ISized"""
         units, size = self._sortingSize
         if units == 'byte':
-            if size == 0:
-                return '0 KB'
-            if size < 1024:
-                return '1 KB'
-            if size > 1048576:
-                return '%0.02f MB' % (size / 1048576.0)
-            return '%d KB' % (size / 1024.0)
+            return byteDisplay(size)
         return u'n/a'
+
+def byteDisplay(size):
+    if size == 0:
+        return '0 KB'
+    if size < 1024:
+        return '1 KB'
+    if size > 1048576:
+        return '%0.02f MB' % (size / 1048576.0)
+    return '%d KB' % (size / 1024.0)
+