66
77"""
88
9- import warnings
9+ from astropy .table import Table
10+
1011from ..query import BaseQuery
1112from ..utils import commons , async_to_sync
13+ from ..utils .class_or_instance import class_or_instance
14+
15+ from .utils import _get_data_from_xml
1216from . import conf
13- from astropy .table import Table , Column
1417
15- from ..utils .class_or_instance import class_or_instance
16- from ..utils import commons , async_to_sync
17- from .utils import *
1818
1919from xml .dom import minidom
2020
2121__all__ = ['ADS' , 'ADSClass' ]
2222
23+
2324@async_to_sync
2425class ADSClass (BaseQuery ):
2526
2627 SERVER = conf .server
2728 QUERY_ADVANCED_PATH = conf .advanced_path
2829 QUERY_SIMPLE_PATH = conf .simple_path
2930 TIMEOUT = conf .timeout
30-
31+
3132 QUERY_SIMPLE_URL = SERVER + QUERY_SIMPLE_PATH
3233 QUERY_ADVANCED_URL = SERVER + QUERY_ADVANCED_PATH
3334
3435 def __init__ (self , * args ):
3536 """ set some parameters """
3637 pass
37-
38+
3839 @class_or_instance
3940 def query_simple (self , query_string , get_query_payload = False , get_raw_response = False ):
4041 self .query_string = query_string
4142 request_payload = self ._args_to_payload (query_string )
42-
43+
4344 response = commons .send_request (self .QUERY_SIMPLE_URL , request_payload , self .TIMEOUT )
4445
4546 # primarily for debug purposes, but also useful if you want to send
@@ -50,17 +51,17 @@ def query_simple(self, query_string, get_query_payload=False, get_raw_response=F
5051 return response
5152 # parse the XML response into AstroPy Table
5253 resulttable = self ._parse_response (response .encode (results .encoding ).decode ('utf-8' ))
53-
54+
5455 return resulttable
55-
56+
5657 def _parse_response (self , response ):
5758 xmlrepr = minidom .parseString (response .text )
5859 # Check if there are any results!
59-
60+
6061 # get the list of hits
6162 hitlist = xmlrepr .childNodes [0 ].childNodes
6263 hitlist = hitlist [1 ::2 ] # every second hit is a "line break"
63-
64+
6465 # Grab the various fields
6566 titles = _get_data_from_xml (hitlist , 'title' )
6667 bibcode = _get_data_from_xml (hitlist , 'bibcode' )
@@ -84,13 +85,13 @@ def _parse_response(self, response):
8485 t ['page' ] = page
8586 t ['score' ] = score
8687 t ['citations' ] = citations
87- t ['abstract' ] = abstract
88+ t ['abstract' ] = abstract
8889 t ['doi' ] = doi
89- t ['eprintid' ] = eprintid
90+ t ['eprintid' ] = eprintid
9091 t ['authors' ] = authors
91-
92+
9293 return t
93-
94+
9495 def _args_to_payload (self , query_string ):
9596 # convert arguments to a valid requests payload
9697 # i.e. a dictionary
0 commit comments