File tree Expand file tree Collapse file tree
mathics/builtin/fileformats Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2020import re
2121import sys
2222
23+
2324try :
2425 import lxml .html as lhtml
26+
27+ lhtml_available = True
2528except 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
3034def node_to_xml_element (node , strip_whitespace = True ):
@@ -89,14 +93,19 @@ class ParseError(Exception):
8993if "__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
96102else :
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
102111def parse_html_file (filename ):
You can’t perform that action at this time.
0 commit comments