예제 #1
0
print(
    "Adding 15 more messages to the message list in revers order.\nSender: Sender\nReciever: Reciever, Message: str(i) | for i = 15 to 0"
)
for i in range(15, 0, -1):
    mess_list.add_message("Sender", "Reciever", str(i))
print("Print 25 messages: (Print 20 messages)")
mess_list.print_n(25)
wait = input("[Enter to Contine]")
wait = None

## user_func.py
print("\n\n<<<< <<<< <<<< user_func.py >>>> >>>> >>>>")
print(
    "Attempting to open test_file.txt. To test opening files that do not exist, ensure that test_file.txt does not exist."
)
user_list = user_func.u_list('test_file.txt')  #might exist
print("setting user_list.key = '1234567890' and user_list.me = 'user0'")
user_list.key = '1234567890'
user_list.me = 'user0'
print("Adding users0 throuhg user20, all with ip '127.0.0.1'")
for i in range(0, 21):
    user_list.add_user(("user" + str(i), '127.0.0.1'))
print("Printing all users in network")
user_list.print_users()
print("Searching for 'user10': Return user_info")
print(user_list.search_users('user10'))
print("Removing 'user10'")
user_list.remove_user('user10')
print("Searching for 'user10': Return None (print True)")
print(user_list.search_users('user10') == None)
print("Writing file")
예제 #2
0
print("Print 4 messages: (Print 4 messages)")
mess_list.print_n(4)
print("Print 'a' messages: (Print None)")
mess_list.print_n('a')
print("Adding 15 more messages to the message list in revers order.\nSender: Sender\nReciever: Reciever, Message: str(i) | for i = 15 to 0")
for i in range(15,0,-1):
  mess_list.add_message("Sender", "Reciever", str(i))
print("Print 25 messages: (Print 20 messages)")
mess_list.print_n(25)
wait = input("[Enter to Contine]")
wait = None

## user_func.py
print("\n\n<<<< <<<< <<<< user_func.py >>>> >>>> >>>>")
print("Attempting to open test_file.txt. To test opening files that do not exist, ensure that test_file.txt does not exist.")
user_list = user_func.u_list('test_file.txt') #might exist
print("setting user_list.key = '1234567890' and user_list.me = 'user0'")
user_list.key = '1234567890'
user_list.me = 'user0'
print("Adding users0 throuhg user20, all with ip '127.0.0.1'")
for i in range(0,21):
  user_list.add_user(("user"+str(i), '127.0.0.1'))
print("Printing all users in network")
user_list.print_users()
print("Searching for 'user10': Return user_info")
print(user_list.search_users('user10'))
print("Removing 'user10'")
user_list.remove_user('user10')
print("Searching for 'user10': Return None (print True)")
print(user_list.search_users('user10') == None)
print("Writing file")
예제 #3
0
def main(LMT= False):
  # Declair Globals that will be set
  global my_user_name, key, filename, input_message


  # LONG MESSAGE TESTING:
  if LMT:
    assert open("test_file.txt")
    user_list = user_func.u_list("test_file.txt")
    message_hist = messages.message_list()
    my_user_name = user_list.me
    key = user_list.key
    user_info = old_user = None
    listen_thread = threading.Thread(target=listen, args = (user_list, message_hist,))
    listen_thread.daemon = True
    listen_thread.start()
    message = ''
    l = int(input("Message Max Length == " + str(MAX_MESSAGE_LENGTH) +"\nLength of string to send: "))
    n = int(input("Number of times to send full message: "))
    for i in range(l):
      message = message + str(i%10)
    for i in range(n):
      at(('user1', '127.0.0.1'), message)
    return None
  # END LONG MESSAGE TESTING
  
  
