11import json
22import re
33import urllib
4+ from idlelib .pyparse import trans
45from typing import Optional
56
67import requests
@@ -116,7 +117,8 @@ def get_ds_from_api(self):
116117 endpoint : str = config ['endpoint' ]
117118 endpoint = self .get_complete_endpoint (endpoint = endpoint )
118119 if not endpoint :
119- raise Exception (f"Failed to get datasource list from { config ['endpoint' ]} , error: [Assistant domain or endpoint miss]" )
120+ raise Exception (
121+ f"Failed to get datasource list from { config ['endpoint' ]} , error: [Assistant domain or endpoint miss]" )
120122 certificateList : list [any ] = json .loads (self .certificate )
121123 header = {}
122124 cookies = {}
@@ -143,23 +145,25 @@ def get_ds_from_api(self):
143145 raise Exception (f"Failed to get datasource list from { endpoint } , error: { result_json .get ('message' )} " )
144146 else :
145147 raise Exception (f"Failed to get datasource list from { endpoint } , status code: { res .status_code } " )
146-
148+
147149 def get_first_element (self , text : str ):
148150 parts = re .split (r'[,;]' , text .strip ())
149151 first_domain = parts [0 ].strip ()
150152 return first_domain
151-
153+
152154 def get_complete_endpoint (self , endpoint : str ) -> str | None :
153155 if endpoint .startswith ("http://" ) or endpoint .startswith ("https://" ):
154156 return endpoint
155157 domain_text = self .assistant .domain
156158 if not domain_text :
157159 return None
158160 if ',' in domain_text or ';' in domain_text :
159- return (self .request_origin .strip ('/' ) if self .request_origin else self .get_first_element (domain_text ).strip ('/' )) + endpoint
161+ return (
162+ self .request_origin .strip ('/' ) if self .request_origin else self .get_first_element (domain_text ).strip (
163+ '/' )) + endpoint
160164 else :
161- return f"{ domain_text } { endpoint } "
162-
165+ return f"{ domain_text } { endpoint } "
166+
163167 def get_simple_ds_list (self ):
164168 if self .ds_list :
165169 return [{'id' : ds .id , 'name' : ds .name , 'description' : ds .comment } for ds in self .ds_list ]
@@ -211,8 +215,8 @@ def get_ds(self, ds_id: int):
211215 if ds .id == ds_id :
212216 return ds
213217 else :
214- raise Exception ("Datasource list is not found." )
215- raise Exception (f"Datasource with id { ds_id } not found." )
218+ raise Exception (trans ( 'i18n_data_training.datasource_list_is_not_found' ) )
219+ raise Exception (trans ( 'i18n_data_training.datasource_id_not_found' , key = ds_id ) )
216220
217221 def convert2schema (self , ds_dict : dict , config : dict [any ]) -> AssistantOutDsSchema :
218222 id_marker : str = ''
@@ -275,17 +279,17 @@ def get_ds_engine(ds: AssistantOutDsSchema) -> Engine:
275279 return engine
276280
277281
278- def get_out_ds_conf (ds : AssistantOutDsSchema , timeout :int = 30 ) -> str :
282+ def get_out_ds_conf (ds : AssistantOutDsSchema , timeout : int = 30 ) -> str :
279283 conf = {
280- "host" :ds .host or '' ,
281- "port" :ds .port or 0 ,
282- "username" :ds .user or '' ,
283- "password" :ds .password or '' ,
284- "database" :ds .dataBase or '' ,
285- "driver" :'' ,
286- "extraJdbc" :ds .extraParams or '' ,
287- "dbSchema" :ds .db_schema or '' ,
288- "timeout" :timeout or 30
284+ "host" : ds .host or '' ,
285+ "port" : ds .port or 0 ,
286+ "username" : ds .user or '' ,
287+ "password" : ds .password or '' ,
288+ "database" : ds .dataBase or '' ,
289+ "driver" : '' ,
290+ "extraJdbc" : ds .extraParams or '' ,
291+ "dbSchema" : ds .db_schema or '' ,
292+ "timeout" : timeout or 30
289293 }
290294 conf ["extraJdbc" ] = ''
291295 return aes_encrypt (json .dumps (conf ))
0 commit comments