2929
3030Github: https://github.com/willforde/python-htmlement
3131Documentation: https://python-htmlement.readthedocs.io/en/stable/?badge=stable
32- Testing: https://www.travis-ci. com/willforde/python-htmlement
33- Coverage: https://coveralls .io/github /willforde/python-htmlement?branch=master
32+ Testing: https://github. com/willforde/python-htmlement/actions
33+ Coverage: https://codecov .io/gh /willforde/python-htmlement
3434Maintainability: https://codeclimate.com/github/willforde/python-htmlement/maintainability
3535"""
3636
37-
38- # Python 2 compatibility
39- from __future__ import unicode_literals
40-
41- # Standard library imports
42- from codecs import open as _open
37+ # Standard Lib
38+ import xml .etree .ElementTree as Etree
4339import warnings
44- import sys
4540import re
4641
47- # Check python version to set the object that can detect non unicode strings
48- if sys .version_info >= (3 , 0 ):
49- import xml .etree .ElementTree as Etree
50- # noinspection PyUnresolvedReferences,PyCompatibility
51- from html .parser import HTMLParser
52- # noinspection PyUnresolvedReferences, PyCompatibility
53- from html .entities import name2codepoint
54- # Python2 compatibility
55- _chr = chr
56- else :
57- # noinspection PyUnresolvedReferences,PyCompatibility
58- from HTMLParser import HTMLParser
59- # noinspection PyUnresolvedReferences, PyCompatibility
60- from htmlentitydefs import name2codepoint
61- # noinspection PyUnresolvedReferences
62- _chr = unichr
63-
64- try :
65- # This attemps to import the C version of ElementTree
66- import xml .etree .cElementTree as Etree
67- # This will fail if the implementation is broken
68- Etree .Comment ("Test for broken cElementTree" )
69- except (ImportError , TypeError ):
70- import xml .etree .ElementTree as Etree
42+ # HTML Parser
43+ from html .entities import name2codepoint
44+ from html .parser import HTMLParser
7145
7246__all__ = ["HTMLement" , "fromstring" , "fromstringlist" , "parse" ]
73- __version__ = "1 .0.1 "
47+ __version__ = "2 .0.0 "
7448
7549# Add missing codepoints
50+ # TODO: This may no longer be required
7651name2codepoint ["apos" ] = 0x0027
7752
7853
@@ -152,7 +127,7 @@ def parse(source, tag="", attrs=None, encoding=None):
152127 """
153128 # Assume that source is a file pointer if no read methods is found
154129 if not hasattr (source , "read" ):
155- source = _open (source , "rb" , encoding = encoding )
130+ source = open (source , "rb" , encoding = encoding )
156131 close_source = True
157132 else :
158133 close_source = False
@@ -385,7 +360,7 @@ def handle_data(self, data):
385360 def handle_entityref (self , name ):
386361 if self .enabled :
387362 try :
388- name = _chr (name2codepoint [name ])
363+ name = chr (name2codepoint [name ])
389364 except KeyError :
390365 pass
391366 self ._data .append (name )
@@ -394,9 +369,9 @@ def handle_charref(self, name):
394369 if self .enabled :
395370 try :
396371 if name [0 ].lower () == "x" :
397- name = _chr (int (name [1 :], 16 ))
372+ name = chr (int (name [1 :], 16 ))
398373 else :
399- name = _chr (int (name ))
374+ name = chr (int (name ))
400375 except ValueError :
401376 pass
402377 self ._data .append (name )
0 commit comments