edq.cli.http.exchange-server

Start an HTTP test server that serves the specified HTTP exchanges.

usage: python3 -m edq.cli.http.exchange-server [-h] [--port PORT]
                                               [--ignore-param IGNORE_PARAMS]
                                               [--ignore-header IGNORE_HEADERS]
                                               PATH [PATH ...]

Start an HTTP test server that serves the specified HTTP exchanges.

positional arguments:
  PATH                  Path to exchange files or dirs (which will be
                        recursively searched for all exchange files).

options:
  -h, --help            show this help message and exit

server options:
  --port PORT           The port to run this test server on. If not set, a
                        random open port will be chosen.
  --ignore-param IGNORE_PARAMS
                        Ignore this parameter during exchange matching.
  --ignore-header IGNORE_HEADERS
                        Ignore this header during exchange matching.
 1# pylint: disable=invalid-name
 2
 3"""
 4Start an HTTP test server that serves the specified HTTP exchanges.
 5"""
 6
 7import argparse
 8import os
 9import sys
10
11import edq.core.argparser
12import edq.net.exchangeserver
13
14def run_cli(args: argparse.Namespace) -> int:
15    """ Run the CLI. """
16
17    match_options = {
18        'params_to_skip': args.ignore_params,
19        'headers_to_skip': args.ignore_headers,
20    }
21
22    server = edq.net.exchangeserver.HTTPExchangeServer(
23            port = args.port,
24            match_options = match_options,
25            verbose = True,
26            raise_on_404 = False,
27    )
28
29    for path in args.paths:
30        path = os.path.abspath(path)
31
32        if (os.path.isfile(path)):
33            server.load_exchange(path)
34        else:
35            server.load_exchanges_dir(path)
36
37    server.start_and_wait()
38
39    return 0
40
41def main() -> int:
42    """ Get a parser, parse the args, and call run. """
43    return run_cli(_get_parser().parse_args())
44
45def _get_parser() -> argparse.ArgumentParser:
46    """ Get the parser. """
47
48    parser = edq.core.argparser.get_default_parser(__doc__.strip(),
49            include_net = True,
50    )
51
52    parser.add_argument('paths', metavar = 'PATH',
53        type = str, nargs = '+',
54        help = 'Path to exchange files or dirs (which will be recursively searched for all exchange files).')
55
56    group = parser.add_argument_group('server options')
57
58    group.add_argument('--port', dest = 'port',
59        action = 'store', type = int, default = None,
60        help = 'The port to run this test server on. If not set, a random open port will be chosen.')
61
62    group.add_argument('--ignore-param', dest = 'ignore_params',
63        action = 'append', type = str, default = [],
64        help = 'Ignore this parameter during exchange matching.')
65
66    group.add_argument('--ignore-header', dest = 'ignore_headers',
67        action = 'append', type = str, default = [],
68        help = 'Ignore this header during exchange matching.')
69
70    return parser
71
72if (__name__ == '__main__'):
73    sys.exit(main())
def run_cli(args: argparse.Namespace) -> int:
15def run_cli(args: argparse.Namespace) -> int:
16    """ Run the CLI. """
17
18    match_options = {
19        'params_to_skip': args.ignore_params,
20        'headers_to_skip': args.ignore_headers,
21    }
22
23    server = edq.net.exchangeserver.HTTPExchangeServer(
24            port = args.port,
25            match_options = match_options,
26            verbose = True,
27            raise_on_404 = False,
28    )
29
30    for path in args.paths:
31        path = os.path.abspath(path)
32
33        if (os.path.isfile(path)):
34            server.load_exchange(path)
35        else:
36            server.load_exchanges_dir(path)
37
38    server.start_and_wait()
39
40    return 0

Run the CLI.

def main() -> int:
42def main() -> int:
43    """ Get a parser, parse the args, and call run. """
44    return run_cli(_get_parser().parse_args())

Get a parser, parse the args, and call run.