@@ -670,7 +670,7 @@ def set_token(self, token):
670
670
subContext = conf .JWST_TOKEN
671
671
data = urlencode ({"token" : token })
672
672
connHandler = self .__jwsttap ._TapPlus__getconnhandler ()
673
- response = connHandler .execute_secure (subContext , data , True )
673
+ response = connHandler .execute_secure (subcontext = subContext , data = data , verbose = True )
674
674
if response .status == 403 :
675
675
print ("ERROR: MAST tokens cannot be assigned or requested by anonymous users" )
676
676
elif response .status == 500 :
@@ -690,7 +690,7 @@ def get_status_messages(self):
690
690
if response .status == 200 :
691
691
for line in response :
692
692
string_message = line .decode ("utf-8" )
693
- print (string_message [string_message .index ('=' )+ 1 :])
693
+ print (string_message [string_message .index ('=' ) + 1 :])
694
694
except OSError :
695
695
print ("Status messages could not be retrieved" )
696
696
@@ -725,7 +725,7 @@ def get_product_list(self, *, observation_id=None,
725
725
if observation_id is None :
726
726
raise ValueError (self .REQUESTED_OBSERVATION_ID )
727
727
plane_ids , max_cal_level = self ._get_plane_id (observation_id = observation_id )
728
- if ( cal_level == 3 and cal_level > max_cal_level ) :
728
+ if cal_level == 3 and cal_level > max_cal_level :
729
729
raise ValueError ("Requesting upper levels is not allowed" )
730
730
list = self ._get_associated_planes (plane_ids = plane_ids ,
731
731
cal_level = cal_level ,
@@ -778,7 +778,7 @@ def _get_plane_id(self, observation_id):
778
778
job .get_results ().reverse ()
779
779
max_cal_level = job .get_results ()["calibrationlevel" ][0 ]
780
780
for row in job .get_results ():
781
- if ( row ["calibrationlevel" ] == max_cal_level ) :
781
+ if row ["calibrationlevel" ] == max_cal_level :
782
782
planeids .append (
783
783
JwstClass .get_decoded_string (row ["planeid" ]))
784
784
return planeids , max_cal_level
@@ -898,8 +898,7 @@ def get_product(self, *, artifact_id=None, file_name=None):
898
898
output_file_name = self ._query_get_product (artifact_id = artifact_id )
899
899
err_msg = str (artifact_id )
900
900
except Exception as exx :
901
- raise ValueError ('Cannot retrieve product for artifact_id '
902
- + artifact_id + ': %s' % str (exx ))
901
+ raise ValueError (f"Cannot retrieve product for artifact_id { artifact_id } : { exx } " )
903
902
else :
904
903
output_file_name = str (file_name )
905
904
err_msg = str (file_name )
@@ -911,16 +910,14 @@ def get_product(self, *, artifact_id=None, file_name=None):
911
910
params_dict ['ARTIFACTID' ] = (self ._query_get_product (
912
911
file_name = file_name ))
913
912
except Exception as exx :
914
- raise ValueError ('Cannot retrieve product for file_name '
915
- + file_name + ': %s' % str (exx ))
913
+ raise ValueError (f"Cannot retrieve product for file_name { file_name } : { exx } " )
916
914
917
915
try :
918
916
self .__jwsttap .load_data (params_dict = params_dict ,
919
917
output_file = output_file_name )
920
918
except Exception as exx :
921
919
log .info ("error" )
922
- raise ValueError ('Error retrieving product for '
923
- + err_msg + ': %s' % str (exx ))
920
+ raise ValueError (f"Error retrieving product for { err_msg } : { exx } " )
924
921
return output_file_name
925
922
926
923
def _query_get_product (self , * , artifact_id = None , file_name = None ):
@@ -1002,8 +999,7 @@ def get_obs_products(self, *, observation_id=None, cal_level="ALL",
1002
999
self .__jwsttap .load_data (params_dict = params_dict ,
1003
1000
output_file = output_file_full_path )
1004
1001
except Exception as exx :
1005
- raise ValueError ('Cannot retrieve products for observation '
1006
- + observation_id + ': %s' % str (exx ))
1002
+ raise ValueError (f"Cannot retrieve products for observation { observation_id } : { exx } " )
1007
1003
1008
1004
files = []
1009
1005
self .__extract_file (output_file_full_path = output_file_full_path ,
@@ -1066,8 +1062,7 @@ def __set_dirs(self, output_file, observation_id):
1066
1062
try :
1067
1063
os .makedirs (output_dir , exist_ok = True )
1068
1064
except OSError as err :
1069
- raise OSError ("Creation of the directory %s failed: %s"
1070
- % (output_dir , err .strerror ))
1065
+ raise OSError (f"Creation of the directory { output_dir } failed: { err .strerror } " )
1071
1066
return output_file_full_path , output_dir
1072
1067
1073
1068
def __set_additional_parameters (self , param_dict , cal_level ,
@@ -1086,10 +1081,9 @@ def __set_additional_parameters(self, param_dict, cal_level,
1086
1081
1087
1082
def __get_quantity_input (self , value , msg ):
1088
1083
if value is None :
1089
- raise ValueError ("Missing required argument: '" + str ( msg ) + " '" )
1084
+ raise ValueError (f "Missing required argument: '{ msg } '" )
1090
1085
if not (isinstance (value , str ) or isinstance (value , units .Quantity )):
1091
- raise ValueError (
1092
- str (msg ) + " must be either a string or astropy.coordinates" )
1086
+ raise ValueError (f"{ msg } must be either a string or units.Quantity" )
1093
1087
if isinstance (value , str ):
1094
1088
q = Quantity (value )
1095
1089
return q
@@ -1099,8 +1093,7 @@ def __get_quantity_input(self, value, msg):
1099
1093
def __get_coord_input (self , value , msg ):
1100
1094
if not (isinstance (value , str ) or isinstance (value ,
1101
1095
commons .CoordClasses )):
1102
- raise ValueError (
1103
- str (msg ) + " must be either a string or astropy.coordinates" )
1096
+ raise ValueError (f"{ msg } must be either a string or astropy.coordinates" )
1104
1097
if isinstance (value , str ):
1105
1098
c = commons .parse_coordinates (value )
1106
1099
return c
@@ -1113,7 +1106,7 @@ def __get_observationid_condition(self, *, value=None):
1113
1106
if (not isinstance (value , str )):
1114
1107
raise ValueError ("observation_id must be string" )
1115
1108
else :
1116
- condition = " AND observationid LIKE '" + value .lower ()+ " ' "
1109
+ condition = f " AND observationid LIKE '{ value .lower ()} ' "
1117
1110
return condition
1118
1111
1119
1112
def __get_callevel_condition (self , cal_level ):
@@ -1122,8 +1115,7 @@ def __get_callevel_condition(self, cal_level):
1122
1115
if (isinstance (cal_level , str ) and cal_level == 'Top' ):
1123
1116
condition = " AND max_cal_level=calibrationlevel "
1124
1117
elif (isinstance (cal_level , int )):
1125
- condition = " AND calibrationlevel=" + \
1126
- str (cal_level )+ " "
1118
+ condition = f" AND calibrationlevel={ str (cal_level )} "
1127
1119
else :
1128
1120
raise ValueError ("cal_level must be either "
1129
1121
"'Top' or an integer" )
@@ -1139,15 +1131,13 @@ def __get_public_condition(self, only_public):
1139
1131
1140
1132
def __get_plane_dataproducttype_condition (self , * , prod_type = None ):
1141
1133
condition = ""
1142
- if ( prod_type is not None ) :
1143
- if ( not isinstance (prod_type , str ) ):
1134
+ if prod_type is not None :
1135
+ if not isinstance (prod_type , str ):
1144
1136
raise ValueError ("prod_type must be string" )
1145
- elif (str (prod_type ).lower () not in self .PLANE_DATAPRODUCT_TYPES ):
1146
- raise ValueError ("prod_type must be one of: "
1147
- + str (', ' .join (self .PLANE_DATAPRODUCT_TYPES )))
1137
+ elif str (prod_type ).lower () not in self .PLANE_DATAPRODUCT_TYPES :
1138
+ raise ValueError ("prod_type must be one of: {str(', '.join(self.PLANE_DATAPRODUCT_TYPES))}" )
1148
1139
else :
1149
- condition = " AND dataproducttype ILIKE '%" + prod_type .lower () + \
1150
- "%' "
1140
+ condition = f" AND dataproducttype ILIKE '%{ prod_type .lower ()} %' "
1151
1141
return condition
1152
1142
1153
1143
def __get_instrument_name_condition (self , * , value = None ):
@@ -1156,10 +1146,9 @@ def __get_instrument_name_condition(self, *, value=None):
1156
1146
if (not isinstance (value , str )):
1157
1147
raise ValueError ("instrument_name must be string" )
1158
1148
elif (str (value ).upper () not in self .INSTRUMENT_NAMES ):
1159
- raise ValueError ("instrument_name must be one of: "
1160
- + str (', ' .join (self .INSTRUMENT_NAMES )))
1149
+ raise ValueError (f"instrument_name must be one of: { str (', ' .join (self .INSTRUMENT_NAMES ))} " )
1161
1150
else :
1162
- condition = " AND instrument_name ILIKE '%" + value .upper ()+ " %' "
1151
+ condition = f " AND instrument_name ILIKE '%{ value .upper ()} %' "
1163
1152
return condition
1164
1153
1165
1154
def __get_filter_name_condition (self , * , value = None ):
@@ -1169,7 +1158,7 @@ def __get_filter_name_condition(self, *, value=None):
1169
1158
raise ValueError ("filter_name must be string" )
1170
1159
1171
1160
else :
1172
- condition = " AND energy_bandpassname ILIKE '%" + value + " %' "
1161
+ condition = f " AND energy_bandpassname ILIKE '%{ value } %' "
1173
1162
return condition
1174
1163
1175
1164
def __get_proposal_id_condition (self , * , value = None ):
@@ -1179,7 +1168,7 @@ def __get_proposal_id_condition(self, *, value=None):
1179
1168
raise ValueError ("proposal_id must be string" )
1180
1169
1181
1170
else :
1182
- condition = " AND proposal_id ILIKE '%" + value + " %' "
1171
+ condition = f " AND proposal_id ILIKE '%{ value } %' "
1183
1172
return condition
1184
1173
1185
1174
def __get_artifact_producttype_condition (self , * , product_type = None ):
@@ -1188,10 +1177,9 @@ def __get_artifact_producttype_condition(self, *, product_type=None):
1188
1177
if (not isinstance (product_type , str )):
1189
1178
raise ValueError ("product_type must be string" )
1190
1179
elif (product_type not in self .ARTIFACT_PRODUCT_TYPES ):
1191
- raise ValueError ("product_type must be one of: "
1192
- + str (', ' .join (self .ARTIFACT_PRODUCT_TYPES )))
1180
+ raise ValueError (f"product_type must be one of: { str (', ' .join (self .ARTIFACT_PRODUCT_TYPES ))} " )
1193
1181
else :
1194
- condition = " AND producttype ILIKE '%" + product_type + " %'"
1182
+ condition = f " AND producttype ILIKE '%{ product_type } %'"
1195
1183
return condition
1196
1184
1197
1185
@staticmethod
@@ -1217,7 +1205,7 @@ def gzip_uncompress_and_rename_single_file(input_file):
1217
1205
os .remove (input_file )
1218
1206
if file .lower ().endswith (".gz" ):
1219
1207
# remove .gz
1220
- new_file_name = file [:len (file )- 3 ]
1208
+ new_file_name = file [:len (file ) - 3 ]
1221
1209
output = output_dir + os .sep + new_file_name
1222
1210
else :
1223
1211
output = input_file
0 commit comments