~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/xml6.py

Merge bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
from bzrlib import cache_utf8, inventory, errors, xml5
 
2
 
 
3
 
 
4
class Serializer_v6(xml5.Serializer_v5):
 
5
 
 
6
    def _append_inventory_root(self, append, inv):
 
7
        """Append the inventory root to output."""
 
8
        append('<inventory')
 
9
        append(' format="6"')
 
10
        if inv.revision_id is not None:
 
11
            append(' revision_id="')
 
12
            append(xml5._encode_and_escape(inv.revision_id))
 
13
        append('>\n')
 
14
        self._append_entry(append, inv.root)
 
15
 
 
16
    def _parent_condition(self, ie):
 
17
        return ie.parent_id is not None
 
18
 
 
19
    def _unpack_inventory(self, elt):
 
20
        """Construct from XML Element"""
 
21
        if elt.tag != 'inventory':
 
22
            raise errors.UnexpectedInventoryFormat('Root tag is %r' % elt.tag)
 
23
        format = elt.get('format')
 
24
        if format != '6':
 
25
            raise errors.UnexpectedInventoryFormat('Invalid format version %r'
 
26
                                                   % format)
 
27
        revision_id = elt.get('revision_id')
 
28
        if revision_id is not None:
 
29
            revision_id = cache_utf8.get_cached_unicode(revision_id)
 
30
        inv = inventory.Inventory(root_id=None, revision_id=revision_id)
 
31
        for e in elt:
 
32
            ie = self._unpack_entry(e, none_parents=True)
 
33
            inv.add(ie)
 
34
        return inv
 
35
 
 
36
 
 
37
serializer_v6 = Serializer_v6()