summaryrefslogtreecommitdiffstats
path: root/module/CaptchaManager.py
diff options
context:
space:
mode:
authorGravatar mkaay <mkaay@mkaay.de> 2009-12-30 12:35:03 +0100
committerGravatar mkaay <mkaay@mkaay.de> 2009-12-30 12:35:03 +0100
commitc1516088e4e7f76dddd68ef71f58c6413862e31c (patch)
tree9e392f79fc225934b8a0a99cc4a119332b6685e0 /module/CaptchaManager.py
parentmessed up last commit message; added new icons, default connection in gui, pu... (diff)
downloadpyload-c1516088e4e7f76dddd68ef71f58c6413862e31c.tar.xz
show captchas in gui, SerienjunkiesOrg plugin
Diffstat (limited to 'module/CaptchaManager.py')
-rw-r--r--module/CaptchaManager.py112
1 files changed, 112 insertions, 0 deletions
diff --git a/module/CaptchaManager.py b/module/CaptchaManager.py
new file mode 100644
index 000000000..9fbff92a1
--- /dev/null
+++ b/module/CaptchaManager.py
@@ -0,0 +1,112 @@
+# -*- 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 <http://www.gnu.org/licenses/>.
+
+ @author: mkaay
+"""
+
+from uuid import uuid4 as uuid
+from threading import Lock
+
+class CaptchaManager():
+ def __init__(self, core):
+ self.lock = Lock()
+ self.core = core
+ self.tasks = []
+
+ def newTask(self, plugin):
+ task = CaptchaTask(plugin, self)
+ self.lock.acquire()
+ self.tasks.append(task)
+ self.lock.release()
+ return task
+
+ def removeTask(self, task):
+ self.lock.acquire()
+ self.tasks.remove(task)
+ self.lock.release()
+
+ def getTask(self):
+ self.lock.acquire()
+ for task in self.tasks:
+ if task.getStatus() == "waiting":
+ self.lock.release()
+ return task
+ self.lock.release()
+ return None
+
+ def getTaskFromID(self, tid):
+ self.lock.acquire()
+ for task in self.tasks:
+ if task.getID() == tid:
+ self.lock.release()
+ return task
+ self.lock.release()
+ return None
+
+class CaptchaTask():
+ def __init__(self, plugin, manager):
+ self.lock = Lock()
+ self.plugin = plugin
+ self.manager = manager
+ self.captchaImg = None
+ self.captchaType = None
+ self.result = None
+ self.status = "preparing"
+ self.id = uuid().hex
+
+ def setCaptcha(self, img, imgType):
+ self.lock.acquire()
+ self.captchaImg = img
+ self.captchaType = imgType
+ self.lock.release()
+
+ def getCaptcha(self):
+ return self.captchaImg, self.captchaType
+
+ def setResult(self, result):
+ self.lock.acquire()
+ self.result = result
+ self.lock.release()
+
+ def getResult(self):
+ return self.result
+
+ def getID(self):
+ return self.id
+
+ def getStatus(self):
+ return self.status
+
+ def setDone(self):
+ self.lock.acquire()
+ self.status = "done"
+ self.lock.release()
+
+ def setWaiting(self):
+ self.lock.acquire()
+ self.status = "waiting"
+ self.lock.release()
+
+ def setWatingForUser(self):
+ self.lock.acquire()
+ self.status = "user"
+ self.lock.release()
+
+ def removeTask(self):
+ self.manager.removeTask(self)
+
+ def __str__(self):
+ return "<CaptchaTask '%s'>" % (self.getID(),)