IrcMiRCARTBot.py:_uploadToImgur(): prevent file object leak via `with' barrier.

MiRCARTCanvasExportStore.py:_exportFileToImgur(): prevent file object leak via `with' barrier.
This commit is contained in:
Lucio Andrés Illanes Albornoz 2018-01-26 22:38:28 +01:00
parent c6ab27c08c
commit 1a503979d1
2 changed files with 4 additions and 2 deletions

View File

@ -180,7 +180,8 @@ class IrcMiRCARTBot(IrcClient.IrcClient):
# }}} # }}}
# {{{ _uploadToImgur(self, imgFilePath, imgName, imgTitle, apiKey): Upload single file to Imgur # {{{ _uploadToImgur(self, imgFilePath, imgName, imgTitle, apiKey): Upload single file to Imgur
def _uploadToImgur(self, imgFilePath, imgName, imgTitle, apiKey): def _uploadToImgur(self, imgFilePath, imgName, imgTitle, apiKey):
requestImageData = open(imgFilePath, "rb").read() with open(imgFilePath, "rb") as requestImage:
requestImageData = requestImage.read()
requestData = { \ requestData = { \
"image": base64.b64encode(requestImageData), \ "image": base64.b64encode(requestImageData), \
"key": apiKey, \ "key": apiKey, \

View File

@ -42,7 +42,8 @@ class MiRCARTCanvasExportStore():
# {{{ _exportFileToImgur(self, apiKey, imgName, imgTitle, pathName): upload single PNG file to Imgur # {{{ _exportFileToImgur(self, apiKey, imgName, imgTitle, pathName): upload single PNG file to Imgur
def _exportFileToImgur(self, apiKey, imgName, imgTitle, pathName): def _exportFileToImgur(self, apiKey, imgName, imgTitle, pathName):
requestImageData = open(pathName, "rb").read() with open(pathName, "rb") as requestImage:
requestImageData = requestImage.read()
requestData = { \ requestData = { \
"image": base64.b64encode(requestImageData), \ "image": base64.b64encode(requestImageData), \
"key": apiKey, \ "key": apiKey, \