-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
45 lines (30 loc) · 860 Bytes
/
utils.py
File metadata and controls
45 lines (30 loc) · 860 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import argparse
from functools import reduce
class Mapper(argparse.Action):
params = None
def __call__(self, parser, args, values, option_string=None):
proxy_types = set(values)
parameter_string = reduce(lambda string, t: string + str(self.params[t]), proxy_types, '')
setattr(args, self.dest, parameter_string)
class ProxyTypeMapper(Mapper):
params = {
'http': 'h',
'https': 's',
'socks4': '4',
'socks5': '5'
}
class AnonymityTypeMapper(Mapper):
params = {
'high': 4,
'avg': 3,
'low': 2
}
def args_to_params(args: dict):
params = '?'
ports = args.pop('ports')
if ports:
params += f'ports={",".join(ports)}&'
for key, value in args.items():
if value:
params += f'{key}={value}&'
return params