11import json
22import re
33import urllib
4- from idlelib .pyparse import trans
54from typing import Optional
65
76import requests
@@ -117,8 +116,7 @@ def get_ds_from_api(self):
117116 endpoint : str = config ['endpoint' ]
118117 endpoint = self .get_complete_endpoint (endpoint = endpoint )
119118 if not endpoint :
120- raise Exception (
121- f"Failed to get datasource list from { config ['endpoint' ]} , error: [Assistant domain or endpoint miss]" )
119+ raise Exception (f"Failed to get datasource list from { config ['endpoint' ]} , error: [Assistant domain or endpoint miss]" )
122120 certificateList : list [any ] = json .loads (self .certificate )
123121 header = {}
124122 cookies = {}
@@ -145,25 +143,23 @@ def get_ds_from_api(self):
145143 raise Exception (f"Failed to get datasource list from { endpoint } , error: { result_json .get ('message' )} " )
146144 else :
147145 raise Exception (f"Failed to get datasource list from { endpoint } , status code: { res .status_code } " )
148-
146+
149147 def get_first_element (self , text : str ):
150148 parts = re .split (r'[,;]' , text .strip ())
151149 first_domain = parts [0 ].strip ()
152150 return first_domain
153-
151+
154152 def get_complete_endpoint (self , endpoint : str ) -> str | None :
155153 if endpoint .startswith ("http://" ) or endpoint .startswith ("https://" ):
156154 return endpoint
157155 domain_text = self .assistant .domain
158156 if not domain_text :
159157 return None
160158 if ',' in domain_text or ';' in domain_text :
161- return (
162- self .request_origin .strip ('/' ) if self .request_origin else self .get_first_element (domain_text ).strip (
163- '/' )) + endpoint
159+ return (self .request_origin .strip ('/' ) if self .request_origin else self .get_first_element (domain_text ).strip ('/' )) + endpoint
164160 else :
165- return f"{ domain_text } { endpoint } "
166-
161+ return f"{ domain_text } { endpoint } "
162+
167163 def get_simple_ds_list (self ):
168164 if self .ds_list :
169165 return [{'id' : ds .id , 'name' : ds .name , 'description' : ds .comment } for ds in self .ds_list ]
@@ -215,8 +211,8 @@ def get_ds(self, ds_id: int):
215211 if ds .id == ds_id :
216212 return ds
217213 else :
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 ) )
214+ raise Exception ("Datasource list is not found." )
215+ raise Exception (f"Datasource with id { ds_id } not found." )
220216
221217 def convert2schema (self , ds_dict : dict , config : dict [any ]) -> AssistantOutDsSchema :
222218 id_marker : str = ''
@@ -279,17 +275,17 @@ def get_ds_engine(ds: AssistantOutDsSchema) -> Engine:
279275 return engine
280276
281277
282- def get_out_ds_conf (ds : AssistantOutDsSchema , timeout : int = 30 ) -> str :
278+ def get_out_ds_conf (ds : AssistantOutDsSchema , timeout :int = 30 ) -> str :
283279 conf = {
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
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
293289 }
294290 conf ["extraJdbc" ] = ''
295291 return aes_encrypt (json .dumps (conf ))
0 commit comments