/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/_groupcompress_py.py

  • Committer: Breezy landing bot
  • Author(s): Martin
  • Date: 2017-06-11 01:56:34 UTC
  • mfrom: (6684.1.5 py3_bootstrap2)
  • Revision ID: breezy.the.bot@gmail.com-20170611015634-9eeh86thh073hcko
More progress towards Python 3 support

Merged from https://code.launchpad.net/~gz/brz/py3_bootstrap2/+merge/325452

Show diffs side-by-side

added added

removed removed

Lines of Context:
290
290
        if bytes_length is None:
291
291
            bytes_length = sum(map(len, new_lines))
292
292
        # reserved for content type, content length
293
 
        out_lines = ['', '', encode_base128_int(bytes_length)]
 
293
        out_lines = [b'', b'', encode_base128_int(bytes_length)]
294
294
        index_lines = [False, False, False]
295
295
        output_handler = _OutputHandler(out_lines, index_lines,
296
296
                                        self._MIN_MATCH_BYTES)
316
316
 
317
317
def encode_base128_int(val):
318
318
    """Convert an integer into a 7-bit lsb encoding."""
319
 
    bytes = []
 
319
    data = bytearray()
320
320
    count = 0
321
321
    while val >= 0x80:
322
 
        bytes.append(chr((val | 0x80) & 0xFF))
 
322
        data.append((val | 0x80) & 0xFF)
323
323
        val >>= 7
324
 
    bytes.append(chr(val))
325
 
    return ''.join(bytes)
326
 
 
327
 
 
328
 
def decode_base128_int(bytes):
 
324
    data.append(val)
 
325
    return bytes(data)
 
326
 
 
327
 
 
328
def decode_base128_int(data):
329
329
    """Decode an integer from a 7-bit lsb encoding."""
330
330
    offset = 0
331
331
    val = 0
332
332
    shift = 0
333
 
    bval = ord(bytes[offset])
 
333
    bval = ord(data[offset])
334
334
    while bval >= 0x80:
335
335
        val |= (bval & 0x7F) << shift
336
336
        shift += 7
337
337
        offset += 1
338
 
        bval = ord(bytes[offset])
 
338
        bval = ord(data[offset])
339
339
    val |= bval << shift
340
340
    offset += 1
341
341
    return val, offset