Skip to content

Commit

Permalink
Rfi fixes (#157)
Browse files Browse the repository at this point in the history
* client session supports the context manager for self closing.

* delete duplicate function call
  • Loading branch information
afeena authored Jun 20, 2017
1 parent 9e20f5b commit 9f7adbd
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
15 changes: 6 additions & 9 deletions tanner/emulators/rfi.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,12 @@ async def download_file(self, path):

else:
try:
with aiohttp.ClientSession(loop=self._loop) as client:
resp = await client.get(url)
data = await resp.text()
async with aiohttp.ClientSession(loop=self._loop) as client:
async with await client.get(url) as resp:
data = await resp.text()
except aiohttp.ClientError as client_error:
self.logger.error('Error during downloading the rfi script %s', client_error)
else:
await resp.release()
await client.close()
tmp_filename = url.name + str(time.time())
file_name = hashlib.md5(tmp_filename.encode('utf-8')).hexdigest()
with open(os.path.join(self.script_dir, file_name), 'bw') as rfile:
Expand Down Expand Up @@ -79,10 +77,9 @@ async def get_rfi_result(self, path):
with open(os.path.join(self.script_dir, file_name), 'br') as script:
script_data = script.read()
try:
with aiohttp.ClientSession(loop=self._loop) as session:

resp = await session.post('http://127.0.0.1:8088/', data=script_data)
rfi_result = await resp.json()
async with aiohttp.ClientSession(loop=self._loop) as session:
async with session.post('http://127.0.0.1:8088/', data=script_data) as resp:
rfi_result = await resp.json()
except aiohttp.ClientError as client_error:
self.logger.error('Error during connection to php sandbox %s', client_error)
else:
Expand Down
1 change: 0 additions & 1 deletion tanner/session_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ async def delete_old_sessions(self, redis_client):
if not sess.is_expired():
continue
await sess.remove_associated_db()
sess.remove_associated_db()
await sess.remove_associated_env()
self.sessions.remove(sess)
try:
Expand Down

0 comments on commit 9f7adbd

Please sign in to comment.