Convert string concat to join - more efficient in time and meory

debug
Simon 3 years ago
parent 384c89bd3a
commit 8d1a3c070d

@ -230,7 +230,7 @@ def make_stat_bridge(_tgid):
def make_default_reflector(reflector,_tmout,system):
bridge = '#'+str(reflector)
bridge = ''.join(['#',str(reflector)])
#_tmout = CONFIG['SYSTEMS'][system]['DEFAULT_UA_TIMER']
if bridge not in BRIDGES:
BRIDGES[bridge] = []
@ -273,7 +273,7 @@ def reset_static_tg(tg,ts,_tmout,system):
return
def reset_default_reflector(reflector,_tmout,system):
bridge = '#'+str(reflector)
bridge = ''.join(['#',str(reflector)])
#_tmout = CONFIG['SYSTEMS'][system]['DEFAULT_UA_TIMER']
if bridge not in BRIDGES:
BRIDGES[bridge] = []
@ -288,7 +288,7 @@ def reset_default_reflector(reflector,_tmout,system):
def make_single_reflector(_tgid,_tmout,_sourcesystem):
_tgid_s = str(int_id(_tgid))
_bridge = '#' + _tgid_s
_bridge = ''.join(['#',_tgid_s])
#1 min timeout for echo
if _tgid_s == '9990':
_tmout = 1
@ -620,7 +620,7 @@ def playFileOnRequest(self,fileNumber):
sleep(1)
_say = []
try:
_say.append(AMBEobj.readSingleFile('/'+_lang+'/ondemand/'+str(fileNumber)+'.ambe'))
_say.append(AMBEobj.readSingleFile(''.join(['/',_lang,'/ondemand/',str(fileNumber),'.ambe'])))
except IOError:
logger.warning('(%s) cannot read file for number %s',system,fileNumber)
return
@ -784,39 +784,39 @@ def options_config():
if 'TS1_1' in _options:
_options['TS1_STATIC'] = _options.pop('TS1_1')
if 'TS1_2' in _options:
_options['TS1_STATIC'] = _options['TS1_STATIC'] + ',' + _options.pop('TS1_2')
_options['TS1_STATIC'] = ''.join([_options['TS1_STATIC'],',',_options.pop('TS1_2')])
if 'TS1_3' in _options:
_options['TS1_STATIC'] = _options['TS1_STATIC'] + ',' + _options.pop('TS1_3')
_options['TS1_STATIC'] = ''.join([_options['TS1_STATIC'],',',_options.pop('TS1_3')])
if 'TS1_4' in _options:
_options['TS1_STATIC'] = _options['TS1_STATIC'] + ',' + _options.pop('TS1_4')
_options['TS1_STATIC'] = ''.join([_options['TS1_STATIC'],',',_options.pop('TS1_4')])
if 'TS1_5' in _options:
_options['TS1_STATIC'] = _options['TS1_STATIC'] + ',' + _options.pop('TS1_5')
_options['TS1_STATIC'] = ''.join([_options['TS1_STATIC'],',',_options.pop('TS1_5')])
if 'TS1_6' in _options:
_options['TS1_STATIC'] = _options['TS1_STATIC'] + ',' + _options.pop('TS1_6')
_options['TS1_STATIC'] = ''.join([_options['TS1_STATIC'],',',_options.pop('TS1_6')])
if 'TS1_7' in _options:
_options['TS1_STATIC'] = _options['TS1_STATIC'] + ',' + _options.pop('TS1_7')
_options['TS1_STATIC'] = ''.join([_options['TS1_STATIC'],',',_options.pop('TS1_7')])
if 'TS1_8' in _options:
_options['TS1_STATIC'] = _options['TS1_STATIC'] + ',' + _options.pop('TS1_8')
_options['TS1_STATIC'] = ''.join([_options['TS1_STATIC'],',',_options.pop('TS1_8')])
if 'TS1_9' in _options:
_options['TS1_STATIC'] = _options['TS1_STATIC'] + ',' + _options.pop('TS1_9')
_options['TS1_STATIC'] = ''.join([_options['TS1_STATIC'],',',_options.pop('TS1_9')])
if 'TS2_1' in _options:
_options['TS2_STATIC'] = _options.pop('TS2_1')
if 'TS2_2' in _options:
_options['TS2_STATIC'] = _options['TS2_STATIC'] + ',' + _options.pop('TS2_2')
_options['TS2_STATIC'] = ''.join([_options['TS2_STATIC'],','. _options.pop('TS2_2')])
if 'TS2_3' in _options:
_options['TS2_STATIC'] = _options['TS2_STATIC'] + ',' + _options.pop('TS2_3')
_options['TS2_STATIC'] = ''.join([_options['TS2_STATIC'],',',_options.pop('TS2_3')])
if 'TS2_4' in _options:
_options['TS2_STATIC'] = _options['TS2_STATIC'] + ',' + _options.pop('TS2_4')
_options['TS2_STATIC'] = ''.join([_options['TS2_STATIC'],',',_options.pop('TS2_4')])
if 'TS2_5' in _options:
_options['TS2_STATIC'] = _options['TS2_STATIC'] + ',' + _options.pop('TS2_5')
_options['TS2_STATIC'] = ''.join([_options['TS2_STATIC'],',',_options.pop('TS2_5')])
if 'TS2_6' in _options:
_options['TS2_STATIC'] = _options['TS2_STATIC'] + ',' + _options.pop('TS2_6')
_options['TS2_STATIC'] = ''.join([_options['TS2_STATIC'],',',_options.pop('TS2_6')])
if 'TS2_7' in _options:
_options['TS2_STATIC'] = _options['TS2_STATIC'] + ',' + _options.pop('TS2_7')
_options['TS2_STATIC'] = ''.join([_options['TS2_STATIC'],',',_options.pop('TS2_7')])
if 'TS2_8' in _options:
_options['TS2_STATIC'] = _options['TS2_STATIC'] + ',' + _options.pop('TS2_8')
_options['TS2_STATIC'] = ''.join([_options['TS2_STATIC'],',',_options.pop('TS2_8')])
if 'TS2_9' in _options:
_options['TS2_STATIC'] = _options['TS2_STATIC'] + ',' + _options.pop('TS2_9')
_options['TS2_STATIC'] = ''.join([_options['TS2_STATIC'],',',_options.pop('TS2_9')])
if 'UserLink' in _options:
_options.pop('UserLink')
@ -1730,7 +1730,7 @@ class routerOBP(OPENBRIDGE):
# If we don't have a voice header then don't wait to decode the Embedded LC
# just make a new one from the HBP header. This is good enough, and it saves lots of time
else:
self.STATUS[_stream_id]['LC'] = LC_OPT + _dst_id + _rf_src
self.STATUS[_stream_id]['LC'] = b''.join([LC_OPT,_dst_id,_rf_src])
_inthops = 0
if _hops:
@ -2070,7 +2070,7 @@ class routerHBP(HBSYSTEM):
_target_status[_target['TS']]['TX_RFS'] = _rf_src
_target_status[_target['TS']]['TX_PEER'] = _peer_id
# Generate LCs (full and EMB) for the TX stream
dst_lc = self.STATUS[_slot]['RX_LC'][0:3] + _target['TGID'] + _rf_src
dst_lc = b''.join([self.STATUS[_slot]['RX_LC'][0:3],_target['TGID'],_rf_src])
_target_status[_target['TS']]['TX_H_LC'] = bptc.encode_header_lc(dst_lc)
_target_status[_target['TS']]['TX_T_LC'] = bptc.encode_terminator_lc(dst_lc)
_target_status[_target['TS']]['TX_EMB_LC'] = bptc.encode_emblc(dst_lc)
@ -2373,7 +2373,7 @@ class routerHBP(HBSYSTEM):
logger.info('(%s) Reflector: Private call from %s to %s',self._system, int_id(_rf_src), _int_dst_id)
if _int_dst_id >= 5 and _int_dst_id != 8 and _int_dst_id != 9 and _int_dst_id <= 999999:
_bridgename = '#'+ str(_int_dst_id)
_bridgename = ''.join(['#',str(_int_dst_id)])
if _bridgename not in BRIDGES and not (_int_dst_id >= 4000 and _int_dst_id <= 5000) and not (_int_dst_id >=9991 and _int_dst_id <= 9999):
logger.info('(%s) [A] Reflector for TG %s does not exist. Creating as User Activated. Timeout: %s',self._system, _int_dst_id,CONFIG['SYSTEMS'][self._system]['DEFAULT_UA_TIMER'])
make_single_reflector(_dst_id,CONFIG['SYSTEMS'][self._system]['DEFAULT_UA_TIMER'],self._system)
@ -2569,7 +2569,7 @@ class routerHBP(HBSYSTEM):
# If we don't have a voice header then don't wait to decode it from the Embedded LC
# just make a new one from the HBP header. This is good enough, and it saves lots of time
else:
self.STATUS[_slot]['RX_LC'] = LC_OPT + _dst_id + _rf_src
self.STATUS[_slot]['RX_LC'] = b''.join([LC_OPT,_dst_id,_rf_src])
#Create default bridge for unknown TG
if int_id(_dst_id) >= 5 and int_id(_dst_id) != 9 and int_id(_dst_id) != 4000 and int_id(_dst_id) != 5000 and (str(int_id(_dst_id)) not in BRIDGES):
@ -2672,7 +2672,7 @@ class routerHBP(HBSYSTEM):
if _bridge[0:1] == '#':
_bridge = _bridge[1:]
else:
_bridge = '#'+_bridge
_bridge = ''.join(['#',_bridge])
if _bridge in BRIDGES:
_sysIgnore = self.to_target(_peer_id, _rf_src, _dst_id, _seq, _slot, _call_type, _frame_type, _dtype_vseq, _stream_id, _data, pkt_time, dmrpkt, _bits,_bridge,_system,False,_sysIgnore,_source_server,_ber,_rssi,_source_rptr)
@ -2794,12 +2794,12 @@ class bridgeReportFactory(reportFactory):
def send_bridge(self):
serialized = pickle.dumps(BRIDGES, protocol=2) #.decode("utf-8", errors='ignore')
self.send_clients(REPORT_OPCODES['BRIDGE_SND']+serialized)
self.send_clients(b''.join([REPORT_OPCODES['BRIDGE_SND'],serialized]))
def send_bridgeEvent(self, _data):
if isinstance(_data, str):
_data = _data.decode('utf-8', error='ignore')
self.send_clients(REPORT_OPCODES['BRDG_EVENT']+_data)
self.send_clients(b''.join([REPORT_OPCODES['BRDG_EVENT'],_data]))
#************************************************
@ -2974,7 +2974,7 @@ if __name__ == '__main__':
if CONFIG['SYSTEMS'][system]['ENABLED']:
if CONFIG['SYSTEMS'][system]['MODE'] == 'MASTER' and (CONFIG['SYSTEMS'][system]['GENERATOR'] > 1):
for count in range(CONFIG['SYSTEMS'][system]['GENERATOR']):
_systemname = system+'-'+str(count)
_systemname = ''.join([system,'-',str(count)])
generator[_systemname] = copy.deepcopy(CONFIG['SYSTEMS'][system])
generator[_systemname]['PORT'] = generator[_systemname]['PORT'] + count
generator[_systemname]['_default_options'] = "TS1_STATIC={};TS2_STATIC={};SINGLE={};DEFAULT_UA_TIMER={};DEFAULT_REFLECTOR={};VOICE={};LANG={}".format(generator[_systemname]['TS1_STATIC'],generator[_systemname]['TS2_STATIC'],int(generator[_systemname]['SINGLE_MODE']),generator[_systemname]['DEFAULT_UA_TIMER'],generator[_systemname]['DEFAULT_REFLECTOR'],int(generator[_systemname]['VOICE_IDENT']), generator[_systemname]['ANNOUNCEMENT_LANGUAGE'])

