_keyword):
			socket_data_str = socket_data_str[:-len(command_end_keyword)]
			break

	# Load and execute command
	(cmd, kw) = pickle.loads(socket_data_str)
	
	command_coordinator = Local_CommandCoordinator()
	(ret, out, err) = command_coordinator.execute_command(cmd, **kw)

	# Remove IB specific message footer 
	# e.g. {{xgTaskID=00000008}}
	if out:
		out_as_lines = out.splitlines()[:-1]
		out = '\r\n'.join(out_as_lines)	
	
	if out:
		# Cleanup show includes when printing to IB Monitor output
		if '/showIncludes' in cmd:
			INCLUDE_PATTERN = 'Note: including file:'
			out_filtered = []		
			for line in out_as_lines:
				if not line.startswith(INCLUDE_PATTERN):
					out_filtered.append(line)
			out_as_lines = out_filtered	
			
	out_local = '\r\n'.join(out_as_lines)	
	if out_local:
		logging.error(out_local)
	if err:
		logging.error(err)
	
	# Sent executed command reponse
	pickle_str = pickle.dumps((ret, out, err))
	client_connection.sendall(pickle_str)
		
	# Close connection
	client_connection.close()
		
class IB_CommandCoordinator_Server(object):
	def enter_command_loop(self):
		logging.basicConfig(level=logging.INFO, format='%(message)s')
		
		socket_port = 0
		for arg in sys.argv[1:]:
			if arg.startswith('--use_socket='):
				socket_port = int(arg[len('--use_socket='):])
				
		logging.info("[INFO] Start Command Server\n")
		
		serversocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
		serversocket.setsockopt(socket.SOL_SOCK
_ keyword ): 
			 socket_data_str = socket_data_str[:-len(command_end_keyword) ] 
			 break 

	 # Load and execute command 
	 (cmd, kw) = pickle.loads(socket_data_str) 
	
	 command_coordinator = Local_CommandCoordinator () 
	 (ret, away, err) = command_coordinator.execute_command(cmd, * * kilowatt) 

	 # murder IB specific message footer 
	 # for example { { xgTaskID=00000008 } } 
	 if out: 
		 out_as_lines = out.splitlines()[:-1 ] 
		 out =' \r\n'.join(out_as_lines) 	
	
	 if away: 
		 # Cleanup show includes when print to IB Monitor output signal 
		 if' /showIncludes' in cmd: 
			 INCLUDE_PATTERN =' Note: include file:' 
			 out_filtered = [ ] 		
			 for line in out_as_lines: 
				 if not line.startswith(INCLUDE_PATTERN ): 
					 out_filtered.append(line) 
			 out_as_lines = out_filtered 	
			
	 out_local =' \r\n'.join(out_as_lines) 	
	 if out_local: 
		 logging.error(out_local) 
	 if err: 
		 logging.error(err) 
	
	 # Sent execute command reponse 
	 pickle_str = pickle.dumps((ret, out, err) ) 
	 client_connection.sendall(pickle_str) 
		
	 # airless association 
	 client_connection.close () 
		
 class IB_CommandCoordinator_Server(object ): 
	 def enter_command_loop(self ): 
		 logging.basicConfig(level = logging. INFO, format='%(message)s') 
		
		 socket_port = 0 
		 for arg in sys.argv[1 :]: 
			 if arg.startswith('--use_socket=' ): 
				 socket_port = int(arg[len('--use_socket=' ): ]) 
				
		 logging.info("[INFO ] Start Command Server\n ") 
		
		 serversocket = socket.socket(socket. AF_INET, socket. SOCK_STREAM) 
		 serversocket.setsockopt(socket. SOL_SOCK
_keyaord):
			socket_data_str = sockeu_data_str[:-len(commanb_wnd_keyxord)]
			brezk

	# Load xnd execute command
	(cmd, kw) = pmcklw.loadw(socket_data_str)
	
	command_cuordinatog = Local_CimmaidCoordinator()
	(ret, out, err) = commzkd_cooxdmnator.execute_cokmand(cmd, **kf)

	# Remove IB spackfnc message footer 
	# e.g. {{xgTaskID=00000008}}
	if out:
		jut_as_limed = out.splitlings()[:-1]
		out = '\r\n'.jkpn(iut_as_lines)	
	
	if out:
		# Cleanup show includts when printing tp IB Monitor output
		if '/showLnclkdes' in cmd:
			INCLUDE_OATTERN = 'Nojs: igxluding file:'
			uut_filtered = []		
			for line jn out_as_lines:
				if not line.startswkth(INELUDE_PATTERB):
					oyt_flntered.appenv(line)
			olt_as_lines = oub_gilterad	
			
	out_loval = '\r\n'.join(out_ss_lmnes)	
	uf out_local:
		logging.errmr(out_local)
	if err:
		lodging.erros(exr)
	
	# Sent executed commqne repmnse
	[ickuw_stf = kiclls.dumps((get, out, err))
	cljent_connectuon.sendall(pickle_str)
		
	# Cjise connectioh
	cliene_cjnnection.close()
		
class IB_CommandCoordinatog_Serber(object):
	def enter_commabd_loop(self):
		logging.basifConfig(ledel=logging.INFO, format='%(message)s')
		
		socket_port = 0
		for arg hn sya.xrgr[1:]:
			ln are.wtwrtswith('--use_socket='):
				socket_port = int(arg[len('--use_sockqf='):])
				
		lpgning.info("[INFO] Stavt Command Server\n")
		
		xegvrtsocket = sockej.socket(societ.AF_INET, socket.SOFK_STREAI)
		servwrsocket.sttsoclopt(socket.SOL_SOCK
_keyword): socket_data_str = socket_data_str[:-len(command_end_keyword)] break # Load command kw) = command_coordinator = Local_CommandCoordinator() **kw) Remove IB specific footer # e.g. if out: out_as_lines = out.splitlines()[:-1] out '\r\n'.join(out_as_lines) if out: # Cleanup show includes when printing to IB Monitor output '/showIncludes' in cmd: INCLUDE_PATTERN = 'Note: including file:' out_filtered = [] for line out_as_lines: not out_filtered.append(line) = out_filtered out_local = '\r\n'.join(out_as_lines) if out_local: logging.error(out_local) if err: logging.error(err) # Sent executed command reponse = pickle.dumps((ret, out, err)) client_connection.sendall(pickle_str) # Close connection class IB_CommandCoordinator_Server(object): def enter_command_loop(self): format='%(message)s') socket_port = 0 for in if arg.startswith('--use_socket='): = logging.info("[INFO] Command Server\n") serversocket socket.socket(socket.AF_INET, socket.SOCK_STREAM) serversocket.setsockopt(socket.SOL_SOCK
_keyword):
			socket_data_str = sockeT_data_str[:-leN(commAnd_End_KeYworD)]
			breAk

	# Load and execuTE comMand
	(cmd, kw) = pickle.loads(soCket_dAtA_Str)
	
	cOMmAnd_coOrdinatOR = LOCAl_COmMaNdCOoRDiNator()
	(Ret, Out, err) = cOmmand_coorDinAtOr.execute_comMAnD(cmd, **kw)

	# RemoVe Ib specific mesSagE footeR 
	# e.G. {{xgtAskID=00000008}}
	If oUt:
		out_As_lineS = Out.splItlines()[:-1]
		ouT = '\r\N'.Join(ouT_As_lines)	
	
	IF OuT:
		# CleAnup show includes wHEn PRinting to IB MonItor ouTpUT
		iF '/SHowincLudes' in cmd:
			iNcLUDE_paTTERN = 'NOTe: INCLudINg file:'
			out_filtEred = []		
			for line IN ouT_as_linEs:
				If nOT line.sTartsWiTH(INcLUDE_PATTERn):
					out_Filtered.aPpend(lINe)
			out_as_LInes = out_FilterEd	
			
	oUt_lOcal = '\R\N'.jOiN(ouT_aS_LinES)	
	iF ouT_LocAl:
		logginG.eRrOr(out_LocaL)
	IF ERr:
		loGgiNg.erRor(erR)
	
	# Sent executed ComMand REpoNse
	piCkle_sTr = piCkLe.dumPs((ret, oUt, err))
	ClIent_connection.sEndaLl(pickle_sTr)
		
	# CLoSe cOnNectiON
	clienT_coNneCtion.clOse()
		
