(encrypt_code, q_main, q_list, exit_on_disconnect=True)
Handle the incoming queue and duplicate for all clients.
Handle the incoming queue and duplicate for all clients.
Handle the incoming queue and duplicate for all clients .
def middleman_thread(encrypt_code, q_main, q_list, exit_on_disconnect=True):
    """Handle the incoming queue and duplicate for all clients."""
    crypt = Crypt(encrypt_code)
    
    #This will cut off all messages from before the previous connection
    try:
        q_list[-1].put(MESSAGE_IGNORE)
    except (IOError, EOFError):
        return
    
    #Loop through and wait for input messages
    t = currentThread()
    while getattr(t, 'running', True):
        try:
            message = q_main.get(timeout=calculate_api_timeout())
        except queue.Empty:
            pass
        except (IOError, EOFError):
            return
        else:
            if message == MESSAGE_QUIT:
                queues = q_list[:-1]
            elif message == MESSAGE_IGNORE:
                queues = q_list[-1]
            else:
                message = crypt.encrypt(message)
                queues = q_list
                
            #Send to client threads
            for q in queues:
                try:
                    q.put(message)
                except AssertionError:
                    if exit_on_disconnect:
                        return
                except (IOError, EOFError):
                    return
def middleman_thread ( encrypt_code , q_main , q_list , exit_on_disconnect = True ) : crypt = Crypt ( encrypt_code ) #This will cut off all messages from before the previous connection try : q_list [ - 1 ] . put ( MESSAGE_IGNORE ) except ( IOError , EOFError ) : return #Loop through and wait for input messages t = currentThread ( ) while getattr ( t , 'running' , True ) : try : message = q_main . get ( timeout = calculate_api_timeout ( ) ) except queue . Empty : pass except ( IOError , EOFError ) : return else : if message == MESSAGE_QUIT : queues = q_list [ : - 1 ] elif message == MESSAGE_IGNORE : queues = q_list [ - 1 ] else : message = crypt . encrypt ( message ) queues = q_list #Send to client threads for q in queues : try : q . put ( message ) except AssertionError : if exit_on_disconnect : return except ( IOError , EOFError ) : return