Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Dec 2, 2021. It is now read-only.

Commit 56094ef

Browse files
committed
flags2_asyncio with closing rehttp response
1 parent 333615d commit 56094ef

File tree

2 files changed

+6
-8
lines changed

2 files changed

+6
-8
lines changed

‎17-futures/countries/flags2_asyncio.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
# BEGIN FLAGS2_ASYNCIO_TOP
1919
import asyncio
2020
import collections
21-
fromcontextlibimport closing
21+
import contextlib
2222

2323
import aiohttp
2424
from aiohttp import web
@@ -41,7 +41,7 @@ def __init__(self, country_code):
4141
def get_flag(base_url, cc): # <2>
4242
url = '{}/{cc}/{cc}.gif'.format(base_url, cc=cc.lower())
4343
resp = yield from aiohttp.request('GET', url)
44-
with closing(resp):
44+
with contextlib.closing(resp):
4545
if resp.status == 200:
4646
image = yield from resp.read()
4747
return image

‎17-futures/countries/flags2_asyncio_executor.py‎

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,16 +81,14 @@ def downloader_coro(cc_list, base_url, verbose, concur_req):
8181
error_msg = exc.__cause__.args[0]
8282
except IndexError:
8383
error_msg = exc.__cause__.__class__.__name__
84+
if verbose and error_msg:
85+
msg = '*** Error for {}: {}'
86+
print(msg.format(country_code, error_msg))
87+
status = HTTPStatus.error
8488
else:
85-
error_msg = ''
8689
status = res.status
8790

88-
if error_msg:
89-
status = HTTPStatus.error
9091
counter[status] += 1
91-
if verbose and error_msg:
92-
msg = '*** Error for {}: {}'
93-
print(msg.format(country_code, error_msg))
9492

9593
return counter
9694

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /