summaryrefslogtreecommitdiffstats
path: root/module/plugins/hooks/ExtractArchive.py
diff options
context:
space:
mode:
authorGravatar Walter Purcaro <vuolter@gmail.com> 2014-11-09 03:08:19 +0100
committerGravatar Walter Purcaro <vuolter@gmail.com> 2014-11-09 03:08:19 +0100
commitbd8259220ab4d56ab419b7b32045b08cc9b0a7c8 (patch)
tree92f1c69d4280f8f57021083dbf878e62033eb502 /module/plugins/hooks/ExtractArchive.py
parentCookie support for getURL method (diff)
downloadpyload-bd8259220ab4d56ab419b7b32045b08cc9b0a7c8.tar.xz
Use with statement instead open method when accessing fod + handle i/o error
Diffstat (limited to 'module/plugins/hooks/ExtractArchive.py')
-rw-r--r--module/plugins/hooks/ExtractArchive.py33
1 files changed, 19 insertions, 14 deletions
diff --git a/module/plugins/hooks/ExtractArchive.py b/module/plugins/hooks/ExtractArchive.py
index 3d6df5b02..39da1ee7b 100644
--- a/module/plugins/hooks/ExtractArchive.py
+++ b/module/plugins/hooks/ExtractArchive.py
@@ -309,16 +309,18 @@ class ExtractArchive(Hook):
def reloadPasswords(self):
passwordfile = self.getConfig("passwordfile")
- if not exists(passwordfile):
- open(passwordfile, "wb").close()
-
- passwords = []
- f = open(passwordfile, "rb")
- for pw in f.read().splitlines():
- passwords.append(pw)
- f.close()
-
- self.passwords = passwords
+
+ try:
+ passwords = []
+ with open(passwordfile, "a+") as f:
+ for pw in f.read().splitlines():
+ passwords.append(pw)
+
+ except IOError, e:
+ self.logError(str(e))
+
+ else:
+ self.passwords = passwords
@Expose
@@ -328,12 +330,15 @@ class ExtractArchive(Hook):
if pw in self.passwords:
self.passwords.remove(pw)
+
self.passwords.insert(0, pw)
- f = open(passwordfile, "wb")
- for pw in self.passwords:
- f.write(pw + "\n")
- f.close()
+ try:
+ with open(passwordfile, "wb") as f:
+ for pw in self.passwords:
+ f.write(pw + "\n")
+ except IOError, e:
+ self.logError(str(e))
def setPermissions(self, files):