From 7475f7108d3bd067bc15ca8a385ec737f1b67f88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucio=20Andr=C3=A9s=20Illanes=20Albornoz?= Date: Fri, 26 Jan 2018 22:38:28 +0100 Subject: [PATCH] IrcMiRCARTBot.py:_uploadToImgur(): prevent file object leak via `with' barrier. MiRCARTCanvasExportStore.py:_exportFileToImgur(): prevent file object leak via `with' barrier. --- IrcMiRCARTBot.py | 3 ++- MiRCARTCanvasExportStore.py | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/IrcMiRCARTBot.py b/IrcMiRCARTBot.py index b028c43..304cd97 100755 --- a/IrcMiRCARTBot.py +++ b/IrcMiRCARTBot.py @@ -180,7 +180,8 @@ class IrcMiRCARTBot(IrcClient.IrcClient): # }}} # {{{ _uploadToImgur(self, imgFilePath, imgName, imgTitle, apiKey): Upload single file to Imgur def _uploadToImgur(self, imgFilePath, imgName, imgTitle, apiKey): - requestImageData = open(imgFilePath, "rb").read() + with open(imgFilePath, "rb") as requestImage: + requestImageData = requestImage.read() requestData = { \ "image": base64.b64encode(requestImageData), \ "key": apiKey, \ diff --git a/MiRCARTCanvasExportStore.py b/MiRCARTCanvasExportStore.py index e7c520d..f8e7035 100644 --- a/MiRCARTCanvasExportStore.py +++ b/MiRCARTCanvasExportStore.py @@ -42,7 +42,8 @@ class MiRCARTCanvasExportStore(): # {{{ _exportFileToImgur(self, apiKey, imgName, imgTitle, pathName): upload single PNG file to Imgur def _exportFileToImgur(self, apiKey, imgName, imgTitle, pathName): - requestImageData = open(pathName, "rb").read() + with open(pathName, "rb") as requestImage: + requestImageData = requestImage.read() requestData = { \ "image": base64.b64encode(requestImageData), \ "key": apiKey, \