summaryrefslogtreecommitdiffstats
path: root/pyload/manager/Captcha.py
diff options
context:
space:
mode:
authorGravatar Walter Purcaro <vuolter@users.noreply.github.com> 2015-04-13 17:20:59 +0200
committerGravatar Walter Purcaro <vuolter@users.noreply.github.com> 2015-04-13 17:20:59 +0200
commite00ef98491f79ae8aa972ae1473dae4a7b78c07e (patch)
tree31be0c7cdcebb61525bcc387bcf15d265a1c494a /pyload/manager/Captcha.py
parentFix except (diff)
downloadpyload-e00ef98491f79ae8aa972ae1473dae4a7b78c07e.tar.xz
Cleanup
Diffstat (limited to 'pyload/manager/Captcha.py')
-rw-r--r--pyload/manager/Captcha.py20
1 files changed, 20 insertions, 0 deletions
diff --git a/pyload/manager/Captcha.py b/pyload/manager/Captcha.py
index e54eacf30..0814cf78a 100644
--- a/pyload/manager/Captcha.py
+++ b/pyload/manager/Captcha.py
@@ -9,23 +9,27 @@ from pyload.utils import encode
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
+
def newTask(self, img, format, file, result_type):
task = CaptchaTask(self.ids, img, format, file, result_type)
self.ids += 1
return task
+
def removeTask(self, task):
self.lock.acquire()
if task in self.tasks:
self.tasks.remove(task)
self.lock.release()
+
def getTask(self):
self.lock.acquire()
for task in self.tasks:
@@ -35,6 +39,7 @@ class CaptchaManager(object):
self.lock.release()
return None
+
def getTaskByID(self, tid):
self.lock.acquire()
for task in self.tasks:
@@ -44,6 +49,7 @@ class CaptchaManager(object):
self.lock.release()
return None
+
def handleCaptcha(self, task, timeout=50):
cli = self.core.isClientConnected()
@@ -65,6 +71,7 @@ class CaptchaManager(object):
class CaptchaTask(object):
+
def __init__(self, id, img, format, file, result_type='textual'):
self.id = str(id)
self.captchaImg = img
@@ -78,9 +85,11 @@ class CaptchaTask(object):
self.status = "init"
self.data = {} # handler can store data here
+
def getCaptcha(self):
return self.captchaImg, self.captchaFormat, self.captchaResultType
+
def setResult(self, text):
if self.isTextual():
self.result = text
@@ -91,48 +100,59 @@ class CaptchaTask(object):
except Exception:
self.result = None
+
def getResult(self):
return encode(self.result)
+
def getStatus(self):
return self.status
+
def setWaiting(self, sec):
""" let the captcha wait secs for the solution """
self.waitUntil = max(time() + sec, self.waitUntil)
self.status = "waiting"
+
def isWaiting(self):
if self.result or self.error or self.timedOut():
return False
else:
return True
+
def isTextual(self):
""" returns if text is written on the captcha """
return self.captchaResultType == 'textual'
+
def isPositional(self):
""" returns if user have to click a specific region on the captcha """
return self.captchaResultType == 'positional'
+
def setWatingForUser(self, exclusive):
if exclusive:
self.status = "user"
else:
self.status = "shared-user"
+
def timedOut(self):
return time() > self.waitUntil
+
def invalid(self):
""" indicates the captcha was not correct """
for x in self.handler:
x.captchaInvalid(self)
+
def correct(self):
for x in self.handler:
x.captchaCorrect(self)
+
def __str__(self):
return "<CaptchaTask '%s'>" % self.id