Beispiel #1
0
def _stream_to_byte_stream(stream, src_format):
    """Convert a record stream to a self delimited byte stream."""
    pack_writer = pack.ContainerSerialiser()
    yield pack_writer.begin()
    yield pack_writer.bytes_record(src_format.network_name(), '')
    for substream_type, substream in stream:
        for record in substream:
            if record.storage_kind in ('chunked', 'fulltext'):
                serialised = record_to_fulltext_bytes(record)
            elif record.storage_kind == 'absent':
                raise ValueError("Absent factory for %s" % (record.key,))
            else:
                serialised = record.get_bytes_as(record.storage_kind)
            if serialised:
                # Some streams embed the whole stream into the wire
                # representation of the first record, which means that
                # later records have no wire representation: we skip them.
                yield pack_writer.bytes_record(serialised, [(substream_type,)])
    yield pack_writer.end()
Beispiel #2
0
 def test_bytes_record_two_names(self):
     serialiser = pack.ContainerSerialiser()
     record = serialiser.bytes_record('bytes', [('name1', ), ('name2', )])
     self.assertEqual('B5\nname1\nname2\n\nbytes', record)
Beispiel #3
0
 def test_bytes_record_whitespace_in_name_part(self):
     serialiser = pack.ContainerSerialiser()
     self.assertRaises(errors.InvalidRecordError, serialiser.bytes_record,
                       'bytes', [('bad name', )])
Beispiel #4
0
 def test_bytes_record_one_name_with_one_part(self):
     serialiser = pack.ContainerSerialiser()
     record = serialiser.bytes_record('bytes', [('name', )])
     self.assertEqual('B5\nname\n\nbytes', record)
Beispiel #5
0
 def test_bytes_record_one_name_with_two_parts(self):
     serialiser = pack.ContainerSerialiser()
     record = serialiser.bytes_record('bytes', [('part1', 'part2')])
     self.assertEqual('B5\npart1\x00part2\n\nbytes', record)
Beispiel #6
0
 def test_bytes_record_no_name(self):
     serialiser = pack.ContainerSerialiser()
     record = serialiser.bytes_record('bytes', [])
     self.assertEqual('B5\n\nbytes', record)
Beispiel #7
0
 def test_end(self):
     serialiser = pack.ContainerSerialiser()
     self.assertEqual('E', serialiser.end())
Beispiel #8
0
 def test_begin(self):
     serialiser = pack.ContainerSerialiser()
     self.assertEqual('Bazaar pack format 1 (introduced in 0.18)\n',
                      serialiser.begin())
Beispiel #9
0
 def test_construct(self):
     """Test constructing a ContainerSerialiser."""
     pack.ContainerSerialiser()
Beispiel #10
0
 def test_bytes_record_header(self):
     serialiser = pack.ContainerSerialiser()
     record = serialiser.bytes_header(32, [('name1', ), ('name2', )])
     self.assertEqual('B32\nname1\nname2\n\n', record)