Movatterモバイル変換


[0]ホーム

URL:


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

Commit56094ef

Browse files
committed
flags2_asyncio with closing rehttp response
1 parent333615d commit56094ef

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
importasyncio
2020
importcollections
21-
fromcontextlibimportclosing
21+
importcontextlib
2222

2323
importaiohttp
2424
fromaiohttpimportweb
@@ -41,7 +41,7 @@ def __init__(self, country_code):
4141
defget_flag(base_url,cc):# <2>
4242
url='{}/{cc}/{cc}.gif'.format(base_url,cc=cc.lower())
4343
resp=yieldfromaiohttp.request('GET',url)
44-
withclosing(resp):
44+
withcontextlib.closing(resp):
4545
ifresp.status==200:
4646
image=yieldfromresp.read()
4747
returnimage

‎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
exceptIndexError:
8383
error_msg=exc.__cause__.__class__.__name__
84+
ifverboseanderror_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-
iferror_msg:
89-
status=HTTPStatus.error
9091
counter[status]+=1
91-
ifverboseanderror_msg:
92-
msg='*** Error for {}: {}'
93-
print(msg.format(country_code,error_msg))
9492

9593
returncounter
9694

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp