How to use log_info method in Lemoncheesecake

Best Python code snippet using lemoncheesecake

ATTVoip.py

Source:ATTVoip.py Github

copy

Full Screen

1# Embedded file name: ATTVoip.py2# -*- coding: utf-8 -*-3import sys4import time5from keygoe.keygoe import Keygoe6import ConfigParser7import os8VOIP_FUN_OK = 19VOIP_FUN_FIAL = -11011class _PHONESTATE():12 """13 """14 S_NONE = 115 S_INIT = 216 S_CALL_OUT_OFFHOOK = 317 S_CHECK_CALL_IN = 518 S_IN_CALL = 719 S_RECV_FAX_START = 820 S_ONHOOK = 921 S_CLEAR_CALL = 10222324class CPEPhone():2526 def __init__(self, trunk_id):27 """28 CPE\xe7\x9b\xb8\xe5\x85\xb3\xe4\xbf\xa1\xe6\x81\xaf29 """30 self.trunk_id = trunk_id31 self.state = _PHONESTATE.S_NONE3233 def get_trunk(self):34 return self.trunk_id3536 def get_state(self):37 return self.state3839 def set_state(self, state):40 self.state = state4142 def reset(self):43 self.state = _PHONESTATE.S_NONE444546class AttToneConfig():4748 def __init__(self, log):49 self.user_info = log50 self.freq_dict = {}51 self.cf = ConfigParser.ConfigParser()52 self.inifile = os.path.join(os.path.dirname(__file__), 'keygoe\\XMS_KEYGOE.INI')53 self.user_info(self.inifile)54 self.cf.read(self.inifile)55 self._read_all_freq()56 self._update_freq()57 self.user_info(u"初始化ATTToneConfig成功")5859 def _read_all_freq(self):60 """61 \xe8\xaf\xbb\xe5\x8f\x96\xe9\x85\x8d\xe7\xbd\xae\xe6\x96\x87\xe4\xbb\xb6\xe8\x8e\xb7\xe5\x8f\x96\xe6\x9c\x89\xe5\x93\xaa\xe9\xa2\x91\xe7\x8e\x8762 """63 self.freq_dict.clear()64 index_freq = 065 ss = self.cf.sections()66 for item in ss:67 if item in ('ConfigInfo', 'Freq'):68 continue69 try:70 Freq = self.cf.getint(item, 'freq')71 if Freq not in self.freq_dict.keys():72 self.freq_dict[Freq] = index_freq73 index_freq += 174 except Exception as e2:75 log_info = u'\u8bfb\u53d6\u914d\u7f6e\u6587\u4ef6\u8282\u70b9%s\u5931\u8d25.' % item76 self.user_info(u"出错")77 self.user_info(log_info)78 raise RuntimeError(log_info)7980 def _update_freq(self):81 """82 \xe6\x9b\xb4\xe6\x96\xb0\xe9\xa2\x91\xe7\x8e\x87\xe7\x9a\x84\xe9\x85\x8d\xe7\xbd\xae\xef\xbc\x8cupdate \xe6\x89\x80\xe6\x9c\x89\xe9\x9f\xb3\xe7\x9a\x84freqindexmask83 """84 try:85 for freq in self.freq_dict.keys():86 index = self.freq_dict.get(freq)87 self.cf.set('Freq', str(index), freq)8889 freq_count = len(self.freq_dict)90 self.cf.set('ConfigInfo', 'freqcount', freq_count)91 except Exception:92 log_info = u'\u8bfb\u53d6\u9891\u7387\u914d\u7f6e\u5931\u8d25.'93 self.user_info(log_info)94 raise RuntimeError(log_info)9596 ss = self.cf.sections()97 for item in ss:98 if item in ('ConfigInfo', 'Freq'):99 continue100 try:101 cur_freq = self.cf.get(item, 'freq')102 cur_index = self.freq_dict[int(cur_freq)]103 cur_freq_maxk = 2 ** cur_index104 self.cf.set(item, 'freqindexmask', cur_freq_maxk)105 self.cf.write(open(self.inifile, 'w'))106 except Exception as e2:107 log_info = u'\u4fee\u6539\u914d\u7f6e\u6587\u4ef6\u8282\u70b9%s\u5931\u8d25.' % item108 raise RuntimeError(log_info)109110 def config_some_tone(self, name, freq, envelopemode, ontime1, offtime1, ontime2, offtime2, timedeviation):111 """112 \xe9\x85\x8d\xe7\xbd\xae\xe8\xa6\x81\xe6\xa3\x80\xe6\xb5\x8b\xe7\x9a\x84\xe9\x9f\xb3113 """114 skey = name115 try:116 if skey == None:117 skey = ''118 raise Exception(u'\u8981\u914d\u7f6e\u7684\u58f0\u97f3\u540d\u79f0\u4e3anone')119 self.cf.set(skey, 'Freq', freq)120 self.cf.set(skey, 'EnvelopeMode', envelopemode)121 self.cf.set(skey, 'On_Time', ontime1)122 self.cf.set(skey, 'Off_Time', offtime1)123 self.cf.set(skey, 'On_Time_Two', ontime2)124 self.cf.set(skey, 'Off_Time_Two', offtime2)125 self.cf.set(skey, 'TimeDeviation', timedeviation)126 self.cf.write(open(self.inifile, 'w'))127 index_freq = -1128 mark_freq = -1129 freq_count = len(self.freq_dict)130 self.user_info(str(self.freq_dict))131 if freq in self.freq_dict.keys():132 index_freq = self.freq_dict[freq]133 mark_freq = 2 ** index_freq134 else:135 index_freq = freq_count + 1 - 1136 if index_freq >= 16:137 log_info = u'\u4e0d\u80fd\u914d\u7f6e\u8d85\u8fc716\u4e2a\u4e0d\u540c\u9891\u7387\uff0c\u8bf7\u65ad\u5f00\u670d\u52a1\u540e\u91cd\u65b0\u8fde\u63a5'138 self.user_info(log_info)139 raise RuntimeError(log_info)140 self.freq_dict[freq] = index_freq141 self.cf.set('Freq', str(index_freq), freq)142 self.cf.set('ConfigInfo', 'freqcount', index_freq + 1)143 mark_freq = 2 ** index_freq144 self.cf.set(skey, 'freqindexmask', mark_freq)145 self.cf.write(open(self.inifile, 'w'))146 except Exception as e:147 log_info = u'\u4fee\u6539\u914d\u7f6e\u6587\u4ef6\u8282\u70b9%s\u5931\u8d25. %s' % (skey, e)148 self.user_info(log_info)149 raise RuntimeError(log_info)150151 log_info = u'\u5c06\u914d\u7f6e\u7684\u5f85\u68c0\u6d4b\u97f3\u4fe1\u606f\u5199\u5165\u5230\u914d\u7f6e\u6587\u4ef6\u6210\u529f'152 self.user_info(log_info)153 return True154155 def config_system_param(self, serverIp, port, username, password):156 """157 \xe9\x85\x8d\xe7\xbd\xae\xe5\xba\x95\xe5\xb1\x82\xe6\xb5\x81\xe7\xa8\x8b\xe6\x9c\x8d\xe5\x8a\xa1\xe5\x8f\x82\xe6\x95\xb0158 """159 try:160 self.cf.set('ConfigInfo', 'ipaddr', serverIp)161 self.cf.set('ConfigInfo', 'port', port)162 self.cf.set('ConfigInfo', 'username', username)163 self.cf.set('ConfigInfo', 'password', password)164 self.cf.write(open(self.inifile, 'w'))165 self.user_info(u"配置ini文件成功")166 except Exception as e:167 log_info = u'\u4fee\u6539\u914d\u7f6e\u6587\u4ef6\u4e2d\u8bed\u97f3\u5361\u6d41\u7a0b\u670d\u52a1\u914d\u7f6e\u4fe1\u606f\u5931\u8d25. %s'168 self.user_info(log_info)169 raise RuntimeError(log_info)170171 return True172173174175class ATTVoip():176177 def __init__(self, log):178 self.user_info = log179 self.debug_info = log180 self.obj = Keygoe(self.user_info)181 if self.obj == None:182 log_info = u'\u8c03\u7528DLL\u5931\u8d25'183 self.user_info(log_info)184 raise RuntimeError(log_info)185 self.trunk_id_list = [1]186 self.init_keygoe_system()187 self.user_info(u"初始化keygoe系统成功")188 self.phone_dict = {}189 self._init_all_trunk()190 self.user_info(u"初始化所有的trunk成功")191 return192193 def init_keygoe_system(self):194 """195 \xe5\xa7\x8b\xe5\x8c\x96\xe8\xaf\xad\xe9\x9f\xb3\xe5\x8d\xa1\xe8\xae\xbe\xe5\xa4\x87196 """197 if VOIP_FUN_OK == self.obj.init_keygoe_system():198 log_info = u'\u5f00\u59cb\u521d\u59cb\u5316\u8bed\u97f3\u5361\u8bbe\u5907...'199 self.user_info(log_info)200 else:201 log_info = u'\u542f\u52a8\u7cfb\u7edf\u521d\u59cb\u5316\u5931\u8d25'202 raise RuntimeError(log_info)203 nRet = self.obj.wait_trunk_init()204 if VOIP_FUN_FIAL == nRet:205 log_info = u'\u521d\u59cb\u5316\u6a21\u62df\u4e2d\u7ee7\u901a\u9053\u5931\u8d25'206 self.user_info("wait trunk init fail")207 self.user_info(log_info)208 raise RuntimeError(log_info)209 self.debug_info(u'\u53ef\u7528Trunk \u662f %d' % nRet)210 self.user_info(u'\u53ef\u7528Trunk \u662f %d' % nRet)211 for i in range(16):212 if nRet & 1 == 1:213 self.trunk_id_list.append(i + 1)214 nRet = nRet >> 1215216 log_info = u'\u5b8c\u6210\u7cfb\u7edf\u521d\u59cb\u5316,\u53ef\u7528\u6a21\u62df\u901a\u9053\u5217\u8868\u5982\u4e0b\uff1a'217 self.user_info(log_info)218 self.user_info(self.trunk_id_list)219220 def exit_keygoe_system(self):221 """222 """223 if VOIP_FUN_OK == self.obj.exit_keygoe_system():224 log_info = u'\u9000\u51fa\u7cfb\u7edf\u6210\u529f'225 self.user_info(log_info)226 else:227 log_info = u'\u9000\u51fa\u7cfb\u7edf\u5931\u8d25'228 self.user_info(log_info)229 raise RuntimeError(log_info)230231 def _init_all_trunk(self):232 """233 \xe5\x88\x9d\xe5\xa7\x8b\xe5\x8c\x9616\xe4\xb8\xaa\xe9\x80\x9a\xe9\x81\x93\xe7\x9a\x84\xe7\xbc\x93\xe5\xad\x98234 """235 self.phone_dict.clear()236 for i in self.trunk_id_list:237 self.phone_dict[i] = CPEPhone(i)238239 def reset_trunk(self, trunk_id):240 """241 """242 phone = self._get_trunk_config_info(trunk_id)243 if VOIP_FUN_OK == self.obj.clear_keygoe_trunk(trunk_id):244 log_info = u'\u91cd\u7f6e\u6a21\u62df\u901a\u9053\u8bbe\u5907%d\u6210\u529f' % trunk_id245 self.user_info(log_info)246 phone.reset()247 else:248 log_info = u'\u91cd\u7f6e\u6a21\u62df\u901a\u9053\u8bbe\u5907%d\u5931\u8d25' % trunk_id249 self.user_info(log_info)250 raise RuntimeError(log_info)251252 def reset_all_trunk(self):253 """254 """255 trunk_id_list = self.phone_dict.keys()256 for trunk_id in trunk_id_list:257 self.reset_trunk(trunk_id)258259 def _get_trunk_config_info(self, trunk_id):260 """261 """262 if self.phone_dict.has_key(trunk_id):263 try:264 return self.phone_dict.get(trunk_id)265 except Exception as e:266 self.user_info(u'\u53d6\u5b57\u5178\u5931\u8d25')267 raise RuntimeError(u'\u53d6\u5b57\u5178\u5931\u8d25')268269 else:270 self.user_info(u'\u8be5\u901a\u9053\u672a\u88ab\u4f7f\u7528\uff0c\u83b7\u53d6\u76f8\u5173\u4fe1\u606f\u5931\u8d25')271 raise RuntimeError(u'\u8be5\u901a\u9053\u672a\u88ab\u4f7f\u7528\uff0c\u83b7\u53d6\u76f8\u5173\u4fe1\u606f\u5931\u8d25')272273 def call_out_offhook(self, trunk_id):274 """275 """276 phone = self._get_trunk_config_info(trunk_id)277 if phone.get_state() not in [_PHONESTATE.S_NONE,278 _PHONESTATE.S_INIT,279 _PHONESTATE.S_ONHOOK,280 _PHONESTATE.S_CLEAR_CALL]:281 log_info = u'\u5f53\u524d\u72b6\u6001\u4e0d\u80fd\u8fdb\u884c\u8be5\u64cd\u4f5c\uff0c\u8bf7\u68c0\u67e5\u5173\u952e\u5b57\u4f7f\u7528\u6d41\u7a0b\u662f\u5426\u6b63\u786e'282 raise RuntimeError(log_info)283 if VOIP_FUN_OK == self.obj.call_out_off_hook(trunk_id):284 log_info = u'\u6a21\u62df\u901a\u9053%d\u6458\u673a\u6210\u529f' % trunk_id285 self.user_info(log_info)286 phone.set_state(_PHONESTATE.S_CALL_OUT_OFFHOOK)287 else:288 log_info = u'\u6a21\u62df\u901a\u9053%d\u6458\u673a\u5931\u8d25' % trunk_id289 raise RuntimeError(log_info)290291 def dial_by_number(self, trunk_id, number):292 """293 """294 phone_a = self._get_trunk_config_info(trunk_id)295 if phone_a.get_state() not in [_PHONESTATE.S_CALL_OUT_OFFHOOK, _PHONESTATE.S_IN_CALL]:296 log_info = u'\u5f53\u524d\u72b6\u6001\u4e0d\u80fd\u8fdb\u884c\u8be5\u64cd\u4f5c\uff0c\u8bf7\u68c0\u67e5\u5173\u952e\u5b57\u4f7f\u7528\u6d41\u7a0b\u662f\u5426\u6b63\u786e'297 raise RuntimeError(log_info)298 if VOIP_FUN_OK == self.obj.dial(trunk_id, number):299 log_info = u'\u6a21\u62df\u901a\u9053%d\u62e8\u53f7\u7ed9%s\u6210\u529f' % (trunk_id, number)300 self.user_info(log_info)301 phone_a.set_state(_PHONESTATE.S_IN_CALL)302 else:303 log_info = u'\u6a21\u62df\u901a\u9053%d\u62e8\u53f7\u7ed9%s\u5931\u8d25' % (trunk_id, number)304 raise RuntimeError(log_info)305306 def send_dtmf(self, trunk_id, dtmf):307 """308 """309 phone = self._get_trunk_config_info(trunk_id)310 if phone.get_state() not in [_PHONESTATE.S_IN_CALL]:311 log_info = u'\u5f53\u524d\u72b6\u6001\u4e0d\u80fd\u8fdb\u884c\u8be5\u64cd\u4f5c\uff0c\u8bf7\u68c0\u67e5\u5173\u952e\u5b57\u4f7f\u7528\u6d41\u7a0b\u662f\u5426\u6b63\u786e'312 raise RuntimeError(log_info)313 self._clear_call_recv_data()314 if VOIP_FUN_OK == self.obj.send_data(trunk_id, dtmf):315 log_info = u'\u6a21\u62df\u901a\u9053%d\u53d1\u9001DTMF\u6570\u636e\u4e3a:%s' % (trunk_id, dtmf)316 self.user_info(log_info)317 else:318 log_info = u'\u6a21\u62df\u901a\u9053%d\u53d1\u9001DTMF\u6570\u636e\u5931\u8d25' % trunk_id319 raise RuntimeError(log_info)320321 def get_recv_dtmf(self, trunk_id):322 """323 """324 phone = self._get_trunk_config_info(trunk_id)325 if phone.get_state() not in [_PHONESTATE.S_IN_CALL]:326 log_info = u'\u5f53\u524d\u72b6\u6001\u4e0d\u80fd\u8fdb\u884c\u8be5\u64cd\u4f5c\uff0c\u8bf7\u68c0\u67e5\u5173\u952e\u5b57\u4f7f\u7528\u6d41\u7a0b\u662f\u5426\u6b63\u786e'327 raise RuntimeError(log_info)328 dtmf_recv = self.obj.get_recv_data(trunk_id)329 log_info = u'\u6a21\u62df\u901a\u9053%d\u63a5\u6536\u5230\u7684DTMF\u4e3a:%s' % (trunk_id, dtmf_recv)330 self.user_info(log_info)331 return dtmf_recv332333 def _clear_call_recv_data(self):334 """335 """336 for i in self.trunk_id_list:337 self.obj.clear_recv_data(i)338339 def _get_fax_info(self, info):340 """341 ASCII342 """343 ls = info.split(',')344 errcode = -1345 errstep = -1346 pages = -1347 for item in ls:348 if 'EvtErrCode' in item:349 errcode = filter(lambda x: x.isdigit(), item)350 if 'ErrStep' in item:351 errstep = filter(lambda x: x.isdigit(), item)352 if 'TotalPages' in item:353 pages = filter(lambda x: x.isdigit(), item)354355 return (int(errcode), int(errstep), int(pages))356357 def _get_code_meaning(self, errcode, errstep):358 """359 \xe8\x8e\xb7\xe5\x8f\x96code\xe5\x80\xbc\xe5\xaf\xb9\xe5\xba\x94\xe7\x9a\x84\xe6\x84\x8f\xe4\xb9\x89360 """361 code_info = u''362 step_info = u''363 errcode_dict = {}364 errcode_dict[0] = u'T30_COMPLETE_SUCCESS'365 errcode_dict[1] = u'T30_PRESTOP_BY_REMOTE'366 errcode_dict[2] = u'T30_PRESTOP_BY_LOCAL'367 errcode_dict[3] = u'T30_NOT_FAX_TERMINAL'368 errcode_dict[4] = u'T30_NOT_COMPATIBLE_FAX_TERMINAL'369 errcode_dict[5] = u'T30_BAD_SIGNAL_CONDITION'370 errcode_dict[6] = u'T30_PROTOCOL_ERROR'371 errcode_dict[7] = u'T30_PROTOCOL_ERROR_TIMEOUT'372 errcode_dict[8] = u'T30_FLOW_REQ_CLEAN_ERROR'373 errcode_dict[9] = u'T30_NOT_RECEIVE_MEDIA_DATA'374 code_info = errcode_dict.get(errcode, u'unkown')375 step_info = {}376 step_info[0] = u'T30_INIT'377 step_info[1] = u'T30_INIT_SEND_CED'378 step_info[2] = u'T30_SEND_CED'379 step_info[3] = u'T30_INIT_SEND_DIS'380 step_info[4] = u'T30_SEND_DIS'381 step_info[5] = u'T30_INIT_RECV_DCS'382 step_info[6] = u'T30_RECV_DCS'383 step_info[7] = u'T30_INIT_RECV_TCF'384 step_info[8] = u'T30_RECV_TCF'385 step_info[9] = u'T30_INIT_SEND_CFR'386 step_info[10] = u'T30_SEND_CFR'387 step_info[11] = u'T30_INIT_SEND_FTT'388 step_info[12] = u'T30_SEND_FTT'389 step_info[13] = u'T30_INIT_RECV_PAGE'390 step_info[14] = u'T30_RECV_PAGE'391 step_info[15] = u'T30_INIT_RECV_EOP'392 step_info[16] = u'T30_RECV_EOP'393 step_info[17] = u'T30_INIT_SEND_MCF'394 step_info[18] = u'T30_SEND_MCF'395 step_info[21] = u'T30_INIT_POSTPAGE_REQ'396 step_info[22] = u'T30_POSTPAGE_REQ'397 step_info[64] = u'T30_INIT_RECV_DIS'398 step_info[65] = u'T30_RECV_DIS'399 step_info[66] = u'T30_INIT_SEND_DCS'400 step_info[67] = u'T30_SEND_DCS'401 step_info[68] = u'T30_INIT_SEND_TCF'402 step_info[69] = u'T30_SEND_TCF'403 step_info[70] = u'T30_INIT_RECV_CFR'404 step_info[71] = u'T30_RECV_CFR'405 step_info[72] = u'T30_INIT_SEND_PAGE'406 step_info[73] = u'T30_SEND_PAGE'407 step_info[74] = u'T30_INIT_SEND_EOP'408 step_info[75] = u'T30_SEND_EOP'409 step_info[76] = u'T30_INIT_SEND_MPS'410 step_info[77] = u'T30_SEND_MPS'411 step_info[78] = u'T30_INIT_SEND_EOM'412 step_info[79] = u'T30_SEND_EOM'413 step_info[80] = u'T30_INIT_RECV_MCF'414 step_info[81] = u'T30_RECV_MCF'415 step_info[82] = u'T30_INIT_PREPAGE_REQ'416 step_info[83] = u'T30_PREPAGE_REQ'417 step_info[84] = u'T30_INIT_PAGE_REQ'418 step_info[85] = u'T30_PAGE_REQ'419 step_info[86] = u'T30_INIT_SEND_CNG'420 step_info[87] = u'T30_SEND_CNG'421 step_info[88] = u'T30_RECV_MCF_CLEAN'422 step_info[89] = u'T30_INIT_RECV_PREDIS'423 step_info[106] = u'T30_RECV_PREDIS'424 step_info[107] = u'T30_TIFF_CAHANGE_COMMAND'425 step_info[108] = u'T30_TIFF_CAHANGE_FINISH'426 step_info[110] = u'T30_PRE_SEND_PAGE'427 step_info = step_info.get(errstep, u'unkown')428 return (code_info, step_info)429430 def send_fax(self, trunk_id, sendfiles_list, bps_int, seconds, recordfile_send, recordfile_recv):431 """432 """433 phone = self._get_trunk_config_info(trunk_id)434 if phone.get_state() not in [_PHONESTATE.S_IN_CALL]:435 log_info = u'\u5f53\u524d\u72b6\u6001\u4e0d\u80fd\u8fdb\u884c\u8be5\u64cd\u4f5c\uff0c\u8bf7\u68c0\u67e5\u5173\u952e\u5b57\u4f7f\u7528\u6d41\u7a0b\u662f\u5426\u6b63\u786e'436 raise RuntimeError(log_info)437 if VOIP_FUN_OK != self.obj.send_fax_prepare(trunk_id):438 log_info = u'\u6a21\u62df\u901a\u9053%\u51c6\u5907\u4f20\u771f\u8bbe\u5907\u5931\u8d25' % trunk_id439 raise RuntimeError(log_info)440 firstfile = ''441 if isinstance(sendfiles_list, list):442 for index in range(len(sendfiles_list)):443 if index == 0:444 firstfile = sendfiles_list[index]445 log_info = u'\u6a21\u62df\u901a\u9053%d\u51c6\u5907\u53d1\u9001\u4f20\u771f\u6587\u4ef6%s, \u901f\u7387\u8bbe\u7f6e\u4e3a%d bps' % (trunk_id, firstfile, bps_int)446 self.user_info(log_info)447 continue448 if VOIP_FUN_OK == self.obj.set_fax_file(trunk_id, sendfiles_list[index]):449 log_info = u'\u6dfb\u52a0\u5f85\u4f20\u7684\u4f20\u771f\u6587\u4ef6%s\u6210\u529f' % sendfiles_list[index]450 self.user_info(log_info)451 else:452 log_info = u'\u6dfb\u52a0\u5f85\u4f20\u7684\u4f20\u771f\u6587\u4ef6%s\u5931\u8d25' % sendfiles_list[index]453 raise RuntimeError(log_info)454455 else:456 firstfile = sendfiles_list457 log_info = u'\u6a21\u62df\u901a\u9053%d\u51c6\u5907\u53d1\u9001\u4f20\u771f\u6587\u4ef6%s\uff0c\u901f\u7387\u8bbe\u7f6e\u4e3a%d bps' % (trunk_id, firstfile, bps_int)458 self.user_info(log_info)459 state, info = self.obj.send_fax(trunk_id, firstfile, bps_int, seconds, recordfile_send, recordfile_recv)460 ierrcode, ierrstep, ipages = self._get_fax_info(info)461 if VOIP_FUN_OK == state:462 log_info = u'\u6a21\u62df\u901a\u9053%d\u53d1\u9001\u4f20\u771f\u6210\u529f,\u53d1\u9001\u9875\u6570\u4e3a%d\u3002' % (trunk_id, ipages)463 self.user_info(log_info)464 else:465 log_info = u'\u6a21\u62df\u901a\u9053%d\u53d1\u9001\u4f20\u771f\u5931\u8d25\u3002' % trunk_id466 c, s = self._get_code_meaning(ierrcode, ierrstep)467 err_info = u'\u5931\u8d25\u4fe1\u606f\uff1a%s\uff0c\u5931\u8d25\u6b65\u9aa4\uff1a%s\uff0c\u4f20\u771f\u9875\u6570\uff1a%d' % (c, s, ipages)468 log_info += err_info469 raise RuntimeError(log_info)470 return ipages471472 def start_recv_fax(self, trunk_id, savefile, bps_int, recordfile_send, recordfile_recv):473 """474 """475 phone = self._get_trunk_config_info(trunk_id)476 if phone.get_state() not in [_PHONESTATE.S_IN_CALL]:477 log_info = u'\u5f53\u524d\u72b6\u6001\u4e0d\u80fd\u8fdb\u884c\u8be5\u64cd\u4f5c\uff0c\u8bf7\u68c0\u67e5\u5173\u952e\u5b57\u4f7f\u7528\u6d41\u7a0b\u662f\u5426\u6b63\u786e'478 raise RuntimeError(log_info)479 if VOIP_FUN_OK != self.obj.recv_fax_prepare(trunk_id):480 log_info = u'\u6a21\u62df\u901a\u9053%d\u51c6\u5907\u4f20\u771f\u8bbe\u5907\u5931\u8d25' % trunk_id481 raise RuntimeError(log_info)482 if VOIP_FUN_OK == self.obj.start_recv_fax(trunk_id, savefile, bps_int, recordfile_send, recordfile_recv):483 log_info = u'\u6a21\u62df\u901a\u9053%d\u51c6\u5907\u63a5\u6536\u4f20\u771f\uff0c\u901f\u7387\u8bbe\u7f6e\u4e3a%d bps, \u4f20\u771f\u6587\u4ef6\u5c06\u4fdd\u6301\u5230%s' % (trunk_id, bps_int, savefile)484 self.user_info(log_info)485 phone.set_state(_PHONESTATE.S_RECV_FAX_START)486 else:487 log_info = u'\u6a21\u62df\u901a\u9053%d\u51c6\u5907\u63a5\u6536\u4f20\u771f\u5931\u8d25' % trunk_id488 raise RuntimeError(log_info)489490 def get_recv_fax_result(self, trunk_id, seconds):491 """492 """493 phone = self._get_trunk_config_info(trunk_id)494 if phone.get_state() not in [_PHONESTATE.S_RECV_FAX_START]:495 log_info = u'\u5f53\u524d\u72b6\u6001\u4e0d\u80fd\u8fdb\u884c\u8be5\u64cd\u4f5c\uff0c\u8bf7\u68c0\u67e5\u5173\u952e\u5b57\u4f7f\u7528\u6d41\u7a0b\u662f\u5426\u6b63\u786e'496 raise RuntimeError(log_info)497 state, info = self.obj.get_recv_fax_result(trunk_id, seconds)498 ierrcode, ierrstep, ipages = self._get_fax_info(info)499 if VOIP_FUN_OK == state:500 log_info = u'\u6a21\u62df\u901a\u9053%d\u63a5\u6536\u4f20\u771f\u6210\u529f\uff0c\u63a5\u6536\u9875\u6570\u4e3a%d\u3002' % (trunk_id, ipages)501 self.user_info(log_info)502 phone.set_state(_PHONESTATE.S_IN_CALL)503 else:504 phone.set_state(_PHONESTATE.S_IN_CALL)505 log_info = u'\u6a21\u62df\u901a\u9053%d\u63a5\u6536\u4f20\u771f\u5931\u8d25\u3002' % trunk_id506 c, s = self._get_code_meaning(ierrcode, ierrstep)507 err_info = u'\u5931\u8d25\u4fe1\u606f\uff1a%s\uff0c\u5931\u8d25\u6b65\u9aa4\uff1a%s\uff0c\u4f20\u771f\u9875\u6570\uff1a%d' % (c, s, ipages)508 log_info += err_info509 raise RuntimeError(log_info)510 return ipages511512 def check_call_in(self, trunk_id, seconds):513 """514 """515 phone = self._get_trunk_config_info(trunk_id)516 if phone.get_state() not in [_PHONESTATE.S_NONE,517 _PHONESTATE.S_INIT,518 _PHONESTATE.S_ONHOOK,519 _PHONESTATE.S_CLEAR_CALL]:520 log_info = u'\u5f53\u524d\u72b6\u6001\u4e0d\u80fd\u8fdb\u884c\u8be5\u64cd\u4f5c\uff0c\u8bf7\u68c0\u67e5\u5173\u952e\u5b57\u4f7f\u7528\u6d41\u7a0b\u662f\u5426\u6b63\u786e'521 raise RuntimeError(log_info)522 if VOIP_FUN_OK == self.obj.check_call_in(trunk_id, seconds):523 log_info = u'\u6a21\u62df\u901a\u9053%d\u6709\u547c\u5165' % trunk_id524 self.user_info(log_info)525 phone.set_state(_PHONESTATE.S_CHECK_CALL_IN)526 else:527 log_info = u'\u6a21\u62df\u901a\u9053%d\u5728%d\u79d2\u5185\u65e0\u547c\u5165' % (trunk_id, seconds)528 self.user_info(log_info)529 raise RuntimeError(log_info)530531 def call_in_offhook(self, trunk_id):532 """533 """534 phone = self._get_trunk_config_info(trunk_id)535 if phone.get_state() not in [_PHONESTATE.S_CHECK_CALL_IN]:536 log_info = u'\u5f53\u524d\u72b6\u6001\u4e0d\u80fd\u8fdb\u884c\u8be5\u64cd\u4f5c\uff0c\u8bf7\u5148\u68c0\u67e5\u662f\u5426\u6709\u7535\u8bdd\u547c\u5165'537 raise RuntimeError(log_info)538 if VOIP_FUN_OK == self.obj.call_in_off_hook(trunk_id):539 log_info = u'\u6a21\u62df\u901a\u9053%d\u6458\u673a\u6210\u529f' % trunk_id540 self.user_info(log_info)541 phone.set_state(_PHONESTATE.S_IN_CALL)542 else:543 log_info = u'\u6a21\u62df\u901a\u9053%d\u6458\u673a\u5931\u8d25' % trunk_id544 raise RuntimeError(log_info)545546 def onhook(self, trunk_id):547 """548 """549 phone = self._get_trunk_config_info(trunk_id)550 if phone.get_state() in [_PHONESTATE.S_NONE,551 _PHONESTATE.S_INIT,552 _PHONESTATE.S_CHECK_CALL_IN,553 _PHONESTATE.S_ONHOOK,554 _PHONESTATE.S_CLEAR_CALL]:555 log_info = u'\u5f53\u524d\u72b6\u6001\u4e0d\u80fd\u8fdb\u884c\u8be5\u64cd\u4f5c\uff0c\u8bf7\u68c0\u67e5\u5173\u952e\u5b57\u4f7f\u7528\u6d41\u7a0b\u662f\u5426\u6b63\u786e'556 raise RuntimeError(log_info)557 if VOIP_FUN_OK == self.obj.on_hook(trunk_id):558 log_info = u'\u6a21\u62df\u901a\u9053%d\u6302\u673a\u6210\u529f' % trunk_id559 self.user_info(log_info)560 phone.set_state(_PHONESTATE.S_ONHOOK)561 else:562 log_info = u'\u6a21\u62df\u901a\u9053%d\u6302\u673a\u5931\u8d25' % trunk_id563 raise RuntimeError(log_info)564565 def hook_flash(self, trunk_id):566 """567 """568 phone = self._get_trunk_config_info(trunk_id)569 if phone.get_state() not in [_PHONESTATE.S_IN_CALL]:570 log_info = u'\u5f53\u524d\u72b6\u6001\u4e0d\u80fd\u8fdb\u884c\u8be5\u64cd\u4f5c\uff0c\u8bf7\u68c0\u67e5\u5173\u952e\u5b57\u4f7f\u7528\u6d41\u7a0b\u662f\u5426\u6b63\u786e'571 raise RuntimeError(log_info)572 if VOIP_FUN_OK == self.obj.set_flash(trunk_id):573 log_info = u'\u6a21\u62df\u901a\u9053%d\u62cd\u53c9\u6210\u529f' % trunk_id574 self.user_info(log_info)575 else:576 log_info = u'\u6a21\u62df\u901a\u9053%d\u62cd\u53c9\u5931\u8d25' % trunk_id577 raise RuntimeError(log_info)578579 def set_flash_time(self, times):580 """581 """582 if VOIP_FUN_OK == self.obj.set_flash_time(times):583 log_info = u'\u8bbe\u7f6e\u62cd\u53c9\u65f6\u95f4\u4e3a%d ms\u6210\u529f' % (times * 20)584 self.user_info(log_info)585 else:586 log_info = u'\u8bbe\u7f6e\u62cd\u53c9\u65f6\u95f4\u4e3a%d ms\u5931\u8d25' % (times * 20)587 raise RuntimeError(log_info)588589 def wait_some_tone(self, trunk_id, tone_name, tone_key, times):590 """591 """592 phone = self._get_trunk_config_info(trunk_id)593 if VOIP_FUN_OK == self.obj.wait_some_tone(trunk_id, tone_key, times):594 log_info = u'\u6a21\u62df\u901a\u9053%d\u68c0\u6d4b\u5230%s\u97f3' % (trunk_id, tone_name)595 self.user_info(log_info)596 return True597 else:598 log_info = u'\u6a21\u62df\u901a\u9053%d\u5728%d\u79d2\u5185\u672a\u68c0\u6d4b\u5230%s\u97f3' % (trunk_id, times, tone_name)599 self.user_info(log_info)600 return False601602 def update_tones_set(self):603 """604 """605 if VOIP_FUN_OK == self.obj.update_tones_set():606 log_info = u'\u66f4\u65b0\u5f85\u68c0\u6d4b\u97f3\u914d\u7f6e\u5230\u5e95\u5c42\u670d\u52a1\u6210\u529f'607 self.user_info(log_info)608 else:609 log_info = u'\u66f4\u65b0\u5f85\u68c0\u6d4b\u97f3\u914d\u7f6e\u5230\u5e95\u5c42\u670d\u52a1\u5931\u8d25'610 raise RuntimeError(log_info)611612 def start_record(self, trunk_id, savefile):613 """614 """615 if VOIP_FUN_OK == self.obj.start_record(trunk_id, savefile):616 log_info = u'\u6a21\u62df\u901a\u9053%d \u542f\u52a8\u5f55\u97f3\u6210\u529f\uff0c\u4fdd\u5b58\u8def\u5f84\u4e3a %s' % (trunk_id, savefile)617 self.user_info(log_info)618 else:619 log_info = u'\u6a21\u62df\u901a\u9053%d \u542f\u52a8\u5f55\u97f3\u5931\u8d25' % trunk_id620 self.user_info(log_info)621622 def stop_record(self, trunk_id):623 """624 """625 if VOIP_FUN_OK == self.obj.stop_record(trunk_id):626 log_info = u'\u6a21\u62df\u901a\u9053%d \u505c\u6b62\u5f55\u97f3\u6210\u529f' % trunk_id627 self.user_info(log_info)628 else:629 log_info = u'\u6a21\u62df\u901a\u9053%d \u505c\u6b62\u5f55\u97f3\u5931\u8d25' % trunk_id630 self.user_info(log_info)631632633634635def Test():636 v = ATTVoip(2)637638639if __name__ == '__main__': ...

Full Screen

Full Screen

request.py

Source:request.py Github

copy

Full Screen

...15 try:16 resp = resp.json()17 return resp['data']['userAuth']['reserve']['reserve'] is not None18 except ValueError as value_exc:19 log_info('\n' + traceback.format_exc())20 log_info("have_seat时无json")21 log_info(resp.content)22 raise value_exc23 except Exception as e:24 log_info('\n' + traceback.format_exc())25 log_info("have_seat时发生其他异常")26 raise e27def is_sign(cookie: str) -> bool:28 """29 是否签到30 Args:31 cookie: headers中的cookie32 Returns:33 true为已经签到34 """35 task = get_task(cookie)36 while task is None:37 task = get_task(cookie)38 return task['status'] == 239class Activity(Enum):40 headers = {"Host": "wechat.v2.traceint.com", "Connection": "keep-alive", "Origin": "https://web.traceint.com",41 "User-Agent": "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36 NetType/WIFI MicroMessenger/7.0.20.1781(0x6700143B) WindowsWechat(0x63040026)",42 "Content-Type": "application/json", "Accept": "*/*", "Sec-Fetch-Site": "same-site",43 "Sec-Fetch-Mode": "cors", "Sec-Fetch-Dest": "empty",44 "Referer": "https://web.traceint.com/web/index.html", "Accept-Encoding": "gzip, deflate, br",45 "Accept-Language": "zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7"}46 captcha = {"operationName": "getStep0",47 "query": "query getStep0 {\n userAuth {\n prereserve {\n getNum\n captcha {\n code\n data\n }\n }\n }\n}"}48 getStep = {"operationName": "getStep",49 "query": "query getStep {\n userAuth {\n prereserve {\n getStep\n queeUrl\n successUrl\n endTime\n }\n }\n}"}50 prereserveLibLayout = {"operationName": "libLayout",51 "query": "query libLayout($libId: Int!) {\n userAuth {\n prereserve {\n libLayout(libId: $libId) {\n max_x\n max_y\n seats_booking\n seats_total\n seats_used\n seats {\n key\n name\n seat_status\n status\n type\n x\n y\n }\n }\n }\n }\n}",52 "variables": {"libId": None}}53 index = {"operationName": "index",54 "query": "query index($pos: String!, $param: [hash]) {\n userAuth {\n oftenseat {\n list {\n id\n info\n lib_id\n seat_key\n status\n }\n }\n message {\n new(from: \"system\") {\n has\n from_user\n title\n num\n }\n indexMsg {\n message_id\n title\n content\n isread\n isused\n from_user\n create_time\n }\n }\n reserve {\n reserve {\n token\n status\n user_id\n user_nick\n sch_name\n lib_id\n lib_name\n lib_floor\n seat_key\n seat_name\n date\n exp_date\n exp_date_str\n validate_date\n hold_date\n diff\n diff_str\n mark_source\n isRecordUser\n isChooseSeat\n isRecord\n mistakeNum\n openTime\n threshold\n daynum\n mistakeNum\n closeTime\n timerange\n forbidQrValid\n renewTimeNext\n forbidRenewTime\n forbidWechatCancle\n }\n getSToken\n }\n currentUser {\n user_id\n user_nick\n user_mobile\n user_sex\n user_sch_id\n user_sch\n user_last_login\n user_avatar(size: MIDDLE)\n user_adate\n user_student_no\n user_student_name\n area_name\n user_deny {\n deny_deadline\n }\n sch {\n sch_id\n sch_name\n activityUrl\n isShowCommon\n isBusy\n }\n }\n }\n ad(pos: $pos, param: $param) {\n name\n pic\n url\n }\n}",55 "variables": {"pos": "App-首页"}}56 verify_captcha = {"operationName": "setStep1",57 "query": "mutation setStep1($captcha: String!, $captchaCode: String!) {\n userAuth {\n prereserve {\n verifyCaptcha(captcha: $captcha, code: $captchaCode)\n setStep1\n }\n }\n}",58 "variables": {"captcha": "wvsb", "captchaCode": "ba315bdcb30fd7f55cd8fe1d443d4024"}}59 save = {"operationName": "save",60 "query": "mutation save($key: String!, $libid: Int!, $captchaCode: String, $captcha: String) {\n userAuth {\n prereserve {\n save(key: $key, libId: $libid, captcha: $captcha, captchaCode: $captchaCode)\n }\n }\n}",61 "variables": {62 "key": "19,75",63 "libid": 758,64 "captchaCode": "",65 "captcha": ""66 }}67 libLayout = {68 "operationName": "libLayout",69 "query": "query libLayout($libId: Int, $libType: Int) {\n userAuth {\n reserve {\n libs(libType: $libType, libId: $libId) {\n lib_id\n is_open\n lib_floor\n lib_name\n lib_type\n lib_layout {\n seats_total\n seats_booking\n seats_used\n max_x\n max_y\n seats {\n x\n y\n key\n type\n name\n seat_status\n status\n }\n }\n }\n }\n }\n}",70 "variables": {71 "libId": 76572 }73 }74 reserveSeat = {75 "operationName": "reserveSeat",76 "query": "mutation reserveSeat($libId: Int!, $seatKey: String!, $captchaCode: String, $captcha: String!) {\n userAuth {\n reserve {\n reserveSeat(\n libId: $libId\n seatKey: $seatKey\n captchaCode: $captchaCode\n captcha: $captcha\n )\n }\n }\n}",77 "variables": {78 "seatKey": "27,74",79 "libId": 765,80 "captchaCode": "",81 "captcha": ""82 }83 }84 reserveCancle = {85 "operationName": "pass_reserveCancle",86 "query": "mutation pass_reserveCancle($sToken: String!) {\n userAuth {\n reserve {\n pass_reserveCancle(sToken: $sToken) {\n timerange\n img\n hours\n mins\n per\n }\n }\n }\n}",87 "variables": {88 "sToken": "c4902bd615587a0f73d24573d083d24f09f10aa6"89 }90 }91 getList = {92 "operationName": "getList",93 "query": "query getList {\n userAuth {\n credit {\n tasks {\n id\n task_id\n task_name\n task_info\n task_url\n credit_num\n contents\n conditions\n task_type\n status\n }\n staticTasks {\n id\n name\n task_type_name\n credit_num\n contents\n button\n }\n }\n }\n}"94 }95 done = {96 "operationName": "done",97 "query": "mutation done($user_task_id: Int!) {\n userAuth {\n credit {\n done(user_task_id: $user_task_id)\n }\n }\n}",98 "variables": {99 "user_task_id": 39265747100 }101 }102def post(post_para: dict, headers: dict) -> requests.Response:103 """对图书馆接口发送post请求104 Args:105 post_para (list(json)): 要发送的json数据106 headers (dict): headers参数107 """108 url = 'https://wechat.v2.traceint.com/index.php/graphql/'109 resp = requests.request("post", url, json=post_para, headers=headers)110 return resp111def get_para_and_headers(activity: Activity, cookie: str) -> tuple:112 """获取该项活动的json参数和headers113 Args:114 activity (Activity): 活动enum115 cookie (str): 传入cookie116 Returns:117 tuple: 返回json参数和headers组成的元组118 """119 headers = Activity.headers.value120 headers['Cookie'] = cookie121 return activity.value, headers122def get_resp(activity: Activity, cookie: str) -> requests.Response:123 """通过传入的活动获取response124 Args:125 activity (Activity): 活动enum126 cookie (str): 传入cookie127 Returns:128 requests.Response: 返回的response129 """130 para, headers = get_para_and_headers(activity, cookie)131 return post(para, headers)132def get_step_response(cookie: str) -> requests.Response:133 """获取getStep的响应134 Args:135 cookie (str): headers中的cookie136 Returns:137 requests.Response: 返回响应138 """139 return get_resp(Activity.getStep, cookie)140def get_step(cookie: str) -> int:141 """获取getStep142 Args:143 cookie (str): headers中的cookie144 Raises:145 value_exc: 无json146 key_exc: json无数据147 type_exc: json中含有空对象148 e: 其他异常149 Returns:150 int: getStep151 """152 resp = get_step_response(cookie)153 try:154 resp = resp.json()155 result = resp['data']['userAuth']['prereserve']['getStep']156 except ValueError as value_exc:157 log_info('\n' + traceback.format_exc())158 log_info("get_step时无json")159 log_info(resp.content)160 raise value_exc161 except KeyError as key_exc:162 log_info('\n' + traceback.format_exc())163 log_info("get_step时json中无code及网址")164 log_info(_json=resp)165 raise key_exc166 except TypeError as type_exc:167 log_info('\n' + traceback.format_exc())168 log_info('get_step时json中有None对象,疑似cookie过期')169 log_info(_json=resp)170 raise type_exc171 except Exception as e:172 log_info('\n' + traceback.format_exc())173 log_info("get_step时发生其他异常")174 raise e175 return result176def get_prereserve_libLayout(cookie: str, lib_id: int) -> list:177 """通过libId获取该层图书馆的座位信息178 Args:179 cookie (str): headers中的cookie180 lib_id (int): 图书馆楼层id181 Raises:182 value_exc: 无json183 key_exc: json无数据184 e: 其他异常185 Returns:186 list: 座位信息list187 """188 para, headers = get_para_and_headers(Activity.prereserveLibLayout, cookie)189 para['variables']['libId'] = lib_id190 resp = post(para, headers)191 try:192 resp = resp.json()193 result = resp["data"]["userAuth"]["prereserve"]["libLayout"]["seats"]194 except ValueError as value_exc:195 log_info('\n' + traceback.format_exc())196 log_info("get_prereserve_libLayout时无json")197 log_info(resp.content)198 raise value_exc199 except KeyError as key_exc:200 log_info('\n' + traceback.format_exc())201 log_info("get_prereserve_libLayout时无json无数据")202 log_info(resp)203 raise key_exc204 except Exception as e:205 log_info('\n' + traceback.format_exc())206 log_info("get_prereserve_libLayout时发生其他异常")207 raise e208 return [seat for seat in result if seat_exist(seat)]209def verify_cookie(cookie: str) -> bool:210 """验证cookie有效性211 Args:212 cookie (str): headers中的cookie参数213 Raises:214 e: 响应无json215 Returns:216 bool: true则cookie有效217 """218 resp = get_resp(Activity.index, cookie)219 try:220 resp = resp.json()221 except ValueError as value_exc:222 log_info('\n' + traceback.format_exc())223 log_info("verify_cookie时无json")224 log_info(resp.content)225 raise value_exc226 except Exception as e:227 log_info('\n' + traceback.format_exc())228 log_info("verify_cookie时发生其他异常")229 raise e230 return 'errors' not in resp231def get_SToken(cookie: str) -> str:232 """获取退座所需要的SToken233 Args:234 cookie (str): headers中的cookie参数235 Raises:236 key_exc: json无对应键值237 value_exc: 响应无json238 e: 其他异常239 Returns:240 str: 退座所需要的SToken241 """242 resp = get_resp(Activity.index, cookie)243 try:244 resp = resp.json()245 result = resp['data']['userAuth']['reserve']['getSToken']246 except KeyError as key_exc:247 log_info('\n' + traceback.format_exc())248 log_info("get_SToken时无所需数据")249 log_info(_json=resp)250 raise key_exc251 except ValueError as value_exc:252 log_info('\n' + traceback.format_exc())253 log_info("get_SToken时无json")254 log_info(resp.content)255 raise value_exc256 except Exception as e:257 log_info('\n' + traceback.format_exc())258 log_info("get_SToken时发生其他异常")259 raise e260 return result261def get_ws_url(cookie: str) -> str:262 """获取websocket链接地址(通常在程序崩溃时重新运行时获取)263 Args:264 cookie (str): headers中的cookie参数265 Raises:266 value_exc: 无json267 key_exc: json无数据268 e: 其他异常269 Returns:270 str: websocket地址271 """272 resp = get_step_response(cookie)273 try:274 resp = resp.json()275 result = resp['data']['userAuth']['prereserve']['queeUrl']276 except ValueError as value_exc:277 log_info('\n' + traceback.format_exc())278 log_info("get_ws_url时无json")279 log_info(resp.content)280 raise value_exc281 except KeyError as key_exc:282 log_info('\n' + traceback.format_exc())283 log_info("get_ws_url时json中无所需数据")284 log_info(_json=resp)285 raise key_exc286 except Exception as e:287 log_info('\n' + traceback.format_exc())288 log_info("get_ws_url时发生其他错误")289 raise e290 return result291def get_queue_url(cookie: str) -> str:292 """获取排队的get连接293 Args:294 cookie (str): headers中的cookie参数295 Raises:296 value_exc: 无json297 key_exc: json无数据298 e: 其他异常299 Returns:300 str: 排队的get连接301 """302 resp = get_step_response(cookie)303 try:304 resp = resp.json()305 result = resp['data']['userAuth']['prereserve']['successUrl']306 except ValueError as value_exc:307 log_info('\n' + traceback.format_exc())308 log_info("get_queue_url时无json")309 log_info(resp.content)310 raise value_exc311 except KeyError as key_exc:312 log_info('\n' + traceback.format_exc())313 log_info("get_queue_url时json中无所需数据")314 log_info(_json=resp)315 raise key_exc316 except Exception as e:317 log_info('\n' + traceback.format_exc())318 log_info("get_queue_url时发生其他异常")319 raise e320 return result321def get_captcha_code_website(cookie: str) -> tuple:322 """获取验证码的code和网址323 Args:324 cookie (str): headers的cookie325 Raises:326 value_exc: 无json327 key_exc: json数据328 e: 其他异常329 Returns:330 tuple: 返回元组,第一个元素为code(后面发送验证请求会用到),第二个元素为网址331 """332 resp = get_resp(Activity.captcha, cookie)333 try:334 resp = resp.json()335 result = (resp['data']['userAuth']['prereserve']['captcha']['code'],336 resp['data']['userAuth']['prereserve']['captcha']['data'])337 except ValueError as value_exc:338 log_info('\n' + traceback.format_exc())339 log_info("get_captcha_code_website时无json")340 log_info(resp.content)341 raise value_exc342 except KeyError as key_exc:343 log_info('\n' + traceback.format_exc())344 log_info("get_captcha_code_website时json中无code及网址")345 log_info(_json=resp)346 raise key_exc347 except Exception as e:348 log_info('\n' + traceback.format_exc())349 log_info("get_captcha_code_website时发生其他异常")350 raise e351 return result352def get_captcha_image(website: str) -> bytes:353 """根据网址获取验证码图片二进制信息354 Args:355 website (str): 验证码网址356 Raises:357 Exception: 图片地址404358 Returns:359 bytes: 图片二进制信息360 """361 resp = requests.get(website)362 if resp.status_code != 404:363 return resp.content364 else:365 log_info('图片地址404')366 raise Exception("get_captcha_image时404 Not Found")367def verify_captcha(cookie: str, captcha: str, code: str) -> tuple:368 """验证验证码是否正确,返回结果以及websocket的url369 Args:370 cookie (str): headers的cookie371 captcha (str): 识别出来的验证码372 code (str): 验证码的code(前面post请求得到的)373 Raises:374 value_exc: 无json375 key_exc: json无数据376 e: 其他异常377 Returns:378 tuple: 第一个元素为bool型,验证是否成功;第二个元素为str,websocket的url379 """380 para, headers = get_para_and_headers(Activity.verify_captcha, cookie)381 para['variables']['captcha'] = captcha382 para['variables']['captchaCode'] = code383 resp = post(para, headers)384 ws_url = None385 try:386 resp = resp.json()387 verify_result = resp['data']['userAuth']['prereserve']['verifyCaptcha']388 if verify_result:389 ws_url = resp['data']['userAuth']['prereserve']['setStep1']390 except ValueError as value_exc:391 log_info('\n' + traceback.format_exc())392 log_info("verify_captcha时无json")393 log_info(resp.content)394 raise value_exc395 except KeyError as key_exc:396 log_info('\n' + traceback.format_exc())397 log_info("verify_captcha时json中无code及网址")398 log_info(_json=resp)399 raise key_exc400 except Exception as e:401 log_info('\n' + traceback.format_exc())402 log_info("verify_captcha时发生其他异常")403 raise e404 return verify_result, ws_url405def save(cookie: str, key: str, lib_id: int) -> bool:406 """407 预定座位408 Args:409 cookie: headers中的cookie410 key: 座位key,seat字典中获取411 lib_id: 楼层id412 Returns:413 true为预定成功414 """415 para, headers = get_para_and_headers(Activity.save, cookie)416 para["variables"]["key"] = key417 para['variables']['libid'] = lib_id418 resp = post(para, headers)419 try:420 resp = resp.json()421 # 如果服务器排队有延迟则再预定一次422 # TODO 测试延迟423 if queue_delay(resp):424 log_info('save时服务器有延迟,即将再试一次')425 log_info(_json=resp)426 resp = post(para, headers)427 resp = resp.json()428 if 'errors' in resp:429 log_info('save时json数据内含错误或预定失败')430 log_info(_json=resp)431 return False432 return resp["data"]["userAuth"]["prereserve"]["save"]433 except ValueError as value_exc:434 log_info('\n' + traceback.format_exc())435 log_info("save时无json")436 log_info(resp.content)437 raise value_exc438 except KeyError as key_exc:439 log_info('\n' + traceback.format_exc())440 log_info("save时json无对应数据")441 log_info(_json=resp)442 raise key_exc443 except Exception as e:444 log_info('\n' + traceback.format_exc())445 log_info("save时发生其他异常")446 log_info(resp)447 log_info(resp.content)448 raise e449def get_libLayout(cookie: str, lib_id: int) -> List[dict]:450 """451 获取捡漏座位信息452 Args:453 cookie: headers中的cookie454 lib_id: 图书馆楼层id455 Returns:456 List[dict]: 座位信息list457 """458 para, headers = get_para_and_headers(Activity.libLayout, cookie)459 para['variables']['libId'] = lib_id460 resp = post(para, headers)461 try:462 resp = resp.json()463 result = resp["data"]["userAuth"]["reserve"]["libs"][0]["lib_layout"]["seats"]464 except ValueError as value_exc:465 log_info('\n' + traceback.format_exc())466 log_info("get_libLayout时无json")467 log_info(resp.content)468 raise value_exc469 except KeyError as key_exc:470 log_info('\n' + traceback.format_exc())471 log_info("get_libLayout时无json无数据")472 log_info(resp)473 raise key_exc474 except Exception as e:475 log_info('\n' + traceback.format_exc())476 log_info("get_libLayout时发生其他异常")477 raise e478 return [seat for seat in result if seat_exist(seat)]479def reserveSeat(cookie: str, seat_key: str, lib_id: int) -> bool:480 """481 预定当日座位482 Args:483 cookie: headers中的cookie484 seat_key: 座位id,seat信息中485 lib_id: 楼层id486 Returns:487 true为预定成功488 """489 para, headers = get_para_and_headers(Activity.reserveSeat, cookie)490 para["variables"]["seatKey"] = seat_key491 para['variables']['libId'] = lib_id492 resp = post(para, headers)493 try:494 resp = resp.json()495 if 'errors' in resp:496 log_info('reserveSeat时json数据内含错误或预定失败')497 log_info(_json=resp)498 return False499 return resp["data"]["userAuth"]["reserve"]["reserveSeat"]500 except ValueError as value_exc:501 log_info('\n' + traceback.format_exc())502 log_info("reserveSeat时无json")503 log_info(resp.content)504 raise value_exc505 except KeyError as key_exc:506 log_info('\n' + traceback.format_exc())507 log_info("reserveSeat时json无对应数据")508 log_info(_json=resp)509 raise key_exc510 except Exception as e:511 log_info('\n' + traceback.format_exc())512 log_info("reserveSeat时发生其他异常")513 log_info(resp)514 log_info(resp.content)515 raise e516def reserve_floor(cookie: str, floor: int, reverse: bool) -> str:517 """518 遍历一整层楼的座位,预定空座位519 Args:520 cookie: headers中的cookie521 floor: 楼层522 reverse: 是否倒序523 Returns:524 成功则返回座位号,否则返回空字符串525 """526 lib_id = get_lib_id(floor)527 seats = get_libLayout(cookie, lib_id)528 seats.sort(key=lambda s: int(s['name']), reverse=reverse)529 log_info(f'开始遍历{floor}楼')530 for seat in seats:531 if seat["seat_status"] == 1:532 log_info(f"开始预定{seat['name']}号")533 try:534 if reserveSeat(cookie, seat['key'], lib_id):535 log_info(f"预定成功,座位为{seat['name']}号")536 return seat['name']537 except Exception:538 log_info(f'预定{seat["name"]}时发生错误')539 return ''540 return ''541# TODO doc注释542# TODO 完善函数543# TODO 未拆封微信浏览器之前无法完善544def renew_cookie(cookie: str) -> str:545 if verify_cookie(cookie):546 log('当前验证码有效,无需更新')547 return cookie548 pass549 return cookie550def queue_init(cookie: str) -> tuple:551 """初始化排队并获取need_captcha, need_queue, ws_url, queue_url552 Args:553 cookie (str): header参数cookie554 Raises:555 value_exc: 无json556 key_exc: json无数据557 e: 其他异常558 Returns:559 tuple: 按顺序分别为need_captcha, need_queue, ws_url, queue_url560 """561 resp = get_step_response(cookie)562 try:563 resp = resp.json()564 get_step = resp['data']['userAuth']['prereserve']['getStep']565 ws_url = resp['data']['userAuth']['prereserve']['queeUrl']566 queue_url = resp['data']['userAuth']['prereserve']['successUrl']567 if get_step == 0:568 need_captcha = True569 else:570 need_captcha = False571 if get_step == 1:572 need_queue = True573 else:574 need_queue = False575 except ValueError as value_exc:576 log_info('\n' + traceback.format_exc())577 log_info("queue_init时无json")578 log_info(resp.content)579 raise value_exc580 except KeyError as key_exc:581 log_info('\n' + traceback.format_exc())582 log_info("queue_init时无json无数据")583 log_info(resp)584 raise key_exc585 except Exception as e:586 log_info('\n' + traceback.format_exc())587 log_info("queue_init时发生其他异常")588 raise e589 return need_captcha, need_queue, ws_url, queue_url590def get_task_resp(cookie: str) -> requests.Response:591 """592 获取签到任务response593 Args:594 cookie: headers中的cookie595 Returns:596 requests.Response: 返回task响应597 """598 return get_resp(Activity.getList, cookie)599def get_task(cookie: str) -> Optional[dict]:600 """601 获取签到任务602 Args:603 cookie: headers中的cookie604 Returns:605 dict: 返回签到任务字典606 """607 resp = get_task_resp(cookie)608 try:609 resp = resp.json()610 tasks = resp['data']['userAuth']['credit']['tasks']611 if tasks is not None:612 return tasks[0]613 else:614 log_info('get_task时tasks体为空')615 log_info(f'tasks:{tasks}')616 return None617 except ValueError as value_exc:618 log_info(f'\n{traceback.format_exc()}')619 log_info('get_task时无json')620 log_info(resp.content)621 raise value_exc622 except KeyError as key_exec:623 log_info(f'\n{traceback.format_exc()}')624 log_info('get_task时json无数据')625 log_info(resp)626 raise key_exec627 except Exception as exc:628 log_info(f'\n{traceback.format_exc()}')629 log_info('get_task时发生其他错误')630 raise exc631def get_task_id(cookie: str) -> int:632 """633 获取签到任务id634 Args:635 cookie: headers中的cookie636 Returns:637 int: 签到任务id638 """639 task = get_task(cookie)640 while task is None:641 task = get_task(cookie)...

