コード例 #1
0
def test_delete_language(loaded_dictionary_temp_dir):
    """Test delete a language also removes its words."""
    language_to_remove = "german"
    Dictionary.remove_dictionary(language_to_remove,
                                 _database_path=loaded_dictionary_temp_dir)
    # Check all words from removed language have been removed too.
    not_existing_dictionary = Dictionary(language_to_remove,
                                         loaded_dictionary_temp_dir)
    not_existing_dictionary._open()
    assert all(not not_existing_dictionary.word_exists(word, _testing=True)
               for word in MICRO_DICTIONARIES[language_to_remove])
    not_existing_dictionary._close()
コード例 #2
0
def main(args=sys.argv[1:], _database_path=None) -> None:
    arguments: Dict[str, str] = parse_arguments(args)

    # DICTIONARY MANAGEMENT
    if arguments["mode"] == "dictionary":
        if arguments["action"] == "create":
            initial_words_file = arguments.get("initial_words_file", None)
            with Dictionary.open(arguments["dictionary_name"],
                                 create=True,
                                 _database_path=_database_path) as dictionary:
                if initial_words_file is not None:
                    dictionary.populate(initial_words_file)
        elif arguments["action"] == "delete":
            Dictionary.remove_dictionary(arguments["dictionary_name"],
                                         _database_path=_database_path)
        elif arguments["action"] == "update":
            with Dictionary.open(arguments["dictionary_name"],
                                 create=False,
                                 _database_path=_database_path) as dictionary:
                dictionary.populate(arguments["words_file"])
        elif arguments["action"] == "list":
            dictionaries = Dictionary.get_available_languages(
                _database_path=_database_path)
            for dictionary in dictionaries:
                print(dictionary)

    # CIPHERING MANAGEMENT
    elif arguments["mode"] == "cipher":
        ciphered_content = _process_file_with_key(
            arguments["file_to_cipher"],
            Algorithm.from_string(arguments["algorithm"]), arguments["key"],
            MessageOperation.from_string(arguments["mode"]),
            arguments["charset"] if "charset" in arguments else None)
        _output_result(ciphered_content, arguments)

    # DECIPHERING MANAGEMENT
    elif arguments["mode"] == "decipher":
        deciphered_content = _process_file_with_key(
            arguments["file_to_decipher"],
            Algorithm.from_string(arguments["algorithm"]), arguments["key"],
            MessageOperation.from_string(arguments["mode"]),
            arguments["charset"] if "charset" in arguments else None)
        _output_result(deciphered_content, arguments)

    # ATTACK MANAGEMENT
    elif arguments["mode"] == "attack":
        recovered_content = _attack_file(
            arguments["file_to_attack"],
            Algorithm.from_string(arguments["algorithm"]),
            arguments["charset"] if "charset" in arguments else None,
            _database_path=_database_path)
        _output_result(recovered_content, arguments)