Exemplo n.º 1
0
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")
user_list.write_file()
print("Reading test_file.txt in to new user_list")
user_list_2 = user_func.u_list('test_file.txt')
print("key: " + user_list_2.key + "\nme: " + user_list_2.me)
print("users in user_list_2")
user_list_2.print_users()
wait = input("[Enter to Contine]")
wait = None
print("Testing Valid User Names\nUser Name | Expected | Result")
print("Borders of charactes in range")
print("aAzZ09- | True | ", str(user_func.valid_user('aAzZ09-')))
print("User Name Lengths")
print("123456789012345678901234567890 (len = 30) | True | ",
      str(user_func.valid_user('123456789012345678901234567890')))
print("1234567890123456789012345678901 (len = 31 )| False | ",
      str(user_func.valid_user('1234567890123456789012345678901')))
print("12 | False | ", str(user_func.valid_user('12')))
print("123 | True | ", str(user_func.valid_user('123')))
print("Borders of characters out of range")
print("user/ | False | ", str(user_func.valid_user('user/')))
print("user: | False | ", str(user_func.valid_user('user:'******'user@')))
print("user[ | False | ", str(user_func.valid_user('user[')))
print("user` | False | ", str(user_func.valid_user("user`")))
print("user{ | False | ", str(user_func.valid_user('user{')))
Exemplo n.º 2
0
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")
user_list.write_file()
print("Reading test_file.txt in to new user_list")
user_list_2 = user_func.u_list('test_file.txt')
print("key: " + user_list_2.key + "\nme: " + user_list_2.me)
print("users in user_list_2")
user_list_2.print_users()
wait = input("[Enter to Contine]")
wait = None
print("Testing Valid User Names\nUser Name | Expected | Result")
print("Borders of charactes in range")
print("aAzZ09- | True | ", str(user_func.valid_user('aAzZ09-')))
print("User Name Lengths")
print("123456789012345678901234567890 (len = 30) | True | ", str(user_func.valid_user('123456789012345678901234567890')))
print("1234567890123456789012345678901 (len = 31 )| False | ", str(user_func.valid_user('1234567890123456789012345678901')))
print("12 | False | ", str(user_func.valid_user('12')))
print("123 | True | ", str(user_func.valid_user('123')))
print("Borders of characters out of range")
print("user/ | False | ", str(user_func.valid_user('user/')))
print("user: | False | ", str(user_func.valid_user('user:'******'user@')))
print("user[ | False | ", str(user_func.valid_user('user[')))
print("user` | False | ", str(user_func.valid_user("user`")))
print("user{ | False | ", str(user_func.valid_user('user{')))


print("<<<< <<<< <<<< Testing main.py >>>> >>>> >>>>")
Exemplo n.º 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
Exemplo n.º 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