Full Screen

Full Screen

import_cghub_manifest.py

Source:import_cghub_manifest.py Github

copy

Full Screen

...109 sampleIDs[index + len(fields[:-3])][field] = sampleIDs[index + len(fields[:-3])].setdefault(field, 0) + 1110 except:111 util.log_exception(log, 'problem splitting %s(%s:%s)' % (record.legacy_sample_id, index, field))112 113 util.log_info(log, '\nStates')114 count = 0115 for state, value in states.iteritems():116 if count < 15:117 count += 1118 util.log_info(log, '%s: %s' % (state, value))119 else:120 util.log_info(log, '\t(of %s)' % (len(states.keys())))121 break122 util.log_info(log, '')123 124 util.log_info(log, 'Centers')125 count = 0126 for center, value in centers.iteritems():127 if count < 15:128 count += 1129 util.log_info(log, '%s: %s' % (center, value))130 else:131 util.log_info(log, ' (of %s)' % (len(centers.keys())))132 break133 util.log_info(log, '')134 135 util.log_info(log, 'Studies')136 count = 0137 for studie, value in studies.iteritems():138 if count < 15:139 count += 1140 util.log_info(log, '%s: %s' % (studie, value))141 else:142 util.log_info(log, '(of %s)' % (len(studies.keys())))143 break144 util.log_info(log, '')145 146 if verbose:147 util.log_info(log, 'Sample ids:')148 count = 0149 for sampleMap in sampleIDs:150 util.log_info(log, 'next part:')151 for sampleID, value in sampleMap.iteritems():152 if count < 15:153 count += 1154 util.log_info(log, '%s: %s' % (sampleID, value))155 else:156 util.log_info(log, '(of %s)' % (len(sampleMap.keys())))157 break158 util.log_info(log, '')159 count = 0160 161 util.log_info(log, 'Diseases:')162 count = 0163 for disease, value in diseases.iteritems():164 count += 1165 util.log_info(log, '%s: %s' % (disease, value))166 util.log_info(log, '')167 168 util.log_info(log, 'Analyte codes:')169 count = 0170 for analyte_code, value in analyte_codes.iteritems():171 if count < 15:172 count += 1173 util.log_info(log, '%s: %s' % (analyte_code, value))174 else:175 util.log_info(log, '(of %s)' % (len(analyte_codes.keys())))176 break177 util.log_info(log, '')178 179 util.log_info(log, 'Sample types')180 count = 0181 for sample_type, value in sample_types.iteritems():182 if count < 15:183 count += 1184 util.log_info(log, '%s: %s' % (sample_type, value))185 else:186 util.log_info(log, '(of %s)' % (len(sample_types.keys())))187 break188 util.log_info(log, '')189 190 util.log_info(log, 'Strategies:')191 count = 0192 for strategie, value in strategies.iteritems():193 if count < 15:194 count += 1195 util.log_info(log, '%s: %s' % (strategie, value))196 else:197 util.log_info(log, '(of %s)' % (len(strategies.keys())))198 break199 util.log_info(log, '')200 201 util.log_info(log, 'Platforms:')202 count = 0203 for platform, value in platforms.iteritems():204 if count < 15:205 count += 1206 util.log_info(log, '%s: %s' % (platform, value))207 else:208 util.log_info(log, '(of %s)' % (len(platforms.keys())))209 break210 util.log_info(log, '')211 212 util.log_info(log, 'Reference Assembles:')213 count = 0214 for refassem, value in refassems.iteritems():215 if count < 15:216 count += 1217 util.log_info(log, '%s: %s' % (refassem, value))218 else:219 util.log_info(log, '(of %s)' % (len(refassems.keys())))220 break221 util.log_info(log, '')222 223 util.log_info(log, 'Models:')224 count = 0225 for model, value in models.iteritems():226 if count < 15:227 count += 1228 util.log_info(log, '%s: %s' % (model, value))229 else:230 util.log_info(log, '(of %s)' % (len(models.keys())))231 break232 233 util.log_info(log, '')234 util.log_info(log, '\n\t\tmax: %s\n\t\tmin: %s' % (minmaxsize['max'].write(), minmaxsize['min'].write()))235236def main(platform, type_uri = 'detail', log = None, removedups = False, limit = -1, verbose = False, print_response = False):237 util.log_info(log, 'begin reading cghub archive')238 filename2cghubRecords = {}239 minmaxsize = {'min': CGHubFileInfo('', 500000000000, ''), 'max': CGHubFileInfo('', 1, '')}240 try:241# archives = util.getURLData(manifest_uri, 'latest_manifest', log)242 response = urllib.urlopen(manifest_uri)243 archives = response.read()244245 lines = archives.split('\n')246 util.log_info(log, '\tarchive size is %s with %s lines' % (len(archives), len(lines)))247 util.log_info(log, '\n\t' + '\n\t'.join(lines[:10]))248 except Exception as e:249 util.log_exception(log, 'problem fetching latest_manifest: %s')250 raise e251 252 headers = lines[0].split('\t')253 column_index2header = {}254 for index, header in enumerate(headers):255 if header in header2record_index.keys():256 column_index2header[index] = header257 258 count = 0259 dupcount = 0260 for line in lines[1:]:261 if not line:262 continue263 if 0 == count % 4096:264 util.log_info(log, 'processed %s records' % (count))265 count += 1266 fields = line.split('\t')267 header2record = {}268 try:269 for index in column_index2header.keys():270 header2record[header2record_index[column_index2header[index]]] = fields[index]271 except Exception as e:272 util.log_info(log, 'problem with parsing line(%s): %s' % (count, line))273 if platform not in header2record[CGHubRecordInfo.study_index]:274 continue275 header2record.update(index2none)276 record = CGHubRecordInfo(header2record)277 filename = header2record[CGHubRecordInfo.bamFilename_index]278 if removedups and filename in filename2cghubRecords:279 if 'Live' == header2record[CGHubRecordInfo.state_index]:280 dupcount += 1281 # check the dates and keep the latest282 currentdate = createDateTime(filename2cghubRecords[filename].upload_date)283 newdate = createDateTime(record.upload_date)284 if currentdate < newdate:285 filename2cghubRecords[filename] = record286 else:287 filename2cghubRecords[filename] = record288 if 'Live' == record.state:289 if minmaxsize['min'].filesize > record.files['bam'].filesize and record.files['bam'].filesize:290 minmaxsize['min'] = record.files['bam']291 if minmaxsize['max'].filesize < record.files['bam'].filesize:292 minmaxsize['max'] = record.files['bam']293 if not record.files['bam'].filesize:294 util.log_info(log, 'no file size: %s--%s' % (record.write(), record.files['bam'].write()))295296 statistics(log, filename2cghubRecords, minmaxsize, verbose)297 util.log_info(log, 'finished reading cghub archive. %s total records, %s duplicates' % (count, dupcount))298 return filename2cghubRecords.values(), minmaxsize, archives299 300if __name__ == '__main__': ...

