25
25
from bzrlib.trace import mutter, warning
28
from cElementTree import (ElementTree, SubElement, Element,
29
XMLTreeBuilder, fromstring, tostring)
29
# it's in this package in python2.5
30
from xml.etree.cElementTree import (ElementTree, SubElement, Element,
31
XMLTreeBuilder, fromstring, tostring)
32
import xml.etree as elementtree
34
from cElementTree import (ElementTree, SubElement, Element,
35
XMLTreeBuilder, fromstring, tostring)
37
ParseError = SyntaxError
31
38
except ImportError:
32
39
mutter('WARNING: using slower ElementTree; consider installing cElementTree'
33
40
" and make sure it's on your PYTHONPATH")
41
# this copy is shipped with bzr
34
42
from util.elementtree.ElementTree import (ElementTree, SubElement,
35
43
Element, XMLTreeBuilder,
36
44
fromstring, tostring)
37
45
import util.elementtree as elementtree
46
from xml.parsers.expat import ExpatError as ParseError
39
from bzrlib.errors import BzrError
48
from bzrlib import errors
42
51
class Serializer(object):
50
59
return tostring(self._pack_inventory(inv)) + '\n'
52
61
def read_inventory_from_string(self, xml_string):
53
return self._unpack_inventory(fromstring(xml_string))
63
return self._unpack_inventory(fromstring(xml_string))
65
raise errors.UnexpectedInventoryFormat(e)
55
67
def read_inventory(self, f):
56
return self._unpack_inventory(self._read_element(f))
69
return self._unpack_inventory(self._read_element(f))
71
raise errors.UnexpectedInventoryFormat(e)
58
73
def write_revision(self, rev, f):
59
74
self._write_element(self._pack_revision(rev), f)