asyncio: Add basic asyncio stream interface test.

pull/11/head
Paul Sokolovsky 2014-04-20 06:27:43 +03:00
rodzic 0adccf0ab1
commit f0ce7978ce
1 zmienionych plików z 25 dodań i 0 usunięć

Wyświetl plik

@ -0,0 +1,25 @@
import asyncio
@asyncio.coroutine
def print_http_headers(url):
reader, writer = yield from asyncio.open_connection(url, 80)
print(reader, writer)
print("================")
query = "GET / HTTP/1.0\r\n\r\n"
yield from writer.write(query.encode('latin-1'))
while True:
line = yield from reader.readline()
if not line:
break
if line:
print(line.rstrip())
import logging
logging.basicConfig(level=logging.INFO)
url = "google.com"
loop = asyncio.get_event_loop()
#task = asyncio.async(print_http_headers(url))
#loop.run_until_complete(task)
loop.call_soon(print_http_headers(url))
loop.run_forever()
loop.close()