~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/xml_serializer.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2006-07-06 03:15:29 UTC
  • mfrom: (1711.2.78 jam-integration)
  • Revision ID: pqm@pqm.ubuntu.com-20060706031529-e189d8c3f42076be
(jam) allow plugins to include benchmarks

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006 Canonical Ltd
2
 
#
 
1
# -*- coding: UTF-8 -*-
 
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
5
5
# the Free Software Foundation; either version 2 of the License, or
6
6
# (at your option) any later version.
7
 
#
 
7
 
8
8
# This program is distributed in the hope that it will be useful,
9
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
11
# GNU General Public License for more details.
12
 
#
 
12
 
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
25
25
from bzrlib.trace import mutter, warning
26
26
 
27
27
try:
28
 
    try:
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
33
 
    except ImportError:
34
 
        from cElementTree import (ElementTree, SubElement, Element,
35
 
                                  XMLTreeBuilder, fromstring, tostring)
36
 
        import elementtree
37
 
    ParseError = SyntaxError
 
28
    from cElementTree import (ElementTree, SubElement, Element,
 
29
                              XMLTreeBuilder, fromstring, tostring)
 
30
    import elementtree
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
47
38
 
48
 
from bzrlib import errors
 
39
from bzrlib.errors import BzrError
49
40
 
50
41
 
51
42
class Serializer(object):
59
50
        return tostring(self._pack_inventory(inv)) + '\n'
60
51
 
61
52
    def read_inventory_from_string(self, xml_string):
62
 
        try:
63
 
            return self._unpack_inventory(fromstring(xml_string))
64
 
        except ParseError, e:
65
 
            raise errors.UnexpectedInventoryFormat(e)
 
53
        return self._unpack_inventory(fromstring(xml_string))
66
54
 
67
55
    def read_inventory(self, f):
68
 
        try:
69
 
            return self._unpack_inventory(self._read_element(f))
70
 
        except ParseError, e:
71
 
            raise errors.UnexpectedInventoryFormat(e)
 
56
        return self._unpack_inventory(self._read_element(f))
72
57
 
73
58
    def write_revision(self, rev, f):
74
59
        self._write_element(self._pack_revision(rev), f)