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