# Main proper  
  print("                     _   __     __             ____ ____   \n" +
        "   _____ ___  __  __/ | / /__  / /_    _   __  \  // __ \  \n" +
        "  /  __/ __ `/ / / /  |/ / _ \/ __/   | | / /  / // / / /  \n" +
        "  / /_/ /_/ / /_/ / /|  /  __/ /_     | |/ /  / // /_/ /   \n" +
        "  \__/\__,_/\__,_/_/ |_/\___/\__/     |___/  /_(_)____/    \n" +
        "\n")
##     ASCII TEXT ART FROM: http://patorjk.com/software/taag/#p=display&f=Slant
  # Select file to open
  while True:
    filename = input("Enter TauNet filename, type 'new' to create new TauNet, or type '!EXIT' to exit.\n: >> ")
    if filename == '!EXIT':
      return None
    elif filename == 'new':
      user_list = user_func.u_list()
      user_list.input_u_list()
    else:
      try:
        open(filename)
      except IOError:
        print(filename + " does not exist.")
        if input("Would you like to create it? (y/n): ") == 'y':
          user_list = user_func.u_list()
          user_list.input_u_list(filename)
          break
      else:
        user_list = user_func.u_list(filename)
        break

  # Set up local variables
  message_hist = messages.message_list()
  user_info = old_user = None
  # Set up global variable
  my_user_name = user_list.me
  key = user_list.key
  filename = user_list.filename
  input_message = "TauNet (" + filename + ") v" + TauNet_version + ">> "

  # Start Listening for incoming messages
  listen_thread = threading.Thread(target=listen, args = (user_list, message_hist,))
  listen_thread.daemon = True
  listen_thread.start()

  # Menu loop
  while True:
    split_command = None
    command = input('\n' + input_message)
    if command == '':
      None# Do nothing
    # Send a message to a user
    elif command[0] == '@':
      user_name, message = read_command(command)
      if(user_name != ''):
        old_user = user_info
        user_info = None
        user_info = user_list.search_users(user_name)
      if user_info: #send the message
          at(user_info, message)
      else:
        user_info = old_user
        print("Error:\n * Invalid Command. ? for help.") ##Invalid user_name

    # Add a user to the list
    elif command[0] == '+': 
      split_command = read_command(command)
      if (split_command[0] != '' and split_command[1] != '' and 
          user_func.valid_user(split_command[0]) and
          user_list.add_user(split_command)):
        user_list.write_file()
      else:
        print("Error:\n * Users name may only contain uppercase and lowercase letters from a-z, the numbers from 0-9, and the - symbol.\n * User names must also not have already been added to the list.")

    # Remove a user from the list          
    elif command[0] == '-':
      if command == '-':
        print("Error:\n * Invalid Command. ? for help.")
      elif user_list.remove_user(command[1:]):
        user_list.write_file()
        user_info = None

    # Display the last n messages
    # or the last message
    elif command[0] == '#':
      try:
        lines = int(command[1:])
      except:
        lines = -1
      if lines > 0 and lines < 21:
        message_hist.print_n(lines)
      else:
        print("Error:\n * n must be a whole number from 1 to 20 represented in digits.")

    # Display the list of users
    elif command == '~':
      user_list.print_users(); print()

    # Display help menue
    elif command == '?':
      help_menu()

    # Clear the Screen
    elif command == '!CLEAR':
      clear()

    # Exit the program      
    elif command == '!EXIT':
      return

    #Invalid command
    else:
      print("Error:\n * Invalid Command. ? for help.")
  return None
예제 #4
0
def main(LMT=False):
    # Declair Globals that will be set
    global my_user_name, key, filename, input_message

    # LONG MESSAGE TESTING:
    if LMT:
        assert open("test_file.txt")
        user_list = user_func.u_list("test_file.txt")
        message_hist = messages.message_list()
        my_user_name = user_list.me
        key = user_list.key
        user_info = old_user = None
        listen_thread = threading.Thread(target=listen,
                                         args=(
                                             user_list,
                                             message_hist,
                                         ))
        listen_thread.daemon = True
        listen_thread.start()
        message = ''
        l = int(
            input("Message Max Length == " + str(MAX_MESSAGE_LENGTH) +
                  "\nLength of string to send: "))
        n = int(input("Number of times to send full message: "))
        for i in range(l):
            message = message + str(i % 10)
        for i in range(n):
            at(('user1', '127.0.0.1'), message)
        return None
    # END LONG MESSAGE TESTING


