Skip to content

Commit fe89264

Browse files
Jorge Fernandez HernandezJorge Fernandez Hernandez
authored andcommitted
GAIAPCR-1341 update the implementation to read the cookies by the new tap mechanism
1 parent ae9dd53 commit fe89264

File tree

3 files changed

+60
-16
lines changed

3 files changed

+60
-16
lines changed

astroquery/utils/tap/conn/tapconn.py

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@
1717

1818
import http.client as httplib
1919
import mimetypes
20+
import os
2021
import platform
22+
import requests
2123
import time
22-
import os
23-
from astroquery.utils.tap.xmlparser import utils
24-
from astroquery.utils.tap import taputils
25-
from astroquery import version
2624

27-
import requests
25+
from astroquery import version
26+
from astroquery.utils.tap import taputils
27+
from astroquery.utils.tap.xmlparser import utils
2828

2929
__all__ = ['TapConn']
3030

@@ -485,6 +485,22 @@ def find_header(self, headers, key):
485485
"""
486486
return taputils.taputil_find_header(headers, key)
487487

488+
def find_all_headers(self, headers, key):
489+
"""Searches for the specified keyword
490+
491+
Parameters
492+
----------
493+
headers : HTTP(s) headers object, mandatory
494+
HTTP(s) response headers
495+
key : str, mandatory
496+
header key to be searched for
497+
498+
Returns
499+
-------
500+
A list of requested header values or an emtpy list if no header is found
501+
"""
502+
return taputils.taputil_find_all_headers(headers, key)
503+
488504
def dump_to_file(self, output, response):
489505
"""Writes the connection response into the specified output
490506
@@ -585,7 +601,7 @@ def get_file_from_header(self, headers):
585601
if content_disposition is not None:
586602
p = content_disposition.find('filename="')
587603
if p >= 0:
588-
filename = os.path.basename(content_disposition[p+10:len(content_disposition)-1])
604+
filename = os.path.basename(content_disposition[p + 10:len(content_disposition) - 1])
589605
content_encoding = self.find_header(headers, 'Content-Encoding')
590606

591607
if content_encoding is not None:
@@ -722,7 +738,7 @@ def encode_multipart(self, fields, files):
722738

723739
def __str__(self):
724740
return f"\tHost: {self.__connHost}\n\tUse HTTPS: {self.__isHttps}" \
725-
f"\n\tPort: {self.__connPort}\n\tSSL Port: {self.__connPortSsl}"
741+
f"\n\tPort: {self.__connPort}\n\tSSL Port: {self.__connPortSsl}"
726742

727743

728744
class ConnectionHandler:

astroquery/utils/tap/core.py

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,10 @@
1515
"""
1616
import getpass
1717
import os
18-
import tempfile
19-
from urllib.parse import urlencode
20-
2118
import requests
19+
import tempfile
2220
from astropy.table.table import Table
21+
from urllib.parse import urlencode
2322

2423
from astroquery import log
2524
from astroquery.utils.tap import taputils
@@ -661,16 +660,23 @@ def __extract_sync_subcontext(self, location):
661660
return location[pos:]
662661

663662
def __findCookieInHeader(self, headers, *, verbose=False):
664-
cookies = self.__connHandler.find_header(headers, 'Set-Cookie')
663+
cookies = self.__connHandler.find_all_headers(headers, 'Set-Cookie')
665664
if verbose:
666665
print(cookies)
667-
if cookies is None:
666+
if not cookies:
668667
return None
669668
else:
670-
items = cookies.split(';')
671-
for i in items:
672-
if i.startswith("JSESSIONID="):
673-
return i
669+
for cook in cookies:
670+
items = cook.split(';')
671+
for item in items:
672+
if item.startswith("SESSION="):
673+
return item
674+
675+
for cook in cookies:
676+
items = cook.split(';')
677+
for item in items:
678+
if item.startswith("JSESSIONID="):
679+
return item
674680
return None
675681

676682
def __parseUrl(self, url, *, verbose=False):

astroquery/utils/tap/taputils.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,28 @@ def taputil_find_header(headers, key):
4949
return None
5050

5151

52+
def taputil_find_all_headers(headers, key):
53+
"""Searches for the specified keyword
54+
55+
Parameters
56+
----------
57+
headers : HTTP(s) headers object, mandatory
58+
HTTP(s) response headers
59+
key : str, mandatory
60+
header key to be searched for
61+
62+
Returns
63+
-------
64+
A list of requested header values or an empty list if not header is found
65+
"""
66+
67+
result = list()
68+
for entry in headers:
69+
if key.lower() == entry[0].lower():
70+
result.append(entry[1])
71+
return result
72+
73+
5274
def taputil_create_sorted_dict_key(dictionaryObject):
5375
"""Searches for the specified keyword
5476

0 commit comments

Comments
 (0)