Exemplo n.º 1
0
    def test_proxy_producer_streaming(self):
        """Test ProxyHashingProducer."""
        data = os.urandom(1024 * 10)
        message = zlib.compress(data)
        ds = diskstorage.DiskStorage(os.path.join(self.tmpdir, "testfile"))
        consumer = ds.put("somenode")
        producer = upload.ProxyHashingProducer(consumer, True)

        chunk_sz = 10
        for part in xrange(0, len(message), chunk_sz):
            yield producer.dataReceived(message[part:part + chunk_sz])
        producer.stopProducing()
        yield producer.flush_decompressor()

        with open(consumer.filepath, "rb") as fh:
            self.assertEqual(fh.read(), message)
        hasher = content_hash_factory()
        hasher.update(data)
        self.assertEqual(producer.hash_object.content_hash(),
                         hasher.content_hash())
        magic_hasher = magic_hash_factory()
        magic_hasher.update(data)
        self.assertEqual(producer.magic_hash_object.content_hash()._magic_hash,
                         magic_hasher.content_hash()._magic_hash)
        self.assertEqual(producer.inflated_size, len(data))
        self.assertEqual(producer.crc32, crc32(data))
Exemplo n.º 2
0
 def __init__(self, hash_factory=content_hash_factory,
              decompressobj_factory=zlib.decompressobj,
              magic_hash_factory=magic_hash_factory):
     self.decompressor = decompressobj_factory()
     self.hash_object = hash_factory()
     self.magic_hash_object = magic_hash_factory()
     self.crc32 = 0
     self.inflated_size = 0
Exemplo n.º 3
0
 def __init__(self, consumer, streaming):
     self.decompressor = zlib.decompressobj()
     self.hash_object = content_hash_factory()
     self.magic_hash_object = magic_hash_factory()
     self.crc32 = 0
     self.inflated_size = 0
     self.deflated_size = 0
     self.consumer = consumer
     self.streaming = streaming
Exemplo n.º 4
0
    def test_resumable_hashing(self):
        """Resuming hash has the same result as hashlib."""
        results = []
        data = "Freedom is slavery" * 1000

        sha = magic_hash_factory()
        sha.update(data)
        results.append(sha.content_hash()._magic_hash)

        sha = rhashlib.resumable_magic_hash_factory()
        sha.update(data[:500])

        sha2 = rhashlib.resumable_magic_hash_factory()
        sha2.set_context(sha.get_context())
        sha2.update(data[500:])

        results.append(sha2.content_hash()._magic_hash)

        self.assertEqual(*results)
 def test_magic_hash_factory(self):
     """Check the factory for the magic content hash."""
     o = magic_hash_factory()
     self.assertTrue(isinstance(o, MagicContentHash))