diff options
author | Walter Purcaro <vuolter@gmail.com> | 2014-12-01 23:53:07 +0100 |
---|---|---|
committer | Walter Purcaro <vuolter@gmail.com> | 2014-12-01 23:53:07 +0100 |
commit | 004a80bfaad38f9400e8aebcb8f980353a232295 (patch) | |
tree | 1e786d2d14a3040767aac237982544b74a9567cb /pyload/manager/CaptchaManager.py | |
parent | Fix previous merge (diff) | |
download | pyload-004a80bfaad38f9400e8aebcb8f980353a232295.tar.xz |
PEP-8, Python Zen, refactor and reduce code (thx FedeG)
Diffstat (limited to 'pyload/manager/CaptchaManager.py')
-rw-r--r-- | pyload/manager/CaptchaManager.py | 26 |
1 files changed, 11 insertions, 15 deletions
diff --git a/pyload/manager/CaptchaManager.py b/pyload/manager/CaptchaManager.py index b89fb3136..955d35b43 100644 --- a/pyload/manager/CaptchaManager.py +++ b/pyload/manager/CaptchaManager.py @@ -24,13 +24,12 @@ from threading import Lock from pyload.utils import encode -class CaptchaManager: +class CaptchaManager(object): def __init__(self, core): self.lock = Lock() self.core = core - self.tasks = [] #task store, for outgoing tasks only - - self.ids = 0 #only for internal purpose + self.tasks = [] # task store, for outgoing tasks only + self.ids = 0 # only for internal purpose def newTask(self, img, format, file, result_type): task = CaptchaTask(self.ids, img, format, file, result_type) @@ -55,7 +54,7 @@ class CaptchaManager: def getTaskByID(self, tid): self.lock.acquire() for task in self.tasks: - if task.id == str(tid): #task ids are strings + if task.id == str(tid): # task ids are strings self.lock.release() return task self.lock.release() @@ -64,26 +63,24 @@ class CaptchaManager: def handleCaptcha(self, task, timeout=50): cli = self.core.isClientConnected() - if cli: #client connected -> should solve the captcha + if cli: #: client connected -> should solve the captcha task.setWaiting(timeout) #wait 50 sec for response for plugin in self.core.addonManager.activePlugins(): try: plugin.newCaptchaTask(task) - except: + except Exception: if self.core.debug: print_exc() - if task.handler or cli: #the captcha was handled + if task.handler or cli: #: the captcha was handled self.tasks.append(task) return True - task.error = _("No Client connected for captcha decrypting") - return False -class CaptchaTask: +class CaptchaTask(object): def __init__(self, id, img, format, file, result_type='textual'): self.id = str(id) self.captchaImg = img @@ -93,10 +90,9 @@ class CaptchaTask: self.handler = [] #: the hook plugins that will take care of the solution self.result = None self.waitUntil = None - self.error = None #error message - + self.error = None # error message self.status = "init" - self.data = {} #handler can store data here + self.data = {} # handler can store data here def getCaptcha(self): return self.captchaImg, self.captchaFormat, self.captchaResultType @@ -108,7 +104,7 @@ class CaptchaTask: try: parts = text.split(',') self.result = (int(parts[0]), int(parts[1])) - except: + except Exception: self.result = None def getResult(self): |