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 85cbffbadb
commit 7475f7108d
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
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, \

View File

@ -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, \