mirror of
https://github.com/lalbornoz/roar.git
synced 2024-11-26 08:56:36 +00:00
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:
parent
c6ab27c08c
commit
1a503979d1
@ -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, \
|
||||||
|
@ -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, \
|
||||||
|
Loading…
Reference in New Issue
Block a user