~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/xml_serializer.py

  • Committer: Jelmer Vernooij
  • Date: 2012-01-06 22:44:57 UTC
  • mfrom: (6436 +trunk)
  • mto: (6437.3.11 2.5)
  • mto: This revision was merged to the branch mainline in revision 6444.
  • Revision ID: jelmer@samba.org-20120106224457-re0pcy0fz31xob77
Merge bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
"""XML externalization support."""
18
18
 
 
19
from __future__ import absolute_import
 
20
 
19
21
# "XML is like violence: if it doesn't solve your problem, you aren't
20
22
# using enough of it." -- various
21
23
 
24
26
 
25
27
import re
26
28
 
27
 
from bzrlib.serializer import Serializer
28
 
from bzrlib.trace import mutter
29
 
 
30
29
try:
 
30
    import xml.etree.cElementTree as elementtree
 
31
    ParseError = getattr(elementtree, "ParseError", SyntaxError)
 
32
except ImportError:
 
33
    # Fall back to pure python implementation if C extention is unavailable
 
34
    import xml.etree.ElementTree as elementtree
31
35
    try:
32
 
        # it's in this package in python2.5
33
 
        from xml.etree.cElementTree import (ElementTree, SubElement, Element,
34
 
            XMLTreeBuilder, fromstring, tostring)
35
 
        import xml.etree as elementtree
36
 
        # Also import ElementTree module so monkey-patching below always works
37
 
        import xml.etree.ElementTree
 
36
        from xml.etree.ElementTree import ParseError
38
37
    except ImportError:
39
 
        from cElementTree import (ElementTree, SubElement, Element,
40
 
                                  XMLTreeBuilder, fromstring, tostring)
41
 
        import elementtree.ElementTree
42
 
    ParseError = SyntaxError
43
 
except ImportError:
44
 
    mutter('WARNING: using slower ElementTree; consider installing cElementTree'
45
 
           " and make sure it's on your PYTHONPATH")
46
 
    # this copy is shipped with bzr
47
 
    from util.elementtree.ElementTree import (ElementTree, SubElement,
48
 
                                              Element, XMLTreeBuilder,
49
 
                                              fromstring, tostring)
50
 
    import util.elementtree as elementtree
51
 
    from xml.parsers.expat import ExpatError as ParseError
 
38
        from xml.parsers.expat import ExpatError as ParseError
 
39
 
 
40
(ElementTree, SubElement, Element, XMLTreeBuilder, fromstring, tostring) = (
 
41
    elementtree.ElementTree, elementtree.SubElement, elementtree.Element,
 
42
    elementtree.XMLTreeBuilder, elementtree.fromstring, elementtree.tostring)
 
43
 
52
44
 
53
45
from bzrlib import (
54
46
    cache_utf8,
 
47
    errors,
55
48
    inventory,
56
49
    lazy_regex,
57
 
    errors,
 
50
    serializer,
58
51
    )
59
52
 
60
53
 
61
 
class XMLSerializer(Serializer):
 
54
class XMLSerializer(serializer.Serializer):
62
55
    """Abstract XML object serialize/deserialize"""
63
56
 
64
57
    squashes_xml_invalid_characters = True