# Main proper
    print("                     _   __     __             ____ ____   \n" +
          "   _____ ___  __  __/ | / /__  / /_    _   __  \  // __ \  \n" +
          "  /  __/ __ `/ / / /  |/ / _ \/ __/   | | / /  / // / / /  \n" +
          "  / /_/ /_/ / /_/ / /|  /  __/ /_     | |/ /  / // /_/ /   \n" +
          "  \__/\__,_/\__,_/_/ |_/\___/\__/     |___/  /_(_)____/    \n" +
          "\n")
    ##     ASCII TEXT ART FROM: http://patorjk.com/software/taag/#p=display&f=Slant
    # Select file to open
    while True:
        filename = input(
            "Enter TauNet filename, type 'new' to create new TauNet, or type '!EXIT' to exit.\n: >> "
        )
        if filename == '!EXIT':
            return None
        elif filename == 'new':
            user_list = user_func.u_list()
            user_list.input_u_list()
        else:
            try:
                open(filename)
            except IOError:
                print(filename + " does not exist.")
                if input("Would you like to create it? (y/n): ") == 'y':
                    user_list = user_func.u_list()
                    user_list.input_u_list(filename)
                    break
            else:
                user_list = user_func.u_list(filename)
                break

    # Set up local variables
    message_hist = messages.message_list()
    user_info = old_user = None
    # Set up global variable
    my_user_name = user_list.me
    key = user_list.key
    filename = user_list.filename
    input_message = "TauNet (" + filename + ") v" + TauNet_version + ">> "

    # Start Listening for incoming messages
    listen_thread = threading.Thread(target=listen,
                                     args=(
                                         user_list,
                                         message_hist,
                                     ))
    listen_thread.daemon = True
    listen_thread.start()

    # Menu loop
    while True:
        split_command = None
        command = input('\n' + input_message)
        if command == '':
            None  # Do nothing
        # Send a message to a user
        elif command[0] == '@':
            user_name, message = read_command(command)
            if (user_name != ''):
                old_user = user_info
                user_info = None
                user_info = user_list.search_users(user_name)
            if user_info:  #send the message
                at(user_info, message)
            else:
                user_info = old_user
                print("Error:\n * Invalid Command. ? for help."
                      )  ##Invalid user_name

        # Add a user to the list
        elif command[0] == '+':
            split_command = read_command(command)
            if (split_command[0] != '' and split_command[1] != ''
                    and user_func.valid_user(split_command[0])
                    and user_list.add_user(split_command)):
                user_list.write_file()
            else:
                print(
                    "Error:\n * Users name may only contain uppercase and lowercase letters from a-z, the numbers from 0-9, and the - symbol.\n * User names must also not have already been added to the list."
                )

        # Remove a user from the list
        elif command[0] == '-':
            if command == '-':
                print("Error:\n * Invalid Command. ? for help.")
            elif user_list.remove_user(command[1:]):
                user_list.write_file()
                user_info = None

        # Display the last n messages
        # or the last message
        elif command[0] == '#':
            try:
                lines = int(command[1:])
            except:
                lines = -1
            if lines > 0 and lines < 21:
                message_hist.print_n(lines)
            else:
                print(
                    "Error:\n * n must be a whole number from 1 to 20 represented in digits."
                )

        # Display the list of users
        elif command == '~':
            user_list.print_users()
            print()

        # Display help menue
        elif command == '?':
            help_menu()

        # Clear the Screen
        elif command == '!CLEAR':
            clear()

        # Exit the program
        elif command == '!EXIT':
            return

        #Invalid command
        else:
            print("Error:\n * Invalid Command. ? for help.")
    return None