1*6236dae4SAndroid Build Coastguard Worker#!/usr/bin/env python3 2*6236dae4SAndroid Build Coastguard Worker# -*- coding: utf-8 -*- 3*6236dae4SAndroid Build Coastguard Worker#*************************************************************************** 4*6236dae4SAndroid Build Coastguard Worker# _ _ ____ _ 5*6236dae4SAndroid Build Coastguard Worker# Project ___| | | | _ \| | 6*6236dae4SAndroid Build Coastguard Worker# / __| | | | |_) | | 7*6236dae4SAndroid Build Coastguard Worker# | (__| |_| | _ <| |___ 8*6236dae4SAndroid Build Coastguard Worker# \___|\___/|_| \_\_____| 9*6236dae4SAndroid Build Coastguard Worker# 10*6236dae4SAndroid Build Coastguard Worker# Copyright (C) Daniel Stenberg, <[email protected]>, et al. 11*6236dae4SAndroid Build Coastguard Worker# 12*6236dae4SAndroid Build Coastguard Worker# This software is licensed as described in the file COPYING, which 13*6236dae4SAndroid Build Coastguard Worker# you should have received as part of this distribution. The terms 14*6236dae4SAndroid Build Coastguard Worker# are also available at https://curl.se/docs/copyright.html. 15*6236dae4SAndroid Build Coastguard Worker# 16*6236dae4SAndroid Build Coastguard Worker# You may opt to use, copy, modify, merge, publish, distribute and/or sell 17*6236dae4SAndroid Build Coastguard Worker# copies of the Software, and permit persons to whom the Software is 18*6236dae4SAndroid Build Coastguard Worker# furnished to do so, under the terms of the COPYING file. 19*6236dae4SAndroid Build Coastguard Worker# 20*6236dae4SAndroid Build Coastguard Worker# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY 21*6236dae4SAndroid Build Coastguard Worker# KIND, either express or implied. 22*6236dae4SAndroid Build Coastguard Worker# 23*6236dae4SAndroid Build Coastguard Worker# SPDX-License-Identifier: curl 24*6236dae4SAndroid Build Coastguard Worker# 25*6236dae4SAndroid Build Coastguard Worker########################################################################### 26*6236dae4SAndroid Build Coastguard Worker# 27*6236dae4SAndroid Build Coastguard Worker# Python3 program to print all combination of size r in an array of size n. 28*6236dae4SAndroid Build Coastguard Worker# This is used to generate test lines in tests/ech_test.sh. 29*6236dae4SAndroid Build Coastguard Worker# This will be discarded in the process of moving from experimental, 30*6236dae4SAndroid Build Coastguard Worker# but is worth preserving for the moment in case of changes to the 31*6236dae4SAndroid Build Coastguard Worker# ECH command line args 32*6236dae4SAndroid Build Coastguard Worker 33*6236dae4SAndroid Build Coastguard Workerdef CombinationRepetitionUtil(chosen, arr, badarr, index, 34*6236dae4SAndroid Build Coastguard Worker r, start, end): 35*6236dae4SAndroid Build Coastguard Worker 36*6236dae4SAndroid Build Coastguard Worker # Current combination is ready, 37*6236dae4SAndroid Build Coastguard Worker # print it 38*6236dae4SAndroid Build Coastguard Worker if index == r: 39*6236dae4SAndroid Build Coastguard Worker # figure out if result should be good or bad and 40*6236dae4SAndroid Build Coastguard Worker # print prefix, assuming $turl does support ECH so 41*6236dae4SAndroid Build Coastguard Worker # should work if given "positive" parameters 42*6236dae4SAndroid Build Coastguard Worker res = 1 43*6236dae4SAndroid Build Coastguard Worker j = len(chosen) - 1 44*6236dae4SAndroid Build Coastguard Worker while res and j >= 0: 45*6236dae4SAndroid Build Coastguard Worker if chosen[j] in badarr: 46*6236dae4SAndroid Build Coastguard Worker res = 0 47*6236dae4SAndroid Build Coastguard Worker j = j - 1 48*6236dae4SAndroid Build Coastguard Worker print("cli_test $turl 1", res, end = " ") 49*6236dae4SAndroid Build Coastguard Worker # print combination but eliminating any runs of 50*6236dae4SAndroid Build Coastguard Worker # two identical params 51*6236dae4SAndroid Build Coastguard Worker for j in range(r): 52*6236dae4SAndroid Build Coastguard Worker if j != 0 and chosen[j] != chosen[j-1]: 53*6236dae4SAndroid Build Coastguard Worker print(chosen[j], end = " ") 54*6236dae4SAndroid Build Coastguard Worker 55*6236dae4SAndroid Build Coastguard Worker print() 56*6236dae4SAndroid Build Coastguard Worker return 57*6236dae4SAndroid Build Coastguard Worker 58*6236dae4SAndroid Build Coastguard Worker # When no more elements are 59*6236dae4SAndroid Build Coastguard Worker # there to put in chosen[] 60*6236dae4SAndroid Build Coastguard Worker if start > n: 61*6236dae4SAndroid Build Coastguard Worker return 62*6236dae4SAndroid Build Coastguard Worker 63*6236dae4SAndroid Build Coastguard Worker # Current is included, put 64*6236dae4SAndroid Build Coastguard Worker # next at next location 65*6236dae4SAndroid Build Coastguard Worker chosen[index] = arr[start] 66*6236dae4SAndroid Build Coastguard Worker 67*6236dae4SAndroid Build Coastguard Worker # Current is excluded, replace it 68*6236dae4SAndroid Build Coastguard Worker # with next (Note that i+1 is passed, 69*6236dae4SAndroid Build Coastguard Worker # but index is not changed) 70*6236dae4SAndroid Build Coastguard Worker CombinationRepetitionUtil(chosen, arr, badarr, index + 1, 71*6236dae4SAndroid Build Coastguard Worker r, start, end) 72*6236dae4SAndroid Build Coastguard Worker CombinationRepetitionUtil(chosen, arr, badarr, index, 73*6236dae4SAndroid Build Coastguard Worker r, start + 1, end) 74*6236dae4SAndroid Build Coastguard Worker 75*6236dae4SAndroid Build Coastguard Worker# The main function that prints all 76*6236dae4SAndroid Build Coastguard Worker# combinations of size r in arr[] of 77*6236dae4SAndroid Build Coastguard Worker# size n. This function mainly uses 78*6236dae4SAndroid Build Coastguard Worker# CombinationRepetitionUtil() 79*6236dae4SAndroid Build Coastguard Workerdef CombinationRepetition(arr, badarr, n, r): 80*6236dae4SAndroid Build Coastguard Worker 81*6236dae4SAndroid Build Coastguard Worker # A temporary array to store 82*6236dae4SAndroid Build Coastguard Worker # all combination one by one 83*6236dae4SAndroid Build Coastguard Worker chosen = [0] * r 84*6236dae4SAndroid Build Coastguard Worker 85*6236dae4SAndroid Build Coastguard Worker # Print all combination using 86*6236dae4SAndroid Build Coastguard Worker # temporary array 'chosen[]' 87*6236dae4SAndroid Build Coastguard Worker CombinationRepetitionUtil(chosen, arr, badarr, 0, r, 0, n) 88*6236dae4SAndroid Build Coastguard Worker 89*6236dae4SAndroid Build Coastguard Worker# Driver code 90*6236dae4SAndroid Build Coastguard Workerbadarr = [ '--ech grease', '--ech false', '--ech ecl:$badecl', '--ech pn:$badpn' ] 91*6236dae4SAndroid Build Coastguard Workergoodarr = [ '--ech hard', '--ech true', '--ech ecl:$goodecl', '--ech pn:$goodpn' ] 92*6236dae4SAndroid Build Coastguard Workerarr = badarr + goodarr 93*6236dae4SAndroid Build Coastguard Workerr = 8 94*6236dae4SAndroid Build Coastguard Workern = len(arr) - 1 95*6236dae4SAndroid Build Coastguard Worker 96*6236dae4SAndroid Build Coastguard WorkerCombinationRepetition(arr, badarr, n, r) 97*6236dae4SAndroid Build Coastguard Worker 98*6236dae4SAndroid Build Coastguard Worker# This code is contributed by Vaibhav Kumar 12. 99