~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/xml5.py

  • Committer: Robert Collins
  • Date: 2005-10-06 22:15:52 UTC
  • mfrom: (1185.13.2)
  • mto: This revision was merged to the branch mainline in revision 1420.
  • Revision ID: robertc@robertcollins.net-20051006221552-9b15c96fa504e0ad
mergeĀ fromĀ upstream

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#! /usr/bin/env python
 
2
 
1
3
# This program is free software; you can redistribute it and/or modify
2
4
# it under the terms of the GNU General Public License as published by
3
5
# the Free Software Foundation; either version 2 of the License, or
20
22
from bzrlib.errors import BzrError
21
23
 
22
24
 
 
25
 
 
26
 
 
27
 
23
28
class Serializer_v5(Serializer):
24
29
    """Version 5 serializer
25
30
 
94
99
                p = SubElement(pelts, 'revision_ref')
95
100
                p.tail = '\n'
96
101
                p.set('revision_id', parent_id)
97
 
        if rev.properties:
98
 
            self._pack_revision_properties(rev, root)
99
102
        return root
100
 
 
101
 
 
102
 
    def _pack_revision_properties(self, rev, under_element):
103
 
        top_elt = SubElement(under_element, 'properties')
104
 
        for prop_name, prop_value in sorted(rev.properties.items()):
105
 
            assert isinstance(prop_name, basestring) 
106
 
            assert isinstance(prop_value, basestring) 
107
 
            prop_elt = SubElement(top_elt, 'property')
108
 
            prop_elt.set('name', prop_name)
109
 
            prop_elt.text = prop_value
110
 
            prop_elt.tail = '\n'
111
 
        top_elt.tail = '\n'
112
 
 
 
103
    
113
104
 
114
105
    def _unpack_inventory(self, elt):
115
106
        """Construct from XML Element
182
173
            assert p.tag == 'revision_ref', \
183
174
                   "bad parent node tag %r" % p.tag
184
175
            rev.parent_ids.append(p.get('revision_id'))
185
 
        self._unpack_revision_properties(elt, rev)
 
176
 
186
177
        v = elt.get('timezone')
187
178
        rev.timezone = v and int(v)
 
179
 
188
180
        rev.message = elt.findtext('message') # text of <message>
189
181
        return rev
190
182
 
191
183
 
192
 
    def _unpack_revision_properties(self, elt, rev):
193
 
        """Unpack properties onto a revision."""
194
 
        props_elt = elt.find('properties')
195
 
        assert len(rev.properties) == 0
196
 
        if not props_elt:
197
 
            return
198
 
        for prop_elt in props_elt:
199
 
            assert prop_elt.tag == 'property', \
200
 
                "bad tag under properties list: %r" % p.tag
201
 
            name = prop_elt.get('name')
202
 
            value = prop_elt.text
203
 
            assert name not in rev.properties, \
204
 
                "repeated property %r" % p.name
205
 
            rev.properties[name] = value
206
 
 
207
 
 
208
184
serializer_v5 = Serializer_v5()