1
# Copyright (C) 2005, 2006 Canonical Ltd
1
# Copyright (C) 2005, 2006, 2007 Canonical Ltd
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
20
20
class Serializer_v6(xml5.Serializer_v5):
21
"""This serialiser adds rich roots."""
22
26
def _append_inventory_root(self, append, inv):
23
27
"""Append the inventory root to output."""
26
28
if inv.revision_id is not None:
27
append(' revision_id="')
28
append(xml5._encode_and_escape(inv.revision_id))
30
self._append_entry(append, inv.root)
32
def _parent_condition(self, ie):
33
return ie.parent_id is not None
35
def _unpack_inventory(self, elt):
29
revid1 = ' revision_id="'
30
revid2 = xml5._encode_and_escape(inv.revision_id)
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)))
41
def _check_revisions(self, inv):
42
"""Extension point for subclasses to check during serialisation.
44
By default no checking is done.
46
:param inv: An inventory about to be serialised, to be checked.
47
:raises: AssertionError if an error has occured.
49
assert inv.revision_id is not None
50
assert inv.root.revision is not None
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')
57
if format != self.format_num:
41
58
raise errors.UnexpectedInventoryFormat('Invalid format version %r'
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)
48
ie = self._unpack_entry(e, none_parents=True)
65
ie = self._unpack_entry(e)
67
assert inv.root.revision is not None