Unverified Commit 440c4e9c authored by Ben Busby's avatar Ben Busby
Browse files

Remove lxml dependency

The lxml dependency in the project was fairly unnecessary, and made the
initial build time for the project considerably slower. This replaces
all instances of lxml with either the default html parser (for bs4
constructors) or the built in xml.etree package (for search suggestion
parsing).
parent 2bbc6499
......@@ -111,8 +111,8 @@ class Filter:
return
# Wrap section in details element to allow collapse/expand
details = BeautifulSoup(features='lxml').new_tag('details')
summary = BeautifulSoup(features='lxml').new_tag('summary')
details = BeautifulSoup(features='html.parser').new_tag('details')
summary = BeautifulSoup(features='html.parser').new_tag('summary')
summary.string = question_divs[0].find('h2').text
question_divs[0].find('h2').decompose()
details.append(summary)
......
from app.models.config import Config
from lxml import etree
import xml.etree.ElementTree as ET
import random
import requests
from requests import Response, ConnectionError
......@@ -185,11 +185,12 @@ class Request:
response = self.send(base_url=AUTOCOMPLETE_URL,
query=urlparse.urlencode(ac_query)).text
if response:
dom = etree.fromstring(response)
return dom.xpath('//suggestion/@data')
if not response:
return []
return []
root = ET.fromstring(response)
return [_.attrib['data'] for _ in
root.findall('.//suggestion/[@data]')]
def send(self, base_url=SEARCH_URL, query='', attempt=0) -> Response:
"""Sends an outbound request to a URL. Optionally sends the request
......
......@@ -75,7 +75,7 @@ def filter_link_args(query_link):
def gen_nojs(sibling):
nojs_link = BeautifulSoup(features='lxml').new_tag('a')
nojs_link = BeautifulSoup(features='html.parser').new_tag('a')
nojs_link['href'] = '/window?location=' + sibling['href']
nojs_link['style'] = 'display:block;width:100%;'
nojs_link.string = 'NoJS Link: ' + nojs_link['href']
......
......@@ -12,7 +12,6 @@ Flask-Session==0.3.2
idna==2.9
itsdangerous==1.1.0
Jinja2==2.10.3
lxml==4.5.1
MarkupSafe==1.1.1
more-itertools==8.3.0
packaging==20.4
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment