~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/xml5.py

  • Committer: Kent Gibson
  • Date: 2007-03-07 14:49:00 UTC
  • mfrom: (2324 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2350.
  • Revision ID: warthog618@gmail.com-20070307144900-6bt7twg47zul3w0w
merged bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006 Canonical Ltd
 
1
# Copyright (C) 2005, 2006, 2007 Canonical Ltd
2
2
#
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
19
19
 
20
20
from bzrlib import (
21
21
    cache_utf8,
 
22
    errors,
22
23
    inventory,
23
24
    )
24
25
from bzrlib.xml_serializer import SubElement, Element, Serializer
148
149
    # This format supports the altered-by hack that reads file ids directly out
149
150
    # of the versionedfile, without doing XML parsing.
150
151
 
 
152
    supported_kinds = set(['file', 'directory', 'symlink'])
 
153
 
151
154
    def write_inventory_to_string(self, inv):
152
155
        """Just call write_inventory with a StringIO and return the value"""
153
156
        sio = cStringIO.StringIO()
190
193
    def _append_entry(self, append, ie):
191
194
        """Convert InventoryEntry to XML element and append to output."""
192
195
        # TODO: should just be a plain assertion
193
 
        assert InventoryEntry.versionable_kind(ie.kind), \
194
 
            'unsupported entry kind %s' % ie.kind
 
196
        if ie.kind not in self.supported_kinds:
 
197
            raise errors.UnsupportedInventoryKind(ie.kind)
195
198
 
196
199
        append("<")
197
200
        append(ie.kind)
217
220
            append('"')
218
221
        if ie.text_size is not None:
219
222
            append(' text_size="%d"' % ie.text_size)
 
223
        if getattr(ie, 'reference_revision', None) is not None:
 
224
            append(' reference_revision="')
 
225
            append(_encode_and_escape(ie.reference_revision))
220
226
        append(" />\n")
221
227
        return
222
228
 
324
330
                                         parent_id)
325
331
            ie.symlink_target = elt.get('symlink_target')
326
332
        else:
327
 
            raise BzrError("unknown kind %r" % kind)
 
333
            raise errors.UnsupportedInventoryKind(kind)
328
334
        revision = elt.get('revision')
329
335
        if revision is not None:
330
336
            revision = get_cached(revision)