From 8fb1252aec84bf0de77de4df442f260c5a4d2f98 Mon Sep 17 00:00:00 2001 From: Waylan Limberg Date: Sun, 31 Oct 2010 18:55:30 -0400 Subject: Fixed previous two commits. cElementTree cannot use ElementTree nodes in the tree, but it still uses ElementTree Comment assinged to a node's tag to test for Comment nodes. Also no longer considering Commet nodes to be block level. --- markdown/etree_loader.py | 4 ++-- markdown/html4.py | 5 ++++- markdown/util.py | 5 +---- tests/test_apis.py | 8 ++++++-- 4 files changed, 13 insertions(+), 9 deletions(-) diff --git a/markdown/etree_loader.py b/markdown/etree_loader.py index 578fa28..64966b5 100644 --- a/markdown/etree_loader.py +++ b/markdown/etree_loader.py @@ -26,8 +26,8 @@ def importETree(): if etree_in_c.VERSION < "1.0": message(CRITICAL, "cElementTree version 1.0 or higher is required.") sys.exit(1) - # Third party serializers (including ours) require non-c Comment - etree_in_c.Comment = Comment + # Third party serializers (including ours) test with non-c Comment + etree_in_c.test_comment = Comment return etree_in_c elif etree.VERSION < "1.1": message(CRITICAL, "ElementTree version 1.1 or higher is required") diff --git a/markdown/html4.py b/markdown/html4.py index 63bcc97..611e628 100644 --- a/markdown/html4.py +++ b/markdown/html4.py @@ -40,7 +40,10 @@ import util ElementTree = util.etree.ElementTree QName = util.etree.QName -Comment = util.etree.Comment +if hasattr(util.etree, 'test_comment'): + Comment = util.etree.test_comment +else: + Comment = util.etree.Comment PI = util.etree.PI ProcessingInstruction = util.etree.ProcessingInstruction diff --git a/markdown/util.py b/markdown/util.py index 9ae523f..8e950b9 100644 --- a/markdown/util.py +++ b/markdown/util.py @@ -53,10 +53,7 @@ def isBlockLevel(tag): """Check if the tag is a block level HTML tag.""" if isinstance(tag, basestring): return BLOCK_LEVEL_ELEMENTS.match(tag) - # Some ElementTree tags are not strings, so return True for Comments - # and False for anything else. - if tag is etree.Comment: - return True + # Some ElementTree tags are not strings, so return False. return False """ diff --git a/tests/test_apis.py b/tests/test_apis.py index 114b09d..0de4727 100644 --- a/tests/test_apis.py +++ b/tests/test_apis.py @@ -301,14 +301,18 @@ class testETreeComments(unittest.TestCase): def setUp(self): # Create comment node self.comment = markdown.util.etree.Comment('foo') + if hasattr(markdown.util.etree, 'test_comment'): + self.test_comment = markdown.util.etree.test_comment + else: + self.test_comment = markdown.util.etree.Comment def testCommentIsComment(self): """ Test that an ElementTree Comment passes the `is Comment` test. """ - self.assert_(self.comment.tag is markdown.util.etree.Comment) + self.assert_(self.comment.tag is markdown.util.etree.test_comment) def testCommentIsBlockLevel(self): """ Test that an ElementTree Comment is recognized as BlockLevel. """ - self.assert_(markdown.util.isBlockLevel(self.comment.tag)) + self.assertFalse(markdown.util.isBlockLevel(self.comment.tag)) def testCommentSerialization(self): """ Test that an ElementTree Comment serializes properly. """ -- cgit v1.2.3