From 01e76034bcad5e5aab7f6e141782071e5c328649 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Sun, 6 Jul 2014 19:08:06 +0200 Subject: Fix account checkLogin + related code cosmetics --- module/plugins/Account.py | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) (limited to 'module/plugins/Account.py') diff --git a/module/plugins/Account.py b/module/plugins/Account.py index e75fc0ecb..f6c59ae25 100644 --- a/module/plugins/Account.py +++ b/module/plugins/Account.py @@ -36,16 +36,16 @@ class Account(Base): associated hoster plugin. Plugin should also provide `loadAccountInfo` """ __name__ = "Account" - __version__ = "0.2" + __version__ = "0.3" __type__ = "account" __description__ = """Base account plugin""" __author_name__ = "mkaay" __author_mail__ = "mkaay@mkaay.de" - #: after that time [in minutes] pyload will relogin the account - login_timeout = 600 - #: account data will be reloaded after this time - info_threshold = 600 + #: after that time (in minutes) pyload will relogin the account + login_timeout = 10 * 60 + #: after that time (in minutes) account data will be reloaded + info_threshold = 10 * 60 def __init__(self, manager, accounts): @@ -84,17 +84,20 @@ class Account(Base): self.logWarning( _("Could not login with account %(user)s | %(msg)s") % {"user": user , "msg": _("Wrong Password")}) - data["valid"] = False - + success = data["valid"] = False except Exception, e: self.logWarning( _("Could not login with account %(user)s | %(msg)s") % {"user": user , "msg": e}) - data["valid"] = False + success = data["valid"] = False if self.core.debug: print_exc() + else: + success = True finally: - if req: req.close() + if req: + req.close() + return success def relogin(self, user): req = self.getAccountRequest(user) @@ -104,7 +107,7 @@ class Account(Base): if user in self.infos: del self.infos[user] #delete old information - self._login(user, self.accounts[user]) + return self._login(user, self.accounts[user]) def setAccounts(self, accounts): self.accounts = accounts @@ -284,9 +287,10 @@ class Account(Base): def checkLogin(self, user): """ checks if user is still logged in """ if user in self.timestamps: - if self.timestamps[user] + self.login_timeout * 60 < time(): + if self.login_timeout > 0 and self.timestamps[user] + login_timeout * 60 > time(): self.logDebug("Reached login timeout for %s" % user) - self.relogin(user) - return False - - return True + return self.relogin(user) + else: + return True + else: + return False -- cgit v1.2.3 From c34ce034ceff9cd99e9e49c32128d090888d93cc Mon Sep 17 00:00:00 2001 From: Hoai-Thu Vuong Date: Tue, 8 Jul 2014 12:50:41 +0700 Subject: Update Account.py I running and received error no define of login_timeout, after adding self. it work perfectly --- module/plugins/Account.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'module/plugins/Account.py') diff --git a/module/plugins/Account.py b/module/plugins/Account.py index f6c59ae25..847a686ec 100644 --- a/module/plugins/Account.py +++ b/module/plugins/Account.py @@ -287,7 +287,7 @@ class Account(Base): def checkLogin(self, user): """ checks if user is still logged in """ if user in self.timestamps: - if self.login_timeout > 0 and self.timestamps[user] + login_timeout * 60 > time(): + if self.login_timeout > 0 and self.timestamps[user] + self.login_timeout * 60 > time(): self.logDebug("Reached login timeout for %s" % user) return self.relogin(user) else: -- cgit v1.2.3 From 01890bf1370b801dd95c97559530cb57321a3559 Mon Sep 17 00:00:00 2001 From: stickell Date: Sun, 13 Jul 2014 20:32:44 +0200 Subject: [Account] fixed bug introduced in 01e76034bcad5e5aab7f6e141782071e5c328649 --- module/plugins/Account.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'module/plugins/Account.py') diff --git a/module/plugins/Account.py b/module/plugins/Account.py index 847a686ec..abeafad3a 100644 --- a/module/plugins/Account.py +++ b/module/plugins/Account.py @@ -287,7 +287,7 @@ class Account(Base): def checkLogin(self, user): """ checks if user is still logged in """ if user in self.timestamps: - if self.login_timeout > 0 and self.timestamps[user] + self.login_timeout * 60 > time(): + if self.login_timeout > 0 and self.timestamps[user] + self.login_timeout * 60 < time(): self.logDebug("Reached login timeout for %s" % user) return self.relogin(user) else: -- cgit v1.2.3 From 5060e4c6374a5116d0d8b02528f910f8c5f8bcf9 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Tue, 15 Jul 2014 16:25:41 +0200 Subject: Fix code indentation, some bad whitespaces and missing authors + use 'not' instead 'is None' + replace __pattern__'s r" with r' + other minor cosmetics --- module/plugins/Account.py | 1 + 1 file changed, 1 insertion(+) (limited to 'module/plugins/Account.py') diff --git a/module/plugins/Account.py b/module/plugins/Account.py index abeafad3a..21f65816a 100644 --- a/module/plugins/Account.py +++ b/module/plugins/Account.py @@ -25,6 +25,7 @@ from threading import RLock from Plugin import Base from module.utils import compare_time, parseFileSize, lock + class WrongPassword(Exception): pass -- cgit v1.2.3 From a1495eb2f9502fdf29974458845f928025bedf53 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Sat, 26 Jul 2014 02:36:15 +0200 Subject: Prefer single quote for dict key --- module/plugins/Account.py | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) (limited to 'module/plugins/Account.py') diff --git a/module/plugins/Account.py b/module/plugins/Account.py index 21f65816a..c4d5c982c 100644 --- a/module/plugins/Account.py +++ b/module/plugins/Account.py @@ -85,12 +85,12 @@ class Account(Base): self.logWarning( _("Could not login with account %(user)s | %(msg)s") % {"user": user , "msg": _("Wrong Password")}) - success = data["valid"] = False + success = data['valid'] = False except Exception, e: self.logWarning( _("Could not login with account %(user)s | %(msg)s") % {"user": user , "msg": e}) - success = data["valid"] = False + success = data['valid'] = False if self.core.debug: print_exc() else: @@ -120,15 +120,15 @@ class Account(Base): """ updates account and return true if anything changed """ if user in self.accounts: - self.accounts[user]["valid"] = True #do not remove or accounts will not login + self.accounts[user]['valid'] = True #do not remove or accounts will not login if password: - self.accounts[user]["password"] = password + self.accounts[user]['password'] = password self.relogin(user) return True if options: - before = self.accounts[user]["options"] - self.accounts[user]["options"].update(options) - return self.accounts[user]["options"] != before + before = self.accounts[user]['options'] + self.accounts[user]['options'].update(options) + return self.accounts[user]['options'] != before else: self.accounts[user] = {"password": password, "options": options, "valid": True} self._login(user, self.accounts[user]) @@ -168,7 +168,7 @@ class Account(Base): self.logDebug("Account Info: %s" % str(infos)) - infos["timestamp"] = time() + infos['timestamp'] = time() self.infos[name] = infos elif "timestamp" in self.infos[name] and self.infos[name][ "timestamp"] + self.info_threshold * 60 < time(): @@ -180,7 +180,7 @@ class Account(Base): def isPremium(self, user): info = self.getAccountInfo(user) - return info["premium"] + return info['premium'] def loadAccountInfo(self, name, req=None): """this should be overwritten in account plugin,\ @@ -193,9 +193,9 @@ class Account(Base): return { "validuntil": None, # -1 for unlimited "login": name, - #"password": self.accounts[name]["password"], #@XXX: security - "options": self.accounts[name]["options"], - "valid": self.accounts[name]["valid"], + #"password": self.accounts[name]['password'], #@XXX: security + "options": self.accounts[name]['options'], + "valid": self.accounts[name]['valid'], "trafficleft": None, # in kb, -1 for unlimited "maxtraffic": None, "premium": True, #useful for free accounts @@ -231,12 +231,12 @@ class Account(Base): """ returns an valid account name and data""" usable = [] for user, data in self.accounts.iteritems(): - if not data["valid"]: continue + if not data['valid']: continue - if "time" in data["options"] and data["options"]["time"]: + if "time" in data['options'] and data['options']['time']: time_data = "" try: - time_data = data["options"]["time"][0] + time_data = data['options']['time'][0] start, end = time_data.split("-") if not compare_time(start.split(":"), end.split(":")): continue @@ -245,10 +245,10 @@ class Account(Base): if user in self.infos: if "validuntil" in self.infos[user]: - if self.infos[user]["validuntil"] > 0 and time() > self.infos[user]["validuntil"]: + if self.infos[user]['validuntil'] > 0 and time() > self.infos[user]['validuntil']: continue if "trafficleft" in self.infos[user]: - if self.infos[user]["trafficleft"] == 0: + if self.infos[user]['trafficleft'] == 0: continue usable.append((user, data)) -- cgit v1.2.3 From ba916633f2bedb04c7358000b91aed69f52e8e43 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Fri, 1 Aug 2014 19:35:59 +0200 Subject: Remove trailing whitespaces + remove license headers + import urllib methods directly + sort and fix key attributes + use save_join instead join + sort some import declarations + other minor code cosmetics --- module/plugins/Account.py | 22 +++------------------- 1 file changed, 3 insertions(+), 19 deletions(-) (limited to 'module/plugins/Account.py') diff --git a/module/plugins/Account.py b/module/plugins/Account.py index c4d5c982c..bd7f97cba 100644 --- a/module/plugins/Account.py +++ b/module/plugins/Account.py @@ -1,28 +1,11 @@ # -*- coding: utf-8 -*- -""" - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3 of the License, - or (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, see . - - @author: mkaay -""" - from random import choice from time import time from traceback import print_exc from threading import RLock -from Plugin import Base +from module.plugins.Plugin import Base from module.utils import compare_time, parseFileSize, lock @@ -37,8 +20,9 @@ class Account(Base): associated hoster plugin. Plugin should also provide `loadAccountInfo` """ __name__ = "Account" - __version__ = "0.3" __type__ = "account" + __version__ = "0.3" + __description__ = """Base account plugin""" __author_name__ = "mkaay" __author_mail__ = "mkaay@mkaay.de" -- cgit v1.2.3