ElementTree vs cElementTree exception confusion
Marien Zwart
marienz at gentoo.org
Fri Sep 22 01:58:22 BST 2006
There are some selftest tests that fail when using the bundled
ElementTree instead of cElementTree. This happens because cElementTree
raises SyntaxError on invalid xml while ElementTree raises ExpatError.
The attached bundle fixes the test.
There are two more uses of SyntaxError in the tree that the tests do
not catch, one in store/revision/knit.py and one in
store/revision/text.py. Would it be ok for those two files to import
xml_serializer to get the right exception to catch, or should
xml_serializer be modified to always raise some exception from
bzrlib.errors so that knit.py and text.py can catch that exception
instead?
--
Marien.
-------------- next part --------------
# Bazaar revision bundle v0.8
#
# message:
# Handle the different exception (non-c)ElementTree raises.
# committer: Marien Zwart <marienz at gentoo.org>
# date: Fri 2006-09-22 02:51:36.890000105 +0200
=== modified file bzrlib/xml_serializer.py
--- bzrlib/xml_serializer.py
+++ bzrlib/xml_serializer.py
@@ -28,6 +28,7 @@
from cElementTree import (ElementTree, SubElement, Element,
XMLTreeBuilder, fromstring, tostring)
import elementtree
+ ParseError = SyntaxError
except ImportError:
mutter('WARNING: using slower ElementTree; consider installing cElementTree'
" and make sure it's on your PYTHONPATH")
@@ -35,6 +36,7 @@
Element, XMLTreeBuilder,
fromstring, tostring)
import util.elementtree as elementtree
+ from xml.parsers.expat import ExpatError as ParseError
from bzrlib import errors
@@ -52,13 +54,13 @@
def read_inventory_from_string(self, xml_string):
try:
return self._unpack_inventory(fromstring(xml_string))
- except SyntaxError, e:
+ except ParseError, e:
raise errors.UnexpectedInventoryFormat(e)
def read_inventory(self, f):
try:
return self._unpack_inventory(self._read_element(f))
- except SyntaxError, e:
+ except ParseError, e:
raise errors.UnexpectedInventoryFormat(e)
def write_revision(self, rev, f):
# revision id: marienz at gentoo.org-20060922005136-6b5e0b856a4baff3
# sha1: 5614772405f7889687846044a76009d74bcfed37
# inventory sha1: 47d0ae575e63ebfe88af104bff9e22b9b6718eeb
# parent ids:
# pqm at pqm.ubuntu.com-20060922002407-21dde3dd8419b20b
# base id: pqm at pqm.ubuntu.com-20060922002407-21dde3dd8419b20b
# properties:
# branch-nick: bzr.dev
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : https://lists.ubuntu.com/archives/bazaar/attachments/20060922/ac9a28b8/attachment.pgp
More information about the bazaar
mailing list