This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import asyncio | |
import aiohttp | |
async def f(sem, client, url): | |
async with sem: | |
with async_timeout.timeout(5): | |
async with client.get(url) as resp: | |
print(resp.status) | |
print(await resp.text()) # resp.context.read(1024) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async def f(url): | |
txt = await get_url(url) | |
return txt | |
task = ensure_future(f()) | |
await task | |
tasks = [t] | |
for t in tasks: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from aiohttp import web, web2, web_reqrep2 | |
async def handle(request): | |
name = request.match_info.get('name', "Anonymous") | |
text = "Hello, " + name | |
# push promise | |
# add Link header in case of HTTP 1.1 | |
# start sending response after push request |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async def fetch(session, url): | |
async with session.get(url) as resp: | |
if resp.headers['Content-Type'] != 'plain/text': | |
resp.close() | |
else: | |
text = await resp.text() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
import asyncio | |
import aioredis | |
from aiohttp import web | |
import json | |
@asyncio.coroutine | |
def ulist(request): | |
data = yield from request.json() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Elpy Error | |
The backend encountered an unexpected error. This indicates a bug in | |
Elpy. Please open a bug report with the data below in the Elpy bug | |
tracker: | |
https://github.com/jorgenschaefer/elpy/issues/new | |
``` | |
Error Message |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import itertools | |
from aiohttp import CIMultiDict | |
import tracemalloc | |
def leaking(headers): | |
headers = ''.join(itertools.chain( | |
('status line',), | |
*((k, ': ', v, '\r\n') for k, v in headers.items()))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import asyncio | |
import warnings | |
class Timeout: | |
def __init__(self, timeout, *, raise_error=False, loop=None): | |
self._timeout = timeout | |
if loop is None: | |
loop = asyncio.get_event_loop() | |
self._loop = loop |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import aiohttp | |
import asyncio | |
class MyClass: | |
def __init__(self): | |
self.data = {'username': 'me', 'password': 'pw'} | |
self.login_url = 'http://example.com/login' | |
self.client = aiohttp.ClientSession() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def f(): | |
future = asyncio.Future() | |
future.set_result(5) | |
return future # yield from f() returns 5. | |
def g(): | |
future = asyncio.Future() | |
asyncio.get_event_loop.call_later(1, future.set_result, 5) | |
return future # yield from g() also returns 5 but 1 second later |