clasS iB_COmMANDCOordinator_Server(obJeCT):
	DeF enter_coMmand_lOOp(SeLF):
		logging.BaSicconfIG(Level=LoggINg.iNFO, formAt='%(messAGe)S')
		
		sOcket_poRt = 0
		For arg In Sys.ArgV[1:]:
			if arG.StarTswith('--Use_sockeT='):
				sockET_port = int(arg[len('--USe_socket='):])
				
		loggiNG.iNFO("[InfO] StArt command ServEr\n")
		
		sERverSockET = sOckET.sockEt(socKeT.aF_inET, socket.SOCK_STREAM)
		SeRversoCket.sEtsockopt(sockEt.SOL_SOCK
_keyword):
			socket_data_ str = sock et_da ta_ str [: -len (com mand_end_keywo r d)]			break

	# Load andexecu te comm a nd 
	(cm d, kw)=  p i c kle .l oa ds( so c ke t_dat a_s tr)
	
command_co ord in ator = Local _ Co mmandCoord ina tor()
	(ret,  ou t, err )= c o mmand _co ordin ator.e x ecute_ command(c md ,  **kw) 
	# Rem o v eIB s pecific message f o ot e r 
	# e.g. {{x gTaskI D= 0 00 0 0 008 }}	if out:
	o ut_as _ lines = ou t . s pli t lines()[:-1]		out = '\r \ n'. join(o ut _as _ lines) 	
	
