~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/xml6.py

  • Committer: Martin Pool
  • Date: 2008-03-16 08:25:21 UTC
  • mto: (3280.2.2 prepare-1.3)
  • mto: This revision was merged to the branch mainline in revision 3284.
  • Revision ID: mbp@sourcefrog.net-20080316082521-xmex8wq1uyj6cxyh
Fix doctest syntax

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006 Canonical Ltd
 
1
# Copyright (C) 2005, 2006, 2007 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
18
18
 
19
19
 
20
20
class Serializer_v6(xml5.Serializer_v5):
 
21
    """This serialiser adds rich roots."""
 
22
 
 
23
    format_num = '6'
 
24
    root_id = None
21
25
 
22
26
    def _append_inventory_root(self, append, inv):
23
27
        """Append the inventory root to output."""
24
 
        append('<inventory')
25
 
        append(' format="6"')
26
28
        if inv.revision_id is not None:
27
 
            append(' revision_id="')
28
 
            append(xml5._encode_and_escape(inv.revision_id))
29
 
        append('>\n')
30
 
        self._append_entry(append, inv.root)
31
 
 
32
 
    def _parent_condition(self, ie):
33
 
        return ie.parent_id is not None
34
 
 
35
 
    def _unpack_inventory(self, elt):
 
29
            revid1 = ' revision_id="'
 
30
            revid2 = xml5._encode_and_escape(inv.revision_id)
 
31
        else:
 
32
            revid1 = ""
 
33
            revid2 = ""
 
34
        append('<inventory format="%s"%s%s>\n' % (
 
35
            self.format_num, revid1, revid2))
 
36
        append('<directory file_id="%s name="%s revision="%s />\n' % (
 
37
            xml5._encode_and_escape(inv.root.file_id),
 
38
            xml5._encode_and_escape(inv.root.name),
 
39
            xml5._encode_and_escape(inv.root.revision)))
 
40
 
 
41
    def _check_revisions(self, inv):
 
42
        """Extension point for subclasses to check during serialisation.
 
43
 
 
44
        By default no checking is done.
 
45
 
 
46
        :param inv: An inventory about to be serialised, to be checked.
 
47
        :raises: AssertionError if an error has occured.
 
48
        """
 
49
        assert inv.revision_id is not None
 
50
        assert inv.root.revision is not None
 
51
 
 
52
    def _unpack_inventory(self, elt, revision_id=None):
36
53
        """Construct from XML Element"""
37
54
        if elt.tag != 'inventory':
38
55
            raise errors.UnexpectedInventoryFormat('Root tag is %r' % elt.tag)
39
56
        format = elt.get('format')
40
 
        if format != '6':
 
57
        if format != self.format_num:
41
58
            raise errors.UnexpectedInventoryFormat('Invalid format version %r'
42
59
                                                   % format)
43
60
        revision_id = elt.get('revision_id')
45
62
            revision_id = cache_utf8.encode(revision_id)
46
63
        inv = inventory.Inventory(root_id=None, revision_id=revision_id)
47
64
        for e in elt:
48
 
            ie = self._unpack_entry(e, none_parents=True)
 
65
            ie = self._unpack_entry(e)
49
66
            inv.add(ie)
 
67
        assert inv.root.revision is not None
50
68
        return inv
51
69
 
52
70