From c2dce8f68a697ea961fa9583a1d76bb9e4c650ce Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Sat, 18 Oct 2014 15:19:27 +0300 Subject: [PATCH] uaiohttpclient: Add usage example. --- uaiohttpclient/example.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 uaiohttpclient/example.py diff --git a/uaiohttpclient/example.py b/uaiohttpclient/example.py new file mode 100644 index 00000000..e44dbb94 --- /dev/null +++ b/uaiohttpclient/example.py @@ -0,0 +1,28 @@ +# +# uaiohttpclient - fetch URL passed as command line argument. +# +import uasyncio as asyncio +import uaiohttpclient as aiohttp + + +def print_stream(resp): + print((yield from resp.read())) + return + while True: + line = yield from reader.readline() + if not line: + break + print(line.rstrip()) + +def run(url): + resp = yield from aiohttp.request("GET", url) + print(resp) + yield from print_stream(resp) + +import sys +import logging +logging.basicConfig(level=logging.INFO) +url = sys.argv[1] +loop = asyncio.get_event_loop() +loop.run_until_complete(run(url)) +loop.close()