Full Screen

Full Screen

logshim.repy

Source:logshim.repy Github

copy

Full Screen

1#!python2"""3<Program Name>4 logshim.repy5<Author>6 Danny Y. Huang, yh1@cs.williams.edu7<Date Started>8 April 11, 20119<Purpose> Logs all data being passed through the shim. Helps debugging. As a10 function enters, we log all the parameters. Before it returns, we log the11 return value in a line that starts with " > ". Each log entry contains the12 epoch time and the string representation of the shim stack below.13"""14logshim_locks = {}15class LogShim(BaseShim):16 17 def __init__(self, shim_stack = ShimStack(), optional_args = None):18 """19 Define the log file name if defined.20 """21 self._LOG_FILE_NAME = 'debug.log'22 23 if optional_args:24 # If option is provided, use it as the log name.25 assert(isinstance(optional_args[0], str)), "Optional arg provided must be string"26 self._LOG_FILE_NAME = optional_args[0]27 # Prevents current write.28 if self._LOG_FILE_NAME not in logshim_locks.keys():29 logshim_locks[self._LOG_FILE_NAME] = createlock()30 BaseShim.__init__(self, shim_stack, optional_args) 31 def _log(self, logstr):32 """ 33 Writes logstr to the log file. First line states the total elapsed time and34 the contents of the shim stack. The second line contains the log data.35 """36 logshim_locks[self._LOG_FILE_NAME].acquire(True) 37 try:38 file_obj = openfile(self._LOG_FILE_NAME, True)39 # Record the epoch time, accurate up to two decimal places, in seconds.40 time_str = 't = %.2f, shim stack = "' % getruntime()41 42 # Write data into the log file43 data_to_write = time_str + self.get_advertisement_string() + '"\n' + str(logstr) + '\n\n'44 file_obj.writeat(data_to_write, self._find_file_location(file_obj)) 45 46 file_obj.close()47 finally:48 logshim_locks[self._LOG_FILE_NAME].release()49 def _find_file_location(self, file_obj):50 """51 Find out where to write in a file. Returns the offset of the file.52 """53 min = 054 max = 10 * 1024 * 1024 * 1024 # Assume that the max file size is 1 GB55 while min <= max :56 mid = (min + max) / 257 try:58 file_obj.readat(1, mid)59 except SeekPastEndOfFileError:60 # If we got an error that means we are seeking past file size,61 # so the file size is smaller then mid.62 max = mid - 163 else:64 # If we did not get an error, then the file is bigger then size mid.65 min = mid + 166 # We may get out of the loop in two different cases, and we have to check67 # if we found the right mid, or just one over.68 try:69 file_obj.readat(1, mid)70 except SeekPastEndOfFileError:71 return mid - 172 else:73 return mid74 def _abbrev(self, input_str):75 """76 Abbreviates the input string. Returns the first 100 bytes, followed by77 elipses, and then the last 100 bytes.78 """79 # TODO abbreviation disabled.80 #return input_str81 length = len(input_str)82 if length < 100:83 return input_str84 else:85 return input_str[0:50] + ' ... (' + str(length - 100) + ' bytes omitted) ... ' + input_str[length-500 : ]86 def sendmessage(self, destip, destport, message, localip, localport):87 log_info = ('sendmessage, destip = %s, destport = %s, localip = %s, localport = %s, message = %s' 88 % (destip, destport, localip, localport, message))89 self._log(log_info)90 try:91 sent = self.get_next_shim_layer().sendmessage(destip, destport, message, localip, localport)92 except Exception, err:93 self._log('%s\n > Exception = %s, %s\n' % (log_info, repr(err), str(err)))94 raise err95 self._log('%s\n > return = %s' % (log_info, sent))96 return sent97 def listenformessage(self, localip, localport):98 log_info = ('listenformessage, localip = %s, localport = %s' % (localip, localport))99 self._log(log_info)100 try:101 next_layer_socket = self.get_next_shim_layer().listenformessage(localip, localport)102 except Exception, err:103 self._log('%s\n > Exception = %s, %s\n' % (log_info, repr(err), str(err)))104 raise err105 self._log('%s\n > return = %s' % (log_info, next_layer_socket)) 106 sock = ShimUDPServerSocket(next_layer_socket, self)107 return sock108 def openconnection(self, destip, destport, localip, localport, timeout):109 log_info = ('openconnection, destip = %s, destport = %s, localip = %s, localport = %s, timeout = %s'110 % (destip, destport, localip, localport, timeout))111 self._log(log_info)112 try:113 next_sockobj = self.get_next_shim_layer().openconnection(destip, destport, localip, localport, timeout)114 except Exception, err:115 self._log('%s\n > Exception = %s, %s\n' % (log_info, repr(err), str(err)))116 raise err117 self._log('%s\n > return = %s' % (log_info, next_sockobj)) 118 sock = ShimSocket(next_sockobj, self)119 return sock120 def listenforconnection(self, localip, localport):121 log_info = 'listenforconnection, localip = %s, localport = %s' % (localip, localport)122 self._log(log_info)123 try:124 next_layer_socket = self.get_next_shim_layer().listenforconnection(localip, localport)125 except Exception, err:126 self._log('%s\n > Exception = %s, %s\n' % (log_info, repr(err), str(err)))127 raise err128 self._log('%s\n > return = %s' % (log_info, next_layer_socket)) 129 sock = ShimTCPServerSocket(next_layer_socket, self)130 return sock131 def socket_close(self, socket):132 log_info = 'socket_close, socket = %s' % socket133 self._log(log_info)134 try:135 value = self.get_next_shim_layer().socket_close(socket)136 except Exception, err:137 self._log('%s\n > Exception = %s, %s\n' % (log_info, repr(err), str(err)))138 raise err139 self._log('%s\n > return = %s' % (log_info, value)) 140 return value141 def socket_send(self, socket, msg):142 log_info = 'socket_send, socket = %s, msg = %s' % (socket, self._abbrev(msg))143 self._log(log_info)144 try:145 sent = self.get_next_shim_layer().socket_send(socket, msg)146 except Exception, err:147 self._log('%s\n > Exception = %s, %s\n' % (log_info, repr(err), str(err)))148 raise err149 self._log('%s\n > return = %s' % (log_info, sent))150 return sent151 def socket_recv(self, socket, bytes):152 log_info = 'socket_recv, socket = %s, bytes = %s' % (socket, bytes)153 self._log(log_info)154 try:155 data = self.get_next_shim_layer().socket_recv(socket, bytes)156 except Exception, err:157 self._log('%s\n > Exception = %s, %s\n' % (log_info, repr(err), str(err)))158 raise err159 self._log('%s\n > return = %s' % (log_info, self._abbrev(data)))160 return data161 def tcpserversocket_getconnection(self, tcpserversocket):162 log_info = 'tcpserversocket_getconnection, tcpserversocket = %s' % tcpserversocket163 try:164 (remote_ip, remote_port, repy_socket) = self.get_next_shim_layer().tcpserversocket_getconnection(tcpserversocket)165 except Exception, err:166 #self._log('%s\n > Exception = %s, %s\n' % (log_info, repr(err), str(err)))167 raise err168 self._log(log_info)169 self._log('%s\n > return = %s' % (log_info, (remote_ip, remote_port, repy_socket)))170 value = (remote_ip, remote_port, ShimSocket(repy_socket, self))171 return value172 def tcpserversocket_close(self, tcpserversocket):173 log_info = 'tcpserversocket_close, tcpserversocket = %s' % tcpserversocket174 self._log(log_info)175 try:176 value = self.get_next_shim_layer().tcpserversocket_close(tcpserversocket)177 except Exception, err:178 self._log('%s\n > Exception = %s, %s\n' % (log_info, repr(err), str(err)))179 raise err180 self._log('%s\n > return = %s' % (log_info, value)) 181 return value182 def udpserversocket_getmessage(self, udpserversocket):183 log_info = 'udpserversocket_getmessage, udpserversocket = %s' % udpserversocket184 self._log(log_info)185 try:186 value = self.get_next_shim_layer().udpserversocket_getmessage(udpserversocket)187 except Exception, err:188 self._log('%s\n > Exception = %s, %s\n' % (log_info, repr(err), str(err)))189 raise err190 self._log('%s\n > return = %s' % (log_info, value)) 191 return value192 def udpserversocket_close(self, udpserversocket):193 log_info = 'udpserversocket_close, udpserversocket = %s' % udpserversocket194 self._log(log_info)195 try:196 value = self.get_next_shim_layer().udpserversocket_close(udpserversocket)197 except Exception, err:198 self._log('%s\n > Exception = %s, %s\n' % (log_info, repr(err), str(err)))199 raise err200 self._log('%s\n > return = %s' % (log_info, value)) 201 return value202 203 def copy(self):204 return LogShim(self.shim_context['shim_stack'].copy(), self.shim_context['optional_args'])205 206 def get_advertisement_string(self):...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Lemoncheesecake automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful