Skip to content

Commit

Permalink
Proposed fix for issue fluentpython#25 of fluentpython/example-code repo
Browse files Browse the repository at this point in the history
The changes to 17-futures/countries/flags_asyncio.py allow it to work
with Python 3.6.6 and aiohttp 3.4.4.
  • Loading branch information
cdm-work committed Sep 20, 2018
1 parent 3d74f0e commit d8b9688
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions 17-futures/countries/flags_asyncio.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,16 @@
from flags import BASE_URL, save_flag, show, main # <2>


@asyncio.coroutine # <3>
def get_flag(cc):
async def get_flag(session, cc):
url = '{}/{cc}/{cc}.gif'.format(BASE_URL, cc=cc.lower())
resp = yield from aiohttp.request('GET', url) # <4>
image = yield from resp.read() # <5>
async with session.get(url) as resp:
image = await resp.read() # <5>
return image


@asyncio.coroutine
def download_one(cc): # <6>
image = yield from get_flag(cc) # <7>
async def download_one(cc): # <6>
async with aiohttp.ClientSession() as session:
image = await get_flag(session, cc) # <7>
show(cc)
save_flag(image, cc.lower() + '.gif')
return cc
Expand Down

0 comments on commit d8b9688

Please sign in to comment.