flags2_asyncio_executor.py closing http request
This commit is contained in:
parent
90daf6eb85
commit
3c25f1ed0f
@ -6,6 +6,7 @@ asyncio version using thread pool to save files
|
|||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
import collections
|
import collections
|
||||||
|
import contextlib
|
||||||
|
|
||||||
import aiohttp
|
import aiohttp
|
||||||
from aiohttp import web
|
from aiohttp import web
|
||||||
@ -28,15 +29,17 @@ class FetchError(Exception):
|
|||||||
def get_flag(base_url, cc):
|
def get_flag(base_url, cc):
|
||||||
url = '{}/{cc}/{cc}.gif'.format(base_url, cc=cc.lower())
|
url = '{}/{cc}/{cc}.gif'.format(base_url, cc=cc.lower())
|
||||||
resp = yield from aiohttp.request('GET', url)
|
resp = yield from aiohttp.request('GET', url)
|
||||||
if resp.status == 200:
|
with contextlib.closing(resp):
|
||||||
image = yield from resp.read()
|
if resp.status == 200:
|
||||||
return image
|
image = yield from resp.read()
|
||||||
elif resp.status == 404:
|
return image
|
||||||
raise web.HTTPNotFound()
|
elif resp.status == 404:
|
||||||
else:
|
raise web.HTTPNotFound()
|
||||||
raise aiohttp.HttpProcessingError(
|
else:
|
||||||
code=resp.status, message=resp.reason,
|
raise aiohttp.HttpProcessingError(
|
||||||
headers=resp.headers)
|
code=resp.status, message=resp.reason,
|
||||||
|
headers=resp.headers)
|
||||||
|
|
||||||
|
|
||||||
# BEGIN FLAGS2_ASYNCIO_EXECUTOR
|
# BEGIN FLAGS2_ASYNCIO_EXECUTOR
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
|
Loading…
Reference in New Issue
Block a user