Commits

Bastian Blank  committed d7e2354

HTML Support - Change imports to internal names

  • Participants
  • Parent commits 47b1c1a

Comments (0)

Files changed (2)

File emeraldtree/html.py

 # The ElementTree toolkit is
 #
 # Copyright (c) 1999-2007 by Fredrik Lundh
-#               2008-2009 Bastian Blank <bblank@thinkmo.de>
+#               2008-2010 Bastian Blank <bblank@thinkmo.de>
 #
 # By obtaining, using, and/or copying this software and/or its
 # associated documentation, you agree that you have read, understood,
 import mimetools, StringIO
 from HTMLParser import HTMLParser as HTMLParserBase
 
-import ElementTree
+from . import tree
 
 
 ##
     namespace = "http://www.w3.org/1999/xhtml"
 
     def __init__(self, encoding=None, builder=None):
+        HTMLParserBase.__init__(self)
         self.__stack = []
-        if builder is None:
-            builder = ElementTree.TreeBuilder()
-        self.__builder = builder
+        self.__builder = builder or tree.TreeBuilder()
         self.encoding = encoding or "iso-8859-1"
-        HTMLParserBase.__init__(self)
 
     ##
     # Flushes parser buffers, and return the root element.
     # (Internal) Handles start tags.
 
     def handle_starttag(self, tag, attrs):
-        tag = ElementTree.QName(tag.lower(), self.namespace)
+        tag = tree.QName(tag.lower(), self.namespace)
         if tag.name == "meta":
             # look for encoding directives
             http_equiv = content = None
                 # Handle short attributes
                 if value is None:
                     value = key
-                key = ElementTree.QName(key.lower(), self.namespace)
+                key = tree.QName(key.lower(), self.namespace)
                 attrib[key] = value
         self.__builder.start(tag, attrib)
         if tag.name in self.IGNOREEND:
     # (Internal) Handles end tags.
 
     def handle_endtag(self, tag):
-        if not isinstance(tag, ElementTree.QName):
-            tag = ElementTree.QName(tag.lower(), self.namespace)
+        if not isinstance(tag, tree.QName):
+            tag = tree.QName(tag.lower(), self.namespace)
         if tag.name in self.IGNOREEND:
             return
         lasttag = self.__stack.pop()

File emeraldtree/tests/test_html.py

 import py.test
-from emeraldtree.ElementTree import *
-from emeraldtree.html import *
+
+from .. import html, tree
 
 def serialize(elem, **options):
     from cStringIO import StringIO
     return file.getvalue()
 
 def test_HTMLParser_simple1():
-    elem = HTML('<a></a>')
+    elem = html.HTML('<a></a>')
     assert elem.tag.name == 'a'
     assert len(elem) == 0
 
 def test_HTMLParser_simple2():
-    elem = HTML('<a><b /></a>')
+    elem = html.HTML('<a><b /></a>')
     assert elem.tag.name == 'a'
     assert len(elem) == 1
     assert elem[0].tag.name == 'b'
     assert len(elem[0]) == 0
 
 def test_HTMLParser_text1():
-    elem = HTML('<a>b</a>')
+    elem = html.HTML('<a>b</a>')
     assert elem.tag.name == 'a'
-    assert isinstance(elem, Element)
+    assert isinstance(elem, tree.Element)
     assert len(elem) == 1
     assert elem[0] == 'b'
     assert isinstance(elem[0], unicode)
 
 def test_HTMLParser_text2():
-    elem = HTML('<a>b<c>d</c>d</a>')
+    elem = html.HTML('<a>b<c>d</c>d</a>')
     assert elem.tag.name == 'a'
     assert len(elem) == 3
     assert elem[0] == 'b'
     assert elem[2] == 'd'
 
 def test_HTMLParser_ignoreend():
-    elem = HTML('<br>')
+    elem = html.HTML('<br>')
     assert elem.tag.name == 'br'
     assert len(elem) == 0
 
-    elem = HTML('<br></br>')
+    elem = html.HTML('<br></br>')
     assert elem.tag.name == 'br'
     assert len(elem) == 0