Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# Extra arguments
parser.add_argument(
'args', metavar='ARGS', nargs=argparse.REMAINDER,
help='extra arguments')
namespace = parser.parse_args(args)
# If module is provided, filname is actually the fist arg
if namespace.module is not None and namespace.filename is not None:
namespace.args.insert(0, namespace.filename)
# Parse the serve argument
if namespace.serve is not None:
namespace.serve = server.parse_server(namespace.serve, parser)
return namespace
description="Run the echo server and a command line interface.")
parser.add_argument(
'server',
metavar='[HOST:]PORT',
type=str,
help='interface for the echo server, default host is localhost')
parser.add_argument(
'--serve-cli',
metavar='[HOST:]PORT',
type=str,
help='serve the command line interface on the given host+port '
'instead of using the standard streams')
namespace = parser.parse_args(args)
host, port = parse_server(namespace.server, parser)
if namespace.serve_cli is not None:
serve_cli = parse_server(namespace.serve_cli, parser)
else:
serve_cli = None
return host, port, serve_cli
def parse_args(args=None):
parser = argparse.ArgumentParser(
description="Run the echo server and a command line interface.")
parser.add_argument(
'server',
metavar='[HOST:]PORT',
type=str,
help='interface for the echo server, default host is localhost')
parser.add_argument(
'--serve-cli',
metavar='[HOST:]PORT',
type=str,
help='serve the command line interface on the given host+port '
'instead of using the standard streams')
namespace = parser.parse_args(args)
host, port = parse_server(namespace.server, parser)
if namespace.serve_cli is not None:
serve_cli = parse_server(namespace.serve_cli, parser)
else:
serve_cli = None
return host, port, serve_cli