~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/xml5.py

  • Committer: Robert Collins
  • Date: 2005-10-15 11:38:29 UTC
  • mfrom: (1185.16.40)
  • Revision ID: robertc@lifelesslap.robertcollins.net-20051015113829-40226233fb246920
mergeĀ fromĀ martin

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
from bzrlib.errors import BzrError
23
23
 
24
24
 
25
 
 
26
 
 
27
 
 
28
25
class Serializer_v5(Serializer):
29
26
    """Version 5 serializer
30
27
 
99
96
                p = SubElement(pelts, 'revision_ref')
100
97
                p.tail = '\n'
101
98
                p.set('revision_id', parent_id)
 
99
        if rev.properties:
 
100
            self._pack_revision_properties(rev, root)
102
101
        return root
103
 
    
 
102
 
 
103
 
 
104
    def _pack_revision_properties(self, rev, under_element):
 
105
        top_elt = SubElement(under_element, 'properties')
 
106
        for prop_name, prop_value in sorted(rev.properties.items()):
 
107
            assert isinstance(prop_name, basestring) 
 
108
            assert isinstance(prop_value, basestring) 
 
109
            prop_elt = SubElement(top_elt, 'property')
 
110
            prop_elt.set('name', prop_name)
 
111
            prop_elt.text = prop_value
 
112
            prop_elt.tail = '\n'
 
113
        top_elt.tail = '\n'
 
114
 
104
115
 
105
116
    def _unpack_inventory(self, elt):
106
117
        """Construct from XML Element
173
184
            assert p.tag == 'revision_ref', \
174
185
                   "bad parent node tag %r" % p.tag
175
186
            rev.parent_ids.append(p.get('revision_id'))
176
 
 
 
187
        self._unpack_revision_properties(elt, rev)
177
188
        v = elt.get('timezone')
178
189
        rev.timezone = v and int(v)
179
 
 
180
190
        rev.message = elt.findtext('message') # text of <message>
181
191
        return rev
182
192
 
183
193
 
 
194
    def _unpack_revision_properties(self, elt, rev):
 
195
        """Unpack properties onto a revision."""
 
196
        props_elt = elt.find('properties')
 
197
        assert len(rev.properties) == 0
 
198
        if not props_elt:
 
199
            return
 
200
        for prop_elt in props_elt:
 
201
            assert prop_elt.tag == 'property', \
 
202
                "bad tag under properties list: %r" % p.tag
 
203
            name = prop_elt.get('name')
 
204
            value = prop_elt.text
 
205
            assert name not in rev.properties, \
 
206
                "repeated property %r" % p.name
 
207
            rev.properties[name] = value
 
208
 
 
209
 
184
210
serializer_v5 = Serializer_v5()