Exemplo n.º 1
0
 def chunk_get(self, url, check_headers=True, **kwargs):
     """
     :keyword check_headers: when True (the default), raise FaultyChunk
         if a mandatory response header is missing.
     :returns: a tuple with a dictionary of chunk metadata and a stream
         to the chunk's data.
     """
     url = self.resolve_url(url)
     reader = ChunkReader([{'url': url}], READ_BUFFER_SIZE, **kwargs)
     # This must be done now if we want to access headers
     stream = reader.stream()
     headers = extract_headers_meta(reader.headers, check=check_headers)
     return headers, stream
Exemplo n.º 2
0
    def test_reader_buf_resume(self):
        chunk = {}

        reader = ChunkReader(None, 8, {})

        # provide source0 with failure
        source0 = FakeSource(['1234', 'abcd', '123', None])

        it = reader._create_iter(chunk, source0)
        # provide source1 for recovery
        source1 = FakeSource(['5678efgh'])
        with patch.object(reader, '_get_source', lambda: (source1, chunk)):
            data = list(it)

        self.assertEqual(data, ['1234abcd', '5678efgh'])
Exemplo n.º 3
0
 def read_meta_chunk(self, storage_method, meta_chunk, headers={}):
     handler = ChunkReader(meta_chunk, None, headers)
     stream = handler.get_iter()
     return Response(part_iter_to_bytes_iter(stream), 200)