Skip to content

Commit e724f62

Browse files
committed
Refactor: Made kwargs keyword only for astroquery/utils/tap/
1 parent 770949e commit e724f62

File tree

9 files changed

+146
-147
lines changed

9 files changed

+146
-147
lines changed

astroquery/utils/tap/conn/tapconn.py

Lines changed: 34 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import httplib
2424
import mimetypes
2525
import time
26-
2726
from astroquery.utils.tap.xmlparser import utils
2827
from astroquery.utils.tap import taputils
2928
from astroquery import version
@@ -41,7 +40,7 @@ class TapConn:
4140
"""
4241

4342
def __init__(self, ishttps,
44-
host,
43+
host, *,
4544
server_context=None,
4645
port=80,
4746
sslport=443,
@@ -142,7 +141,7 @@ def __get_data_context(self, encodedData=None):
142141
else:
143142
return self.__dataContext
144143

145-
def __get_datalink_context(self, subContext, encodedData=None):
144+
def __get_datalink_context(self, subContext, *, encodedData=None):
146145
if self.__datalinkContext is None:
147146
raise ValueError("datalink_context must be specified at TAP "
148147
+ "object creation for this action to be "
@@ -170,7 +169,7 @@ def __get_table_edit_context(self):
170169
def __get_server_context(self, subContext):
171170
return f"{self.__serverContext}/{subContext}"
172171

173-
def execute_tapget(self, subcontext, verbose=False):
172+
def execute_tapget(self, subcontext, *, verbose=False):
174173
"""Executes a TAP GET request
175174
The connection is done through HTTP or HTTPS depending on the login
176175
status (logged in -> HTTPS)
@@ -189,12 +188,12 @@ def execute_tapget(self, subcontext, verbose=False):
189188
"""
190189
if subcontext.startswith("http"):
191190
# absolute url
192-
return self.__execute_get(subcontext, verbose)
191+
return self.__execute_get(subcontext, verbose=verbose)
193192
else:
194193
context = self.__get_tap_context(subcontext)
195-
return self.__execute_get(context, verbose)
194+
return self.__execute_get(context, verbose=verbose)
196195

197-
def execute_dataget(self, query, verbose=False):
196+
def execute_dataget(self, query, *, verbose=False):
198197
"""Executes a data GET request
199198
The connection is done through HTTP or HTTPS depending on the login
200199
status (logged in -> HTTPS)
@@ -213,7 +212,7 @@ def execute_dataget(self, query, verbose=False):
213212
context = self.__get_data_context(query)
214213
return self.__execute_get(context, verbose)
215214

216-
def execute_datalinkget(self, subcontext, query, verbose=False):
215+
def execute_datalinkget(self, subcontext, query, *, verbose=False):
217216
"""Executes a datalink GET request
218217
The connection is done through HTTP or HTTPS depending on the login
219218
status (logged in -> HTTPS)
@@ -234,8 +233,8 @@ def execute_datalinkget(self, subcontext, query, verbose=False):
234233
context = self.__get_datalink_context(subcontext, query)
235234
return self.__execute_get(context, verbose)
236235

237-
def __execute_get(self, context, verbose=False):
238-
conn = self.__get_connection(verbose)
236+
def __execute_get(self, context, *, verbose=False):
237+
conn = self.__get_connection(verbose=verbose)
239238
if verbose:
240239
print(f"host = {conn.host}:{conn.port}")
241240
print(f"context = {context}")
@@ -246,7 +245,7 @@ def __execute_get(self, context, verbose=False):
246245
return response
247246

248247
def execute_tappost(self, subcontext, data,
249-
content_type=CONTENT_TYPE_POST_DEFAULT,
248+
content_type=CONTENT_TYPE_POST_DEFAULT, *,
250249
verbose=False):
251250
"""Executes a POST request
252251
The connection is done through HTTP or HTTPS depending on the login
@@ -269,10 +268,10 @@ def execute_tappost(self, subcontext, data,
269268
An HTTP(s) response object
270269
"""
271270
context = self.__get_tap_context(subcontext)
272-
return self.__execute_post(context, data, content_type, verbose)
271+
return self.__execute_post(context, data, content_type, verbose=verbose)
273272

274273
def execute_datapost(self, data,
275-
content_type=CONTENT_TYPE_POST_DEFAULT,
274+
content_type=CONTENT_TYPE_POST_DEFAULT, *,
276275
verbose=False):
277276
"""Executes a POST request
278277
The connection is done through HTTP or HTTPS depending on the login
@@ -292,10 +291,10 @@ def execute_datapost(self, data,
292291
An HTTP(s) response object
293292
"""
294293
context = self.__get_data_context()
295-
return self.__execute_post(context, data, content_type, verbose)
294+
return self.__execute_post(context, data, content_type, verbose=verbose)
296295

297296
def execute_datalinkpost(self, subcontext, data,
298-
content_type=CONTENT_TYPE_POST_DEFAULT,
297+
content_type=CONTENT_TYPE_POST_DEFAULT, *,
299298
verbose=False):
300299
"""Executes a POST request
301300
The connection is done through HTTP or HTTPS depending on the login
@@ -318,10 +317,10 @@ def execute_datalinkpost(self, subcontext, data,
318317
An HTTP(s) response object
319318
"""
320319
context = self.__get_datalink_context(subcontext)
321-
return self.__execute_post(context, data, content_type, verbose)
320+
return self.__execute_post(context, data, content_type, verbose=verbose)
322321

323322
def execute_upload(self, data,
324-
content_type=CONTENT_TYPE_POST_DEFAULT,
323+
content_type=CONTENT_TYPE_POST_DEFAULT, *,
325324
verbose=False):
326325
"""Executes a POST upload request
327326
The connection is done through HTTP or HTTPS depending on the login
@@ -341,9 +340,9 @@ def execute_upload(self, data,
341340
An HTTP(s) response object
342341
"""
343342
context = self.__get_upload_context()
344-
return self.__execute_post(context, data, content_type, verbose)
343+
return self.__execute_post(context, data, content_type, verbose=verbose)
345344

346-
def execute_share(self, data, verbose=False):
345+
def execute_share(self, data, *, verbose=False):
347346
"""Executes a POST upload request
348347
The connection is done through HTTP or HTTPS depending on the login
349348
status (logged in -> HTTPS)
@@ -368,7 +367,7 @@ def execute_share(self, data, verbose=False):
368367
verbose=verbose)
369368

370369
def execute_table_edit(self, data,
371-
content_type=CONTENT_TYPE_POST_DEFAULT,
370+
content_type=CONTENT_TYPE_POST_DEFAULT, *,
372371
verbose=False):
373372
"""Executes a POST upload request
374373
The connection is done through HTTP or HTTPS depending on the login
@@ -388,10 +387,10 @@ def execute_table_edit(self, data,
388387
An HTTP(s) response object
389388
"""
390389
context = self.__get_table_edit_context()
391-
return self.__execute_post(context, data, content_type, verbose)
390+
return self.__execute_post(context, data, content_type, verbose=verbose)
392391

393392
def execute_table_tool(self, data,
394-
content_type=CONTENT_TYPE_POST_DEFAULT,
393+
content_type=CONTENT_TYPE_POST_DEFAULT, *,
395394
verbose=False):
396395
"""Executes a POST upload request
397396
The connection is done through HTTP or HTTPS depending on the login
@@ -411,12 +410,12 @@ def execute_table_tool(self, data,
411410
An HTTP(s) response object
412411
"""
413412
context = self.__get_table_edit_context()
414-
return self.__execute_post(context, data, content_type, verbose)
413+
return self.__execute_post(context, data, content_type, verbose=verbose)
415414

416415
def __execute_post(self, context, data,
417-
content_type=CONTENT_TYPE_POST_DEFAULT,
416+
content_type=CONTENT_TYPE_POST_DEFAULT, *,
418417
verbose=False):
419-
conn = self.__get_connection(verbose)
418+
conn = self.__get_connection(verbose=verbose)
420419
if verbose:
421420
print(f"host = {conn.host}:{conn.port}")
422421
print(f"context = {context}")
@@ -428,7 +427,7 @@ def __execute_post(self, context, data,
428427
self.__currentStatus = response.status
429428
return response
430429

431-
def execute_secure(self, subcontext, data, verbose=False):
430+
def execute_secure(self, subcontext, data, *, verbose=False):
432431
"""Executes a secure POST request
433432
The connection is done through HTTPS
434433
@@ -445,7 +444,7 @@ def execute_secure(self, subcontext, data, verbose=False):
445444
-------
446445
An HTTPS response object
447446
"""
448-
conn = self.__get_connection_secure(verbose)
447+
conn = self.__get_connection_secure(verbose=verbose)
449448
context = self.__get_server_context(subcontext)
450449
self.__postHeaders["Content-type"] = CONTENT_TYPE_POST_DEFAULT
451450
conn.request("POST", context, data, self.__postHeaders)
@@ -638,7 +637,7 @@ def get_host_url_secure(self):
638637
return f'{self.__connHost}:{self.__connPortSsl}{self.__get_tap_context("")}'
639638

640639
def check_launch_response_status(self, response, debug,
641-
expected_response_status,
640+
expected_response_status, *,
642641
raise_exception=True):
643642
"""Checks the response status code
644643
Returns True if the response status code is the
@@ -673,13 +672,13 @@ def check_launch_response_status(self, response, debug,
673672
else:
674673
return isError
675674

676-
def __get_connection(self, verbose=False):
677-
return self.__connectionHandler.get_connection(self.__isHttps,
678-
self.__cookie,
679-
verbose)
675+
def __get_connection(self, *, verbose=False):
676+
return self.__connectionHandler.get_connection(ishttps=self.__isHttps,
677+
cookie=self.__cookie,
678+
verbose=verbose)
680679

681-
def __get_connection_secure(self, verbose=False):
682-
return self.__connectionHandler.get_connection_secure(verbose)
680+
def __get_connection_secure(self, *, verbose=False):
681+
return self.__connectionHandler.get_connection_secure(verbose=verbose)
683682

684683
def encode_multipart(self, fields, files):
685684
"""Encodes a multipart form request
@@ -731,7 +730,7 @@ def __init__(self, host, port, sslport):
731730
self.__connPort = port
732731
self.__connPortSsl = sslport
733732

734-
def get_connection(self, ishttps=False, cookie=None, verbose=False):
733+
def get_connection(self, *, ishttps=False, cookie=None, verbose=False):
735734
if (ishttps) or (cookie is not None):
736735
if verbose:
737736
print("------>https")

astroquery/utils/tap/conn/tests/test_conn.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def test_get():
4848
# GET
4949
subContext = "testSubContextGet"
5050
context = f"/{serverContext}/{tapContext}/{subContext}"
51-
r = tap.execute_tapget(subcontext=subContext)
51+
r = tap.execute_tapget(subcontext=subContext, verbose=False)
5252
assert r.status == 222
5353
assert r.get_method() == 'GET'
5454
assert r.get_context() == context
@@ -79,7 +79,7 @@ def test_post():
7979
subContext = "testSubContextGet"
8080
context = f"/{serverContext}/{tapContext}/{subContext}"
8181
data = "postData"
82-
r = tap.execute_tappost(subcontext=subContext, data=data)
82+
r = tap.execute_tappost(subcontext=subContext, data=data, verbose=False)
8383
assert r.status == 111
8484
assert r.get_method() == 'POST'
8585
assert r.get_context() == context
@@ -110,7 +110,7 @@ def test_login():
110110
subContext = "testSubContextPost"
111111
context = f"/{serverContext}/{subContext}"
112112
data = "testData"
113-
r = tap.execute_secure(subcontext=subContext, data=data)
113+
r = tap.execute_secure(subcontext=subContext, data=data, verbose=False)
114114
assert r.status == 333
115115
assert r.get_method() == 'POST'
116116
assert r.get_context() == context

0 commit comments

Comments
 (0)