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

Steve Alexander steve@cat-box.net
Fri, 27 Dec 2002 13:23:28 -0500


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

Modified Files:
	size.py 
Log Message:
units should be singular.
added a sized adapter for containers that presents the number of items
contained.
If you have a kind of container for which it is expensive to get the
number of items contained, then you should make an ISized for that
container.


=== Zope3/src/zope/app/size.py 1.1 => 1.2 ===
--- Zope3/src/zope/app/size.py:1.1	Fri Dec 27 10:22:50 2002
+++ Zope3/src/zope/app/size.py	Fri Dec 27 13:22:57 2002
@@ -31,7 +31,7 @@
         except (AttributeError, ValueError, TypeError):
             self._sortingSize = None, None
         else:
-            self._sortingSize = 'bytes', size
+            self._sortingSize = 'byte', size
 
     def sizeForSorting(self):
         """See ISized"""
@@ -40,13 +40,12 @@
     def sizeForDisplay(self):
         """See ISized"""
         units, size = self._sortingSize
-        if units == 'bytes':
-            result = u''
+        if units == 'byte':
+            if size == 0:
+                return '0 KB'
             if size < 1024:
-                result = "1 KB"
-            elif size > 1048576:
-                result = "%0.02f MB" % (size / 1048576.0)
-            else:
-                result = "%d KB" % (size / 1024.0)
-            return result
+                return '1 KB'
+            if size > 1048576:
+                return '%0.02f MB' % (size / 1048576.0)
+            return '%d KB' % (size / 1024.0)
         return u'n/a'