Skip to content

Commit

Permalink
Merge branch 'master' of github.com:KeepSafe/aiohttp
Browse files Browse the repository at this point in the history
  • Loading branch information
asvetlov committed Feb 28, 2016
2 parents 4e01955 + c4a7084 commit bcd4a85
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
6 changes: 3 additions & 3 deletions aiohttp/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ def main(argv):
type=int,
default="8080"
)
args, extra_args = arg_parser.parse_known_args(argv)
args, extra_argv = arg_parser.parse_known_args(argv)

# Import logic
mod_str, _, func_str = args.entry_func.partition(":")
Expand All @@ -368,9 +368,9 @@ def main(argv):
except AttributeError:
arg_parser.error("module %r has no attribute %r" % (mod_str, func_str))

app = func(extra_args)
app = func(extra_argv)
run_app(app, host=args.hostname, port=args.port)
arg_parser.exit(message="Stopped\n")

if __name__ == "__main__":
main(sys.argv)
main(sys.argv[1:])
4 changes: 2 additions & 2 deletions docs/web.rst
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ Command Line Interface (CLI)
:mod:`aiohttp.web` implements a basic CLI for quickly serving an
:class:`Application` in *development* over TCP/IP::

$ python -m aiohttp.web -H localhost -P 8080 package.module.init_func
$ python -m aiohttp.web -H localhost -P 8080 package.module:init_func

``package.module.init_func`` should be an importable :term:`callable` that
accepts a list of any non-parsed command-line arguments and returns an
:class:`Application` instance after setting it up::

def init_function(args):
def init_function(argv):
app = web.Application()
app.router.add_route("GET", "/", index_handler)
return app
Expand Down
10 changes: 5 additions & 5 deletions examples/web_app.py → examples/cli_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
Serve this app using::
$ python -m aiohttp.web -H localhost -P 8080 --repeat 10 web_app.init \
$ python -m aiohttp.web -H localhost -P 8080 --repeat 10 cli_app:init \
> "Hello World"
Here ``--repeat`` & ``"Hello World"`` are application specific command-line
arguments. `aiohttp.web` only parses & consumes the command-line arguments it
needs (i.e. ``-H``, ``-P`` & ``entry-func``) and passes on any additional
arguments to the `web_app.init` function for processing.
arguments to the `cli_app:init` function for processing.
"""

from aiohttp.web import Application, Response
Expand All @@ -22,7 +22,7 @@ def display_message(req):
return Response(text=text)


def init(args):
def init(argv):
arg_parser = ArgumentParser(
prog="aiohttp.web ...", description="Application CLI", add_help=False
)
Expand All @@ -45,10 +45,10 @@ def init(args):
help="show this message and exit", action="help"
)

parsed_args = arg_parser.parse_args(args)
args = arg_parser.parse_args(argv)

app = Application()
app["args"] = parsed_args
app["args"] = args
app.router.add_route('GET', '/', display_message)

return app

0 comments on commit bcd4a85

Please sign in to comment.