Exemple #1
0
 def test_byteDisplay(self):
     from zope.app.size import byteDisplay
     self.assertEqual(byteDisplay(0), u'0 KB')
     self.assertEqual(byteDisplay(1), u'1 KB')
     self.assertEqual(byteDisplay(2048), u'${size} KB')
     self.assertEqual(byteDisplay(2048).mapping, {'size': '2'})
     self.assertEqual(byteDisplay(2000000), u'${size} MB')
     self.assertEqual(byteDisplay(2000000).mapping, {'size': '1.91'})
Exemple #2
0
 def sizeForDisplay(self):
     '''See `ISized`'''
     w, h = self._image.getImageSize()
     if w < 0:
         w = '?'
     if h < 0:
         h = '?'
     bytes = self._image.getSize()
     byte_size = byteDisplay(bytes)
     mapping = byte_size.mapping
     if mapping is None:
         mapping = {}
     mapping.update({'width': str(w), 'height': str(h)})
     #TODO the way this message id is defined, it won't be picked up by
     # i18nextract and never show up in message catalogs
     return _(byte_size + ' ${width}x${height}', mapping=mapping)
Exemple #3
0
 def getSize(self):
     """Get the database size in a human readable format."""
     size = self.request.publication.db.getSize()
     if not isinstance(size, (int, long, float)):
         return str(size)
     return byteDisplay(size)