/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/bundle/serializer/v08.py

  • Committer: Breezy landing bot
  • Author(s): Jelmer Vernooij
  • Date: 2018-07-11 21:04:12 UTC
  • mfrom: (7031.1.4 python3-diff)
  • Revision ID: breezy.the.bot@gmail.com-20180711210412-l80sfib91f3uhwc0
Port diff and merge_directive to Python 3.

Merged from https://code.launchpad.net/~jelmer/brz/python3-diff/+merge/349216

Show diffs side-by-side

added added

removed removed

Lines of Context:
247
247
                            trailing_space_when_empty=True)
248
248
 
249
249
        # Add an extra blank space at the end
250
 
        self.to_file.write('\n')
 
250
        self.to_file.write(b'\n')
251
251
 
252
252
    def _write_action(self, name, parameters, properties=None):
253
253
        if properties is None:
254
254
            properties = []
255
255
        p_texts = ['%s:%s' % v for v in properties]
256
 
        self.to_file.write('=== ')
 
256
        self.to_file.write(b'=== ')
257
257
        self.to_file.write(' '.join([name]+parameters).encode('utf-8'))
258
258
        self.to_file.write(' // '.join(p_texts).encode('utf-8'))
259
 
        self.to_file.write('\n')
 
259
        self.to_file.write(b'\n')
260
260
 
261
261
    def _write_delta(self, new_tree, old_tree, default_revision_id,
262
262
                     force_binary):
404
404
        for line in self._next():
405
405
            # The bzr header is terminated with a blank line
406
406
            # which does not start with '#'
407
 
            if line is None or line == '\n':
 
407
            if line is None or line == b'\n':
408
408
                break
409
 
            if not line.startswith('#'):
 
409
            if not line.startswith(b'#'):
410
410
                continue
411
411
            found_something = True
412
412
            self._handle_next(line)
418
418
    def _read_next_entry(self, line, indent=1):
419
419
        """Read in a key-value pair
420
420
        """
421
 
        if not line.startswith('#'):
 
421
        if not line.startswith(b'#'):
422
422
            raise errors.MalformedHeader('Bzr header did not start with #')
423
423
        line = line[1:-1].decode('utf-8') # Remove the '#' and '\n'
424
424
        if line[:indent] == ' '*indent:
425
425
            line = line[indent:]
426
426
        if not line:
427
 
            return None, None# Ignore blank lines
 
427
            return None, None # Ignore blank lines
428
428
 
429
429
        loc = line.find(': ')
430
430
        if loc != -1:
458
458
                    value = value.encode('utf8')
459
459
                elif key in ('parent_ids'):
460
460
                    value = [v.encode('utf8') for v in value]
 
461
                elif key in ('testament_sha1'):
 
462
                    value = value.encode('ascii')
461
463
                setattr(revision_info, key, value)
462
464
            else:
463
465
                raise errors.MalformedHeader('Duplicated Key: %s' % key)
473
475
        does not start properly indented.
474
476
        """
475
477
        values = []
476
 
        start = '#' + (' '*indent)
 
478
        start = b'#' + (b' '*indent)
477
479
 
478
480
        if self._next_line is None or self._next_line[:len(start)] != start:
479
481
            return values
492
494
        """
493
495
        #mutter('_read_one_patch: %r' % self._next_line)
494
496
        # Peek and see if there are no patches
495
 
        if self._next_line is None or self._next_line.startswith('#'):
 
497
        if self._next_line is None or self._next_line.startswith(b'#'):
496
498
            return None, [], False
497
499
 
498
500
        first = True
499
501
        lines = []
500
502
        for line in self._next():
501
503
            if first:
502
 
                if not line.startswith('==='):
 
504
                if not line.startswith(b'==='):
503
505
                    raise errors.MalformedPatches('The first line of all patches'
504
506
                        ' should be a bzr meta line "==="'
505
507
                        ': %r' % line)
506
508
                action = line[4:-1].decode('utf-8')
507
 
            elif line.startswith('... '):
508
 
                action += line[len('... '):-1].decode('utf-8')
 
509
            elif line.startswith(b'... '):
 
510
                action += line[len(b'... '):-1].decode('utf-8')
509
511
 
510
512
            if (self._next_line is not None and
511
 
                self._next_line.startswith('===')):
 
513
                self._next_line.startswith(b'===')):
512
514
                return action, lines, True
513
 
            elif self._next_line is None or self._next_line.startswith('#'):
 
515
            elif self._next_line is None or self._next_line.startswith(b'#'):
514
516
                return action, lines, False
515
517
 
516
518
            if first:
517
519
                first = False
518
 
            elif not line.startswith('... '):
 
520
            elif not line.startswith(b'... '):
519
521
                lines.append(line)
520
522
 
521
523
        return action, lines, False
541
543
            self._handle_next(line)
542
544
            if self._next_line is None:
543
545
                break
544
 
            if not self._next_line.startswith('#'):
 
546
            if not self._next_line.startswith(b'#'):
545
547
                # Consume the trailing \n and stop processing
546
548
                next(self._next())
547
549
                break