#!/usr/bin/env python31# -*- coding: utf-8 -*-2#***************************************************************************3# _ _ ____ _4# Project ___| | | | _ \| |5# / __| | | | |_) | |6# | (__| |_| | _ <| |___7# \___|\___/|_| \_\_____|8#9# Copyright (C) Daniel Stenberg, <[email protected]>, et al.10#11# This software is licensed as described in the file COPYING, which12# you should have received as part of this distribution. The terms13# are also available at https://curl.se/docs/copyright.html.14#15# You may opt to use, copy, modify, merge, publish, distribute and/or sell16# copies of the Software, and permit persons to whom the Software is17# furnished to do so, under the terms of the COPYING file.18#19# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY20# KIND, either express or implied.21#22# SPDX-License-Identifier: curl23#24###########################################################################25#26# Python3 program to print all combination of size r in an array of size n.27# This is used to generate test lines in tests/ech_test.sh.28# This will be discarded in the process of moving from experimental,29# but is worth preserving for the moment in case of changes to the30# ECH command line args3132def CombinationRepetitionUtil(chosen, arr, badarr, index,33r, start, end):3435# Current combination is ready,36# print it37if index == r:38# figure out if result should be good or bad and39# print prefix, assuming $turl does support ECH so40# should work if given "positive" parameters41res = 142j = len(chosen) - 143while res and j >= 0:44if chosen[j] in badarr:45res = 046j = j - 147print("cli_test $turl 1", res, end = " ")48# print combination but eliminating any runs of49# two identical params50for j in range(r):51if j != 0 and chosen[j] != chosen[j-1]:52print(chosen[j], end = " ")5354print()55return5657# When no more elements are58# there to put in chosen[]59if start > n:60return6162# Current is included, put63# next at next location64chosen[index] = arr[start]6566# Current is excluded, replace it67# with next (Note that i+1 is passed,68# but index is not changed)69CombinationRepetitionUtil(chosen, arr, badarr, index + 1,70r, start, end)71CombinationRepetitionUtil(chosen, arr, badarr, index,72r, start + 1, end)7374# The main function that prints all75# combinations of size r in arr[] of76# size n. This function mainly uses77# CombinationRepetitionUtil()78def CombinationRepetition(arr, badarr, n, r):7980# A temporary array to store81# all combination one by one82chosen = [0] * r8384# Print all combination using85# temporary array 'chosen[]'86CombinationRepetitionUtil(chosen, arr, badarr, 0, r, 0, n)8788# Driver code89badarr = [ '--ech grease', '--ech false', '--ech ecl:$badecl', '--ech pn:$badpn' ]90goodarr = [ '--ech hard', '--ech true', '--ech ecl:$goodecl', '--ech pn:$goodpn' ]91arr = badarr + goodarr92r = 893n = len(arr) - 19495CombinationRepetition(arr, badarr, n, r)9697# This code is contributed by Vaibhav Kumar 12.9899100