flags2_asyncio with closing rehttp response

This commit is contained in:
Luciano Ramalho
2015-07-14 00:22:05 -03:00
parent 333615d051
commit 56094ef0f0
2 changed files with 6 additions and 8 deletions

View File

@@ -18,7 +18,7 @@ Sample run::
# BEGIN FLAGS2_ASYNCIO_TOP
import asyncio
import collections
from contextlib import closing
import contextlib
import aiohttp
from aiohttp import web
@@ -41,7 +41,7 @@ class FetchError(Exception): # <1>
def get_flag(base_url, cc): # <2>
url = '{}/{cc}/{cc}.gif'.format(base_url, cc=cc.lower())
resp = yield from aiohttp.request('GET', url)
with closing(resp):
with contextlib.closing(resp):
if resp.status == 200:
image = yield from resp.read()
return image