<s> import threading <EOL> from . . constants import * <EOL> from . . config import * <EOL> from struct import pack , unpack <EOL> import hashlib <EOL> printLock = threading . Lock ( ) <EOL> responseMessages = [ ] <EOL> responseMessagesLock = threading . Lock ( ) <EOL> shutdown = False <EOL> def isShutdownReady ( ) : <EOL> return shutdown <EOL> def startShutdown ( ) : <EOL> global shutdown <EOL> shutdown = True <EOL> def safePrint ( * x ) : <EOL> s = "<STR_LIT>" <EOL> for obj in x : <EOL> s += str ( obj ) <EOL> with printLock : <EOL> print ( s ) <EOL> def getVersionPayload ( conf ) : <EOL> return VERSION <EOL> def getCommandString ( command , conf ) : <EOL> data = MESSAGE_MAGIC_BYTES <EOL> commandStr = command . encode ( ) + ( b'<STR_LIT:\x00>' * ( <NUM_LIT:8> - len ( command ) ) ) <EOL> data += commandStr <EOL> payload = '<STR_LIT>' <EOL> if command == '<STR_LIT>' : <EOL> payload = getVersionPayload ( conf ) <EOL> payload = payload . encode ( ) <EOL> payloadLen = len ( payload ) <EOL> data += pack ( '<STR_LIT>' , payloadLen ) <EOL> data += hashlib . sha512 ( payload ) . digest ( ) [ <NUM_LIT:0> : <NUM_LIT:4> ] <EOL> return data + payload </s>
