Exemplo n.º 1
0
def add_default_return(definition, processed_conditions, implementation):
    """
    Modify source code to include a default return if no True key is present.
    :param definition: function def
    :param processed_conditions: obj containing dict with tables.
    :param implementation: source code
    :return: source code
    """
    if processed_conditions.default:
        return get_returning_implementation(implementation, definition, processed_conditions.default)
    elif not h.has_true_key(processed_conditions.tables):
        return get_returning_implementation(implementation, definition, False)

    return implementation
Exemplo n.º 2
0
    def change_keys_from_bool_to_int(d, new_key):
        """
        Changes the keys from booleans (True or False) to int(0 or 1)
        if a int(0 or 1) is present.
        :param d: dict
        :param new_key: a new key to be added to dict.
        :return: new dict
        """
        if helpers.var_is_1(new_key) and helpers.has_true_key(d):
            d[1] = d.pop(True, None)

        if helpers.var_is_0(new_key) and helpers.has_false_key(d):
            d[0] = d.pop(False, None)

        return d