~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/xml_serializer.py

  • Committer: wang
  • Date: 2006-10-29 13:41:32 UTC
  • mto: (2104.4.1 wang_65714)
  • mto: This revision was merged to the branch mainline in revision 2109.
  • Revision ID: wang@ubuntu-20061029134132-3d7f4216f20c4aef
Replace python's difflib by patiencediff because the worst case 
performance is cubic for difflib and people commiting large data 
files are often hurt by this. The worst case performance of patience is 
quadratic. Fix bug 65714.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# -*- coding: UTF-8 -*-
 
1
# Copyright (C) 2005, 2006 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
25
25
from bzrlib.trace import mutter, warning
26
26
 
27
27
try:
28
 
    from cElementTree import (ElementTree, SubElement, Element,
29
 
                              XMLTreeBuilder, fromstring, tostring)
30
 
    import elementtree
 
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
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
38
47
 
39
 
from bzrlib.errors import BzrError
 
48
from bzrlib import errors
40
49
 
41
50
 
42
51
class Serializer(object):
50
59
        return tostring(self._pack_inventory(inv)) + '\n'
51
60
 
52
61
    def read_inventory_from_string(self, xml_string):
53
 
        return self._unpack_inventory(fromstring(xml_string))
 
62
        try:
 
63
            return self._unpack_inventory(fromstring(xml_string))
 
64
        except ParseError, e:
 
65
            raise errors.UnexpectedInventoryFormat(e)
54
66
 
55
67
    def read_inventory(self, f):
56
 
        return self._unpack_inventory(self._read_element(f))
 
68
        try:
 
69
            return self._unpack_inventory(self._read_element(f))
 
70
        except ParseError, e:
 
71
            raise errors.UnexpectedInventoryFormat(e)
57
72
 
58
73
    def write_revision(self, rev, f):
59
74
        self._write_element(self._pack_revision(rev), f)