~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/xml5.py

  • Committer: Michael Ellerman
  • Date: 2006-02-28 14:45:51 UTC
  • mto: (1558.1.18 Aaron's integration)
  • mto: This revision was merged to the branch mainline in revision 1586.
  • Revision ID: michael@ellerman.id.au-20060228144551-3d9941ecde4a0b0a
Update contrib/pwk for -p1 diffs from bzr

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006 Canonical Ltd
2
 
#
3
1
# This program is free software; you can redistribute it and/or modify
4
2
# it under the terms of the GNU General Public License as published by
5
3
# the Free Software Foundation; either version 2 of the License, or
15
13
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
14
 
17
15
 
18
 
from bzrlib.xml_serializer import SubElement, Element, Serializer
 
16
from bzrlib.xml_serializer import ElementTree, SubElement, Element, Serializer
19
17
from bzrlib.inventory import ROOT_ID, Inventory, InventoryEntry
20
18
import bzrlib.inventory as inventory
21
 
from bzrlib.revision import Revision
 
19
from bzrlib.revision import Revision        
22
20
from bzrlib.errors import BzrError
23
21
 
24
22
 
37
35
        e.text = '\n'
38
36
        if inv.root.file_id not in (None, ROOT_ID):
39
37
            e.set('file_id', inv.root.file_id)
40
 
        if inv.revision_id is not None:
41
 
            e.set('revision_id', inv.revision_id)
42
38
        for path, ie in inv.iter_entries():
43
39
            e.append(self._pack_entry(ie))
44
40
        return e
45
41
 
 
42
 
46
43
    def _pack_entry(self, ie):
47
44
        """Convert InventoryEntry to XML element"""
48
 
        # TODO: should just be a plain assertion
49
45
        if not InventoryEntry.versionable_kind(ie.kind):
50
46
            raise AssertionError('unsupported entry kind %s' % ie.kind)
51
47
        e = Element(ie.kind)
69
65
        if ie.parent_id != ROOT_ID:
70
66
            assert isinstance(ie.parent_id, basestring)
71
67
            e.set('parent_id', ie.parent_id)
 
68
 
72
69
        e.tail = '\n'
 
70
 
73
71
        return e
74
72
 
 
73
 
75
74
    def _pack_revision(self, rev):
76
75
        """Revision object -> xml tree"""
77
76
        root = Element('revision',
122
121
            if format != '5':
123
122
                raise BzrError("invalid format version %r on inventory"
124
123
                                % format)
125
 
        revision_id = elt.get('revision_id')
126
 
        inv = Inventory(root_id, revision_id=revision_id)
 
124
        inv = Inventory(root_id)
127
125
        for e in elt:
128
126
            ie = self._unpack_entry(e)
129
127
            if ie.parent_id == ROOT_ID:
199
197
            return
200
198
        for prop_elt in props_elt:
201
199
            assert prop_elt.tag == 'property', \
202
 
                "bad tag under properties list: %r" % prop_elt.tag
 
200
                "bad tag under properties list: %r" % p.tag
203
201
            name = prop_elt.get('name')
204
202
            value = prop_elt.text
205
203
            assert name not in rev.properties, \
206
 
                "repeated property %r" % name
 
204
                "repeated property %r" % p.name
207
205
            rev.properties[name] = value
208
206
 
209
207