Exemplo n.º 1
0
Arquivo: ash.py Projeto: sjp38/ash
def _get_and_process_user_input():
    user_input = _get_expression()
    if user_input == "":
        # TODO: print help message.
        return
    result = None
    if modglob._conn_to_ashmon:
        modglob.sock.sendall(user_input + ashmon.END_OF_MSG)
        tokens = ""
        while True:
            received = modglob.sock.recv(1024)
            if not received or not modglob._conn_to_ashmon:
                print "connection crashed!"
                modglob.sock.close()
                modglob.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
                modglob.sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)

                modglob._conn_to_ashmon = False
                break
            msgs, tokens = ashmon.get_complete_message(received, tokens)
            for msg in msgs:
                result = eval(msg)
                break
    else:
        result = ashval.ashval(user_input)

    if result:
        print_result(result)