Skip to content

Commit

Permalink
Fix errors
Browse files Browse the repository at this point in the history
  • Loading branch information
m-bo-one committed Apr 10, 2018
1 parent 620c345 commit e87d7d7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
19 changes: 15 additions & 4 deletions aioethereum/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,10 @@ def _post(self, data):
# See https://www.python.org/dev/peps/pep-0492/#new-syntax

contextmanager = aiohttp.ClientSession(loop=self._loop)
session = yield from contextmanager.__aenter__()
try:
session = yield from contextmanager.__aenter__()
except AttributeError:
session = contextmanager.__enter__()
try:
with async_timeout.timeout(self._timeout, loop=self._loop):
# do not return just yet, the "else" branch needs to run too
Expand All @@ -117,11 +120,19 @@ def _post(self, data):
data=json.dumps(data),
headers={'Content-Type': 'application/json'}
)
except:
if not (yield from contextmanager.__aexit__(*sys.exc_info())):
except: # noqa
try:
exit = yield from contextmanager.__aexit__(*sys.exc_info())
except AttributeError:
exit = contextmanager.__exit__(*sys.exc_info())

if not exit:
raise
else:
yield from contextmanager.__aexit__(None, None, None)
try:
yield from contextmanager.__aexit__(None, None, None)
except AttributeError:
contextmanager.__exit__(None, None, None)
return r

@asyncio.coroutine
Expand Down
2 changes: 1 addition & 1 deletion tests/test_http_rpc_call.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
@pytest.mark.run_loop
def test_rpc_call_with_conn_error(create_ethereum_client, loop, server):
with mock.patch("aiohttp.client.ClientSession._request") as patched:
patched.side_effect = aiohttp.ClientConnectorError('refused')
patched.side_effect = aiohttp.ClientConnectorError('refused', 'ref')
client = yield from create_ethereum_client(server.http_address,
loop=loop)
with pytest.raises(ConnectionError) as excinfo:
Expand Down

0 comments on commit e87d7d7

Please sign in to comment.