edq.net.cli

 1import argparse
 2import typing
 3
 4import edq.net.exchange
 5import edq.net.request
 6
 7def set_cli_args(parser: argparse.ArgumentParser, extra_state: typing.Dict[str, typing.Any]) -> None:
 8    """
 9    Set common CLI arguments.
10    This is a sibling to init_from_args(), as the arguments set here can be interpreted there.
11    """
12
13    group = parser.add_argument_group('network options')
14
15    group.add_argument('--http-exchanges-cache-dir', dest = 'http_exchanges_cache_dir',
16        action = 'store', type = str, default = None,
17        help = 'If set, try to read HTTP responses from this directory before making a request.')
18
19    group.add_argument('--http-exchanges-clean-func', dest = 'http_exchanges_clean_func',
20        action = 'store', type = str, default = None,
21        help = 'If set, default all created exchanges to this modifier function.')
22
23    group.add_argument('--http-exchanges-finalize-func', dest = 'http_exchanges_finalize_func',
24        action = 'store', type = str, default = None,
25        help = 'If set, default all created exchanges to this finalize.')
26
27    group.add_argument('--http-exchanges-out-dir', dest = 'http_exchanges_out_dir',
28        action = 'store', type = str, default = None,
29        help = 'If set, write all outgoing HTTP requests as exchanges to this directory.')
30
31    group.add_argument('--https-no-verify', dest = 'https_no_verify',
32        action = 'store_true', default = False,
33        help = 'If set, skip HTTPS/SSL verification.')
34
35def init_from_args(
36        parser: argparse.ArgumentParser,
37        args: argparse.Namespace,
38        extra_state: typing.Dict[str, typing.Any]) -> None:
39    """
40    Take in args from a parser that was passed to set_cli_args(),
41    and call init() with the appropriate arguments.
42    """
43
44    if (args.http_exchanges_cache_dir is not None):
45        edq.net.request._exchanges_cache_dir = args.http_exchanges_cache_dir
46
47    if (args.http_exchanges_out_dir is not None):
48        edq.net.request._exchanges_out_dir = args.http_exchanges_out_dir
49
50    if (args.http_exchanges_clean_func is not None):
51        edq.net.exchange._exchanges_clean_func = args.http_exchanges_clean_func
52
53    if (args.http_exchanges_finalize_func is not None):
54        edq.net.exchange._exchanges_finalize_func = args.http_exchanges_finalize_func
55
56    if (args.https_no_verify):
57        edq.net.request._disable_https_verification()
def set_cli_args(parser: argparse.ArgumentParser, extra_state: Dict[str, Any]) -> None:
 8def set_cli_args(parser: argparse.ArgumentParser, extra_state: typing.Dict[str, typing.Any]) -> None:
 9    """
10    Set common CLI arguments.
11    This is a sibling to init_from_args(), as the arguments set here can be interpreted there.
12    """
13
14    group = parser.add_argument_group('network options')
15
16    group.add_argument('--http-exchanges-cache-dir', dest = 'http_exchanges_cache_dir',
17        action = 'store', type = str, default = None,
18        help = 'If set, try to read HTTP responses from this directory before making a request.')
19
20    group.add_argument('--http-exchanges-clean-func', dest = 'http_exchanges_clean_func',
21        action = 'store', type = str, default = None,
22        help = 'If set, default all created exchanges to this modifier function.')
23
24    group.add_argument('--http-exchanges-finalize-func', dest = 'http_exchanges_finalize_func',
25        action = 'store', type = str, default = None,
26        help = 'If set, default all created exchanges to this finalize.')
27
28    group.add_argument('--http-exchanges-out-dir', dest = 'http_exchanges_out_dir',
29        action = 'store', type = str, default = None,
30        help = 'If set, write all outgoing HTTP requests as exchanges to this directory.')
31
32    group.add_argument('--https-no-verify', dest = 'https_no_verify',
33        action = 'store_true', default = False,
34        help = 'If set, skip HTTPS/SSL verification.')

Set common CLI arguments. This is a sibling to init_from_args(), as the arguments set here can be interpreted there.

def init_from_args( parser: argparse.ArgumentParser, args: argparse.Namespace, extra_state: Dict[str, Any]) -> None:
36def init_from_args(
37        parser: argparse.ArgumentParser,
38        args: argparse.Namespace,
39        extra_state: typing.Dict[str, typing.Any]) -> None:
40    """
41    Take in args from a parser that was passed to set_cli_args(),
42    and call init() with the appropriate arguments.
43    """
44
45    if (args.http_exchanges_cache_dir is not None):
46        edq.net.request._exchanges_cache_dir = args.http_exchanges_cache_dir
47
48    if (args.http_exchanges_out_dir is not None):
49        edq.net.request._exchanges_out_dir = args.http_exchanges_out_dir
50
51    if (args.http_exchanges_clean_func is not None):
52        edq.net.exchange._exchanges_clean_func = args.http_exchanges_clean_func
53
54    if (args.http_exchanges_finalize_func is not None):
55        edq.net.exchange._exchanges_finalize_func = args.http_exchanges_finalize_func
56
57    if (args.https_no_verify):
58        edq.net.request._disable_https_verification()

Take in args from a parser that was passed to set_cli_args(), and call init() with the appropriate arguments.