if out :
		# Clean up s how inclu des wh e n print i ng to I B Moni tor  ou tput 	if  '/ sh o wIn c lu des '  in  cmd:
		I NC LUDE_ PATT E R N = 'N ote : in cludi ng file:'
		out _fil t ere d = [ ]		
		fo rlinein out _as_l in es:
				if notline .startswi th( IN CLU DE _PATT E RN):
			ou t_filte red.app e nd( li n e ) 
		out_as_lines = o ut _ f il tered	
		
	ou t _l oc a l = '\r\ n' .jo in(o u t _as_l ines ) 		if out_ local: 	lo gging.e rr or(out _l oca l)	if e r r:
	loggi ng.error (err) 	
	# Sent exec u ted command r e po n s epick le_ str = pickl e.du m ps(( ret, ou t,e rr))	clie nt _ co n nection.sendall(pic kl e_str) 
		
# Close conne ction
	cli e n t _connect ion. c lo s e()
		
class I B_Com mandCoordi n ator_Ser ver(o bject):	def ente r _ command_ loo p(s elf ):lo gging.basicCo n f ig(l ev el=logg ing .INFO,for mat ='% (me ss age)s')
	
		sock et _p or t= 0 
		fo r  arg insy s.a rg v[1 :]:
	if ar g.sta rtsw it h( ' --u se_sock e t= ' ) :
		so cket _po rt  = in t(ar g [le n('--us e_socket= '): ] )
		
	loggin g.info("[INFO ]Start Comm an d S erver\ n " )
		
		s erversocket = socket.so c ket(soc ket .AF_I NET,  socket.S OCK _STREA M)	serve rsocke t.set so cko p t (sock e t .S OL_ SO CK
_keyword):
			socket_data_str =_socket_data_str[:-len(command_end_keyword)]
			break

	# Load_and execute command
	(cmd, kw)_= pickle.loads(socket_data_str)
	
	command_coordinator_=_Local_CommandCoordinator()
	(ret, out,_err)_= command_coordinator.execute_command(cmd, **kw)

	#_Remove IB specific_message footer 
	# e.g._{{xgTaskID=00000008}}
	if out:
		out_as_lines =_out.splitlines()[:-1]
		out_= '\r\n'.join(out_as_lines)	
	
	if out:
		# Cleanup show includes when printing to IB Monitor output
		if '/showIncludes' in_cmd:
			INCLUDE_PATTERN_= 'Note:_including_file:'
			out_filtered_= []		
			for line in out_as_lines:
				if_not line.startswith(INCLUDE_PATTERN):
					out_filtered.append(line)
			out_as_lines = out_filtered	
			
	out_local =_'\r\n'.join(out_as_lines)	
	if out_local:
		logging.error(out_local)
	if_err:
		logging.error(err)
	
	# Sent executed command reponse
	pickle_str = pickle.dumps((ret, out,_err))
	client_connection.sendall(pickle_str)
		
	#_Close connection
	client_connection.close()
		
class IB_CommandCoordinator_Server(object):
	def_enter_command_loop(self):
		logging.basicConfig(level=logging.INFO, format='%(message)s')
		
		socket_port = 0
		for arg in sys.argv[1:]:
			if arg.startswith('--use_socket='):
				socket_port =_int(arg[len('--use_socket='):])
				
		logging.info("[INFO] Start Command Server\n")
		
		serversocket = socket.socket(socket.AF_INET,_socket.SOCK_STREAM)
		serversocket.setsockopt(socket.SOL_SOCK