/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/index.py

  • Committer: Breezy landing bot
  • Author(s): Martin
  • Date: 2017-06-10 02:49:30 UTC
  • mfrom: (6677.1.4 py3_bootstrap)
  • Revision ID: breezy.the.bot@gmail.com-20170610024930-enw8wdbjy9s4dtnm
Progress on Python 3 to get TestCaseWithTransport working

Merged from https://code.launchpad.net/~gz/brz/py3_bootstrap/+merge/325439

Show diffs side-by-side

added added

removed removed

Lines of Context:
50
50
from .static_tuple import StaticTuple
51
51
 
52
52
_HEADER_READV = (0, 200)
53
 
_OPTION_KEY_ELEMENTS = "key_elements="
54
 
_OPTION_LEN = "len="
55
 
_OPTION_NODE_REFS = "node_ref_lists="
56
 
_SIGNATURE = "Bazaar Graph Index 1\n"
 
53
_OPTION_KEY_ELEMENTS = b"key_elements="
 
54
_OPTION_LEN = b"len="
 
55
_OPTION_NODE_REFS = b"node_ref_lists="
 
56
_SIGNATURE = b"Bazaar Graph Index 1\n"
57
57
 
58
58
 
59
59
_whitespace_re = re.compile('[\t\n\x0b\x0c\r\x00 ]')
257
257
        should be written to disk.
258
258
        """
259
259
        lines = [_SIGNATURE]
260
 
        lines.append(_OPTION_NODE_REFS + str(self.reference_lists) + '\n')
261
 
        lines.append(_OPTION_KEY_ELEMENTS + str(self._key_length) + '\n')
 
260
        lines.append(b'%s%d\n' % (_OPTION_NODE_REFS, self.reference_lists))
 
261
        lines.append(b'%s%d\n' % (_OPTION_KEY_ELEMENTS, self._key_length))
262
262
        key_count = len(self._nodes) - len(self._absent_keys)
263
 
        lines.append(_OPTION_LEN + str(key_count) + '\n')
 
263
        lines.append(b'%s%d\n' % (_OPTION_LEN, key_count))
264
264
        prefix_length = sum(len(x) for x in lines)
265
265
        # references are byte offsets. To avoid having to do nasty
266
266
        # polynomial work to resolve offsets (references to later in the
323
323
            for key, non_ref_bytes, total_references in key_offset_info:
324
324
                key_addresses[key] = non_ref_bytes + total_references*digits
325
325
            # serialise
326
 
            format_string = '%%0%sd' % digits
 
326
            format_string = b'%%0%dd' % digits
327
327
        for key, (absent, references, value) in nodes:
328
328
            flattened_references = []
329
329
            for ref_list in references:
330
330
                ref_addresses = []
331
331
                for reference in ref_list:
332
332
                    ref_addresses.append(format_string % key_addresses[reference])
333
 
                flattened_references.append('\r'.join(ref_addresses))
334
 
            string_key = '\x00'.join(key)
335
 
            lines.append("%s\x00%s\x00%s\x00%s\n" % (string_key, absent,
336
 
                '\t'.join(flattened_references), value))
337
 
        lines.append('\n')
338
 
        result = BytesIO(''.join(lines))
 
333
                flattened_references.append(b'\r'.join(ref_addresses))
 
334
            string_key = b'\x00'.join(key)
 
335
            lines.append(b"%s\x00%s\x00%s\x00%s\n" % (string_key, absent,
 
336
                b'\t'.join(flattened_references), value))
 
337
        lines.append(b'\n')
 
338
        result = BytesIO(b''.join(lines))
339
339
        if expected_bytes and len(result.getvalue()) != expected_bytes:
340
340
            raise errors.BzrError('Failed index creation. Internal error:'
341
341
                ' mismatched output length and expected length: %d %d' %