def test_humanReadableFileSize(self): """ L{eridanus.util.humanReadableFileSize} correctly converts a value in bytes to something easier for a human to interpret. """ self.assertEqual(util.humanReadableFileSize(1023), u'1023 bytes') self.assertEqual(util.humanReadableFileSize(1024), u'1.00 KB') self.assertEqual(util.humanReadableFileSize(1024 ** 3), u'1.00 GB') self.assertNotEqual(util.humanReadableFileSize(1023), u'1023.00 bytes') self.assertNotEqual(util.humanReadableFileSize(1024), u'1024 bytes')
def test_humanReadableFileSize(self): """ L{eridanus.util.humanReadableFileSize} correctly converts a value in bytes to something easier for a human to interpret. """ self.assertEqual(util.humanReadableFileSize(1023), u'1023 bytes') self.assertEqual(util.humanReadableFileSize(1024), u'1.00 KB') self.assertEqual(util.humanReadableFileSize(1024**3), u'1.00 GB') self.assertNotEqual(util.humanReadableFileSize(1023), u'1023.00 bytes') self.assertNotEqual(util.humanReadableFileSize(1024), u'1024 bytes')
def _buildMetadata(data, headers): """ Create entry metadata from C{data} and C{headers}. @rtype: C{iterable} of C{(unicode, unicode)} @return: Iterable of C{(key, value)} pairs """ def getHeader(name): h = headers.getRawHeaders(name) if h is not None: return unicode(h[0], 'ascii') return None contentType = getHeader('content-type') if contentType is not None: yield u'contentType', contentType if contentType.startswith('image'): for info in _extractImageMetadata(StringIO(data)): yield info size = getHeader('content-range') if size is not None: if size.startswith('bytes'): size = int(size.split(u'/')[-1]) yield u'size', util.humanReadableFileSize(size)
def test_buildMetadata(self): """ Metadata for an HTTP resource is extracted from the HTTP headers and any available resource data. """ data = self.pngStream.read() md = dict(linkdb._buildMetadata(data, {})) self.assertEquals({}, md) md = dict(linkdb._buildMetadata(data, {'content-type': ['text/plain']})) self.assertEquals({u'contentType': u'text/plain'}, md) md = dict( linkdb._buildMetadata(data, {'content-range': ['bytes 10240/20480']})) self.assertEquals({u'size': util.humanReadableFileSize(20480)}, md)
def test_buildMetadata(self): """ Metadata for an HTTP resource is extracted from the HTTP headers and any available resource data. """ data = self.pngStream.read() md = dict(linkdb._buildMetadata(data, Headers())) self.assertEquals({}, md) md = dict(linkdb._buildMetadata(data, Headers({ 'content-type': ['text/plain']}))) self.assertEquals({ u'contentType': u'text/plain'}, md) md = dict(linkdb._buildMetadata( data, Headers({'content-range': ['bytes 10240/20480']}))) self.assertEquals({ u'size': util.humanReadableFileSize(20480)}, md)