on master help sign in
minor fixes of arxiv
9c2b7a8Noémi Ványi
searx/engines/arxiv.py+6−5
@@ -2,7 +2,7 @@
2
2
3"""
3"""
4 ArXiV (Scientific preprints)
4 ArXiV (Scientific preprints)
5− @website https://axiv.org
5+ @website https://arxiv.org
6 @provide-api yes (export.arxiv.org/api/query)
6 @provide-api yes (export.arxiv.org/api/query)
7 @using-api yes
7 @using-api yes
8 @results XML-RSS
8 @results XML-RSS
@@ -41,7 +41,8 @@ def request(query, params):
41def response(resp):
41def response(resp):
42 results = []
42 results = []
43
43
44− search_results = html.fromstring(resp.text).xpath('//entry')
44+ dom = html.fromstring(resp.content)
45+ search_results = dom.xpath('//entry')
45
46
46 for entry in search_results:
47 for entry in search_results:
47 title = entry.xpath('.//title')[0].text
48 title = entry.xpath('.//title')[0].text
@@ -49,15 +50,15 @@ def response(resp):
49 url = entry.xpath('.//id')[0].text
50 url = entry.xpath('.//id')[0].text
50
51
51 content_string = '{doi_content}{abstract_content}'
52 content_string = '{doi_content}{abstract_content}'
52−
53+
53 abstract = entry.xpath('.//summary')[0].text
54 abstract = entry.xpath('.//summary')[0].text
54
55
55 # If a doi is available, add it to the snipppet
56 # If a doi is available, add it to the snipppet
56 try:
57 try:
57 doi_content = entry.xpath('.//link[@title="doi"]')[0].text
58 doi_content = entry.xpath('.//link[@title="doi"]')[0].text
58− content = content_string.format(doi_content=doi_content, abstract_content=abstract_content)
59+ content = content_string.format(doi_content=doi_content, abstract_content=abstract)
59 except:
60 except:
60− content = content_string.format(abstract_content=abstract_content)
61+ content = content_string.format(doi_content="", abstract_content=abstract)
61
62
62 if len(content) > 300:
63 if len(content) > 300:
63 content = content[0:300] + "..."
64 content = content[0:300] + "..."
tests/unit/engines/test_arxiv.py+3−3
@@ -21,11 +21,11 @@ class TestBaseEngine(SearxTestCase):
21 self.assertRaises(AttributeError, arxiv.response, '')
21 self.assertRaises(AttributeError, arxiv.response, '')
22 self.assertRaises(AttributeError, arxiv.response, '[]')
22 self.assertRaises(AttributeError, arxiv.response, '[]')
23
23
24− response = mock.Mock(text='''<?xml version="1.0" encoding="UTF-8"?>
24+ response = mock.Mock(content=b'''<?xml version="1.0" encoding="UTF-8"?>
25<feed xmlns="http://www.w3.org/2005/Atom"></feed>''')
25<feed xmlns="http://www.w3.org/2005/Atom"></feed>''')
26 self.assertEqual(arxiv.response(response), [])
26 self.assertEqual(arxiv.response(response), [])
27
27
28− xml_mock = '''<?xml version="1.0" encoding="UTF-8"?>
28+ xml_mock = b'''<?xml version="1.0" encoding="UTF-8"?>
29<feed xmlns="http://www.w3.org/2005/Atom">
29<feed xmlns="http://www.w3.org/2005/Atom">
30 <title type="html">ArXiv Query: search_query=all:test_query&amp;id_list=&amp;start=0&amp;max_results=1</title>
30 <title type="html">ArXiv Query: search_query=all:test_query&amp;id_list=&amp;start=0&amp;max_results=1</title>
31 <id>http://arxiv.org/api/1</id>
31 <id>http://arxiv.org/api/1</id>
@@ -50,7 +50,7 @@ class TestBaseEngine(SearxTestCase):
50</feed>
50</feed>
51'''
51'''
52
52
53− response = mock.Mock(text=xml_mock.encode('utf-8'))
53+ response = mock.Mock(content=xml_mock)
54 results = arxiv.response(response)
54 results = arxiv.response(response)
55 self.assertEqual(type(results), list)
55 self.assertEqual(type(results), list)
56 self.assertEqual(len(results), 1)
56 self.assertEqual(len(results), 1)