@ -256,7 +256,7 @@ class OPENBRIDGE(DatagramProtocol):
def send_bcve(self):
if self._config['ENHANCED_OBP'] and self._config['TARGET_IP']:
_packet = BCVE + VER.to_bytes(1,'big')
_packet = b''.join([BCVE,VER.to_bytes(1,'big')])
_packet = b''.join([_packet, (hmac_new(self._config['PASSPHRASE'],_packet[4:5],sha1).digest())])
self.transport.write(_packet, (self._config['TARGET_IP'], self._config['TARGET_PORT']))
logger.trace('(%s) *BridgeControl* sent BCVE. Ver: %s',self._system,VER)
@ -872,11 +872,11 @@ class HBSYSTEM(DatagramProtocol):
def master_dereg(self):
for _peer in self._peers:
self.send_peer(_peer, MSTCL + _peer)
self.send_peer(_peer, b''.join([MSTCL,_peer]))
logger.info('(%s) De-Registration sent to Peer: %s (%s)', self._system, self._peers[_peer]['CALLSIGN'], self._peers[_peer]['RADIO_ID'])
def peer_dereg(self):
self.send_master(RPTCL + self._config['RADIO_ID'])
self.send_master(b''.join([RPTCL,self._config['RADIO_ID']]))
logger.info('(%s) De-Registration sent to Master: %s:%s', self._system, self._config['MASTER_SOCKADDR'][0], self._config['MASTER_SOCKADDR'][1])
def proxy_IPBlackList(self,peer_id,sockaddr):
@ -1376,9 +1376,9 @@ class reportFactory(Factory):
def try_download(_path, _file, _url, _stale,):
no_verify = ssl._create_unverified_context()
now = time()
file_exists = isfile(_path+_file) == True
file_exists = isfile(''.join([_path,_file])) == True
if file_exists:
file_old = (getmtime(_path+_file) + _stale) < now
file_old = (getmtime(''.join([_path,_file])) + _stale) < now
if not file_exists or (file_exists and file_old):
try:
with urlopen(_url, context=no_verify) as response:
@ -1391,7 +1391,7 @@ def try_download(_path, _file, _url, _stale,):
else:
if data and (data != b'{}'):
try:
with open(_path+_file, 'wb') as outfile:
with open(''.join([_path,_file]), 'wb') as outfile:
outfile.write(data)
outfile.close()
except IOError:
@ -1408,7 +1408,7 @@ def try_download(_path, _file, _url, _stale,):
def mk_server_dict(path,filename):
server_ids = {}
try:
with open(path+filename,newline='') as csvfile:
with open(''.join([path,filename]),newline='') as csvfile:
reader = csv.DictReader(csvfile,dialect='excel-tab')
for _row in reader:
server_ids[_row['OPB Net ID']] = _row['Country']

Loading…
Cancel
Save

Powered by TurnKey Linux.