<commit_before>#!/usr/bin/env python3

# Name: TUSCommandBuilder.py
# Description: Holds the command builder - the provider of xml formatted commands.
# Author: <NAME>.

import TUSDictionary

from xml.dom.minidom import Document

class CommandBuilderException(Exception):
    """ Exception for handling problems that occurred during the building of a command. """

    def __init__(self):
        """ TODO. """

        pass

class CommandBuilder:
    """ Builds xml commands basing upon the language dictionary. """

    def __init__(self):
        """ Initializes CommandBuilder. """

        pass

    def build(self, a_id_request, a_user_values, a_parameters_values):
        """ Builds a command.

        Requires three arguments:
        a_id_request        - the identifier of the request.
        a_user_values       - the values of the <user> element.
        a_parameters_values - the values of the <parameters> element.

        Returns a human readable xml command.

        """

        # Get the command schema from the dictionary.
        try:
            command_schema = TUSDictionary.COMMAND_SCHEMAS[a_id_request]

            # Create a document.
            command = Document()

            # Create the <request> element.
            request = command.createElement("request")
            command.appendChild(request)
            request.setAttribute("id", repr(command_schema[0]))

            # TODO: Temporary here, until ExecutorEcho will not need parameters.
            parameters = command.createElement("parameters")
            request.appendChild(parameters)

            if command_schema[1]:
                if len(command_schema[1]) != len(a_user_values):
                    raise CommandBuilderException()

                user = command.createElement("user")
                request.appendChild(user)

                login = command.createElement("login")
                user.appendChild(login)
                login.setAttribute("value", a_user_values[0])

                password = command.createElement("password")
                user.appendChild(password)
                password.setAttribute("value", a_user_values[1])

            if command_schema[2]:
                if len(command_schema[2]) != len(a_parameters_values):
                    raise CommandBuilderException()

                for (name, value) in zip(command_schema[2], a_parameters_values):
                    element = command.createElement(name)
                    parameters.appendChild(element)
                    element.setAttribute("value", value)

            # Return a newly created command in human readable format.
            return command.toprettyxml(indent="    ")

        except:
            raise CommandBuilderException()<commit_msg>Cosmetic change.<commit_after>#!/usr/bin/env python3

# Name: TUSCommandBuilder.py
# Description: Holds the command builder - the provider of xml formatted commands.
# Author: <NAME>.

import TUSDictionary

from xml.dom.minidom import Document

class CommandBuilderException(Exception):
    """ Exception for handling problems that occurred during the building of a command. """

    def __init__(self):
        """ TODO. """

        pass

class CommandBuilder:
    """ Builds xml commands basing upon the language dictionary. """

    def __init__(self):
        """ Initializes CommandBuilder. """

        pass

    def build(self, a_id_request, a_user_values, a_parameters_values):
        """ Builds a command.

        Requires three arguments:
        a_id_request        - the identifier of the request.
        a_user_values       - the values of the <user> element.
        a_parameters_values - the values of the <parameters> element.

        Returns a human readable xml command.

        """

        # Get the command schema from the dictionary.
        try:
            command_schema = TUSDictionary.COMMAND_SCHEMAS[a_id_request]

            # Create a document.
            command = Document()

            # Create the <request> element.
            request = command.createElement("request")
            command.appendChild(request)
            request.setAttribute("id", repr(command_schema[0]))

            # TODO: Temporary here, until ExecutorEcho will not need parameters.
            parameters = command.createElement("parameters")
            request.appendChild(parameters)

            if command_schema[1]:
                if len(command_schema[1]) != len(a_user_values):
                    raise CommandBuilderException()

                user = command.createElement("user")
                request.appendChild(user)

                login = command.createElement("login")
                user.appendChild(login)
                login.setAttribute("value", a_user_values[0])

                password = command.createElement("password")
                user.appendChild(password)
                password.setAttribute("value", a_user_values[1])

            if command_schema[2]:
                if len(command_schema[2]) != len(a_parameters_values):
                    raise CommandBuilderException()

                for (name, value) in zip(command_schema[2], a_parameters_values):
                    element = command.createElement(name)
                    parameters.appendChild(element)
                    element.setAttribute("value", value)

            # Return a newly created command in human readable format.
            return command.toprettyxml(indent = "    ")

        except:
            raise CommandBuilderException()
{'fraction_non_alphanumeric': 0.08553934810012606, 'fraction_numerical': 0.0032414910858995136, 'mean_word_length': 2.1254924029262803, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 10}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1996168', 'n_tokens_mistral': 1357, 'n_tokens_neox': 1284, 'n_words': 362}