From bd8259220ab4d56ab419b7b32045b08cc9b0a7c8 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Sun, 9 Nov 2014 03:08:19 +0100 Subject: Use with statement instead open method when accessing fod + handle i/o error --- module/plugins/hoster/MegaCoNz.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'module/plugins/hoster/MegaCoNz.py') diff --git a/module/plugins/hoster/MegaCoNz.py b/module/plugins/hoster/MegaCoNz.py index 70688c26a..9b120827c 100644 --- a/module/plugins/hoster/MegaCoNz.py +++ b/module/plugins/hoster/MegaCoNz.py @@ -48,9 +48,9 @@ class MegaCoNz(Hoster): # generate a session id, no idea where to obtain elsewhere uid = random.randint(10 << 9, 10 ** 10) - resp = self.load(self.API_URL % uid, post=json_dumps([kwargs])) - self.logDebug("Api Response: " + resp) - return json_loads(resp) + res = self.load(self.API_URL % uid, post=json_dumps([kwargs])) + self.logDebug("Api Response: " + res) + return json_loads(res) def decryptAttr(self, data, key): @@ -78,8 +78,12 @@ class MegaCoNz(Hoster): file_crypted = self.lastDownload file_decrypted = file_crypted.rsplit(self.FILE_SUFFIX)[0] - f = open(file_crypted, "rb") - df = open(file_decrypted, "wb") + + try: + f = open(file_crypted, "rb") + df = open(file_decrypted, "wb") + except IOError, e: + self.fail(str(e)) # TODO: calculate CBC-MAC for checksum -- cgit v1.2.3