Skip to content

Commit f6fd7e6

Browse files
mmaterarocky
authored andcommitted
remove warning lxml and improve the handling of lxml not availability
1 parent 9ecf464 commit f6fd7e6

1 file changed

Lines changed: 15 additions & 6 deletions

File tree

mathics/builtin/fileformats/htmlformat.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,15 @@
2020
import re
2121
import sys
2222

23+
2324
try:
2425
import lxml.html as lhtml
26+
27+
lhtml_available = True
2528
except ImportError:
26-
print("lxml.html is not available...")
27-
pass
29+
from mathics.builtin.fileformats.xmlformat import parse_xml_stream
30+
31+
lhtml_available = False
2832

2933

3034
def node_to_xml_element(node, strip_whitespace=True):
@@ -89,14 +93,19 @@ class ParseError(Exception):
8993
if "__pypy__" in sys.builtin_module_names:
9094

9195
def parse_html_stream(f):
92-
parser = lhtml.HTMLParser(encoding="utf8")
93-
return lhtml.parse(f, parser)
94-
96+
if lhtml_available:
97+
parser = lhtml.HTMLParser(encoding="utf8")
98+
return lhtml.parse(f, parser)
99+
else:
100+
return parse_xml_stream(f)
95101

96102
else:
97103

98104
def parse_html_stream(f):
99-
return lhtml.parse(f)
105+
if lhtml_available:
106+
return lhtml.parse(f)
107+
else:
108+
return parse_xml_stream(f)
100109

101110

102111
def parse_html_file(filename):

0 commit comments

Comments
 (0)