10
10
11
11
import base64
12
12
import email
13
+ import functools
13
14
import json
14
15
import os
15
16
import os .path
@@ -77,6 +78,26 @@ def ist_table(instrument_name):
77
78
return f"ist.{ instrument_name } "
78
79
79
80
81
+ def unlimited_max_rec (func ):
82
+ """
83
+ decorator to overwrite the ROW LIMIT
84
+ for specific queries
85
+ """
86
+ @functools .wraps (func )
87
+ def wrapper (self , * args , ** kwargs ):
88
+ if not isinstance (self , EsoClass ):
89
+ raise ValueError (f"Expecting EsoClass, found { type (self )} " )
90
+
91
+ tmpvar = self .ROW_LIMIT
92
+ try :
93
+ self .ROW_LIMIT = sys .maxsize
94
+ result = func (self , * args , ** kwargs )
95
+ finally :
96
+ self .ROW_LIMIT = tmpvar
97
+ return result
98
+ return wrapper
99
+
100
+
80
101
class EsoClass (QueryWithLogin ):
81
102
ROW_LIMIT = conf .row_limit
82
103
USERNAME = conf .username
@@ -224,26 +245,23 @@ def query_tap_service(self,
224
245
225
246
return table_to_return
226
247
248
+ @unlimited_max_rec
227
249
def list_instruments (self ) -> List [str ]:
228
250
""" List all the available instrument-specific queries offered by the ESO archive.
229
251
230
252
Returns
231
253
-------
232
254
instrument_list : list of strings
233
255
"""
234
- tmpvar = self .ROW_LIMIT
235
- self .ROW_LIMIT = sys .maxsize
236
- try :
237
- if self ._instruments is None :
238
- self ._instruments = []
239
- query_str = ("select table_name from TAP_SCHEMA.tables "
240
- "where schema_name='ist' order by table_name" )
241
- res = self .query_tap_service (query_str )["table_name" ].data
242
- self ._instruments = list (map (lambda x : x .split ("." )[1 ], res ))
243
- finally :
244
- self .ROW_LIMIT = tmpvar
256
+ if self ._instruments is None :
257
+ self ._instruments = []
258
+ query_str = ("select table_name from TAP_SCHEMA.tables "
259
+ "where schema_name='ist' order by table_name" )
260
+ res = self .query_tap_service (query_str )["table_name" ].data
261
+ self ._instruments = list (map (lambda x : x .split ("." )[1 ], res ))
245
262
return self ._instruments
246
263
264
+ @unlimited_max_rec
247
265
def list_collections (self ) -> List [str ]:
248
266
""" List all the available collections (phase 3) in the ESO archive.
249
267
@@ -254,21 +272,16 @@ def list_collections(self) -> List[str]:
254
272
Defaults to True. If set overrides global caching behavior.
255
273
See :ref:`caching documentation <astroquery_cache>`.
256
274
"""
257
- tmpvar = self .ROW_LIMIT
258
- self .ROW_LIMIT = sys .maxsize
259
- try :
260
- if self ._collections is None :
261
- self ._collections = []
262
- t = EsoNames .phase3_table
263
- c = EsoNames .phase3_collections_column
264
- query_str = f"select distinct { c } from { t } "
265
- res = self .query_tap_service (query_str )[c ].data
266
-
267
- self ._collections = list (res )
268
- finally :
269
- self .ROW_LIMIT = tmpvar
275
+ if self ._collections is None :
276
+ self ._collections = []
277
+ t = EsoNames .phase3_table
278
+ c = EsoNames .phase3_collections_column
279
+ query_str = f"select distinct { c } from { t } "
280
+ res = self .query_tap_service (query_str )[c ].data
281
+ self ._collections = list (res )
270
282
return self ._collections
271
283
284
+ @unlimited_max_rec
272
285
def print_table_help (self , table_name : str ) -> None :
273
286
"""
274
287
Prints the columns contained in a given table
0 commit comments