222
class _Serializer_v5(Serializer):
223
"""Version 5 serializer
225
You should use the serialzer_v5 singleton."""
229
def _pack_inventory(self, inv):
230
"""Convert to XML Element"""
231
e = Element('inventory')
233
if inv.root.file_id not in (None, ROOT_ID):
234
e.set('file_id', inv.root.file_id)
235
for path, ie in inv.iter_entries():
236
e.append(self._pack_entry(ie))
240
def _pack_entry(self, ie):
241
"""Convert InventoryEntry to XML element"""
243
e.set('name', ie.name)
244
e.set('file_id', ie.file_id)
245
e.set('kind', ie.kind)
247
if ie.text_size != None:
248
e.set('text_size', '%d' % ie.text_size)
250
for f in ['text_version', 'text_sha1', 'entry_version']:
255
# to be conservative, we don't externalize the root pointers
256
# for now, leaving them as null in the xml form. in a future
257
# version it will be implied by nested elements.
258
if ie.parent_id != ROOT_ID:
259
assert isinstance(ie.parent_id, basestring)
260
e.set('parent_id', ie.parent_id)
267
def _pack_revision(self, rev):
268
"""Revision object -> xml tree"""
269
root = Element('revision',
270
committer = rev.committer,
271
timestamp = '%.9f' % rev.timestamp,
272
revision_id = rev.revision_id,
273
inventory_id = rev.inventory_id,
274
inventory_sha1 = rev.inventory_sha1,
277
root.set('timezone', str(rev.timezone))
280
msg = SubElement(root, 'message')
281
msg.text = rev.message
285
pelts = SubElement(root, 'parents')
286
pelts.tail = pelts.text = '\n'
287
for rr in rev.parents:
288
assert isinstance(rr, RevisionReference)
289
p = SubElement(pelts, 'revision_ref')
291
assert rr.revision_id
292
p.set('revision_id', rr.revision_id)
298
def _unpack_inventory(self, elt):
299
"""Construct from XML Element
301
assert elt.tag == 'inventory'
302
root_id = elt.get('file_id') or ROOT_ID
303
inv = Inventory(root_id)
305
ie = self._unpack_entry(e)
306
if ie.parent_id == ROOT_ID:
307
ie.parent_id = root_id
312
def _unpack_entry(self, elt):
314
assert kind == 'directory' or kind == 'file'
316
parent_id = elt.get('parent_id')
317
if parent_id == None:
320
ie = InventoryEntry(elt.get('file_id'),
324
ie.text_version = elt.get('text_version')
325
ie.entry_version = elt.get('entry_version')
326
ie.text_sha1 = elt.get('text_sha1')
327
v = elt.get('text_size')
328
ie.text_size = v and int(v)
333
def _unpack_revision(self, elt):
334
"""XML Element -> Revision object"""
335
assert elt.tag == 'revision'
337
rev = Revision(committer = elt.get('committer'),
338
timestamp = float(elt.get('timestamp')),
339
revision_id = elt.get('revision_id'),
340
inventory_id = elt.get('inventory_id'),
341
inventory_sha1 = elt.get('inventory_sha1')
344
for p in elt.find('parents'):
345
assert p.tag == 'revision_ref', \
346
"bad parent node tag %r" % p.tag
347
rev_ref = RevisionReference(p.get('revision_id'))
348
rev.parents.append(rev_ref)
350
v = elt.get('timezone')
351
rev.timezone = v and int(v)
353
rev.message = elt.findtext('message') # text of <message>
219
358
"""singleton instance"""
220
359
serializer_v4 = _Serializer_v4()
361
serializer_v5 = _Serializer_v5()