diff options
author | http://j3h.us/ <http://j3h.us/@lillialexis.local> | 2007-10-02 18:01:58 +0000 |
---|---|---|
committer | http://j3h.us/ <http://j3h.us/@lillialexis.local> | 2007-10-02 18:01:58 +0000 |
commit | fdbc6c8bac06a3d0cd9814bf310564c4c675032f (patch) | |
tree | dc26a23469e9a46d8023f49cbfae4c5a4f1bbc25 /openid/yadis | |
parent | 719e63a729003787858a6b86c8f13edd15126f98 (diff) | |
download | openid-fdbc6c8bac06a3d0cd9814bf310564c4c675032f.tar.gz |
[project @ Be smarter about using the ElementTree API]
* Use the XML function instead of directly calling XMLTreeBuilder,
since XMLTreeBuilder is not ported to all implementations of
ElementTree
* Make the detection routine actually attempt to parse a trivial
document to ensure that a parser is present at all
Diffstat (limited to 'openid/yadis')
-rw-r--r-- | openid/yadis/etxrd.py | 17 |
1 files changed, 2 insertions, 15 deletions
diff --git a/openid/yadis/etxrd.py b/openid/yadis/etxrd.py index 398abd3..1242b01 100644 --- a/openid/yadis/etxrd.py +++ b/openid/yadis/etxrd.py @@ -27,15 +27,6 @@ from time import strptime from openid.oidutil import importElementTree ElementTree = importElementTree() -# Use expat if it's present. Otherwise, use xmllib -try: - XMLTreeBuilder = ElementTree.XMLTreeBuilder - - # This will raise an ImportError if an XML parser is not present. - p = XMLTreeBuilder() -except ImportError: - from elementtree.SimpleXMLTreeBuilder import TreeBuilder as XMLTreeBuilder - # the different elementtree modules don't have a common exception # model. We just want to be able to catch the exceptions that signify # malformed XML data and wrap them, so that the other library code @@ -43,13 +34,11 @@ except ImportError: try: # Make the parser raise an exception so we can sniff out the type # of exceptions - p.feed('> purposely malformed XML <') - p.close() + ElementTree.XML('> purposely malformed XML <') except (SystemExit, MemoryError, AssertionError, ImportError): raise except: XMLError = sys.exc_info()[0] - del p from openid.yadis import xri @@ -77,9 +66,7 @@ def parseXRDS(text): not contain an XRDS. """ try: - parser = XMLTreeBuilder() - parser.feed(text) - element = parser.close() + element = ElementTree.XML(text) except XMLError, why: exc = XRDSError('Error parsing document as XML') exc.reason = why |