diff options
author | Stefano <l.stickell@yahoo.it> | 2013-07-24 14:24:51 +0200 |
---|---|---|
committer | Stefano <l.stickell@yahoo.it> | 2013-07-24 14:36:59 +0200 |
commit | 9be1035b2945f82b269487a009c02bd5a83028b0 (patch) | |
tree | 83c2496c60ddb5de3821151b80d69b639f007fe3 /pyload/plugins/addons/ImageTyperz.py | |
parent | Two more replace module import rules (diff) | |
download | pyload-9be1035b2945f82b269487a009c02bd5a83028b0.tar.xz |
Fixed PEP 8 violations in Hooks
(cherry picked from commit 669b1e0ec048e1ed8aeb842b2570376e9ad96863)
Conflicts:
pyload/plugins/addons/CaptchaTrader.py
pyload/plugins/addons/ClickAndLoad.py
pyload/plugins/addons/Ev0InFetcher.py
pyload/plugins/addons/ExternalScripts.py
pyload/plugins/addons/ExtractArchive.py
pyload/plugins/addons/HotFolder.py
pyload/plugins/addons/MergeFiles.py
pyload/plugins/addons/MultiHome.py
pyload/plugins/addons/XMPPInterface.py
Diffstat (limited to 'pyload/plugins/addons/ImageTyperz.py')
-rw-r--r-- | pyload/plugins/addons/ImageTyperz.py | 59 |
1 files changed, 25 insertions, 34 deletions
diff --git a/pyload/plugins/addons/ImageTyperz.py b/pyload/plugins/addons/ImageTyperz.py index f8f515113..c9e43b8ae 100644 --- a/pyload/plugins/addons/ImageTyperz.py +++ b/pyload/plugins/addons/ImageTyperz.py @@ -16,16 +16,14 @@ @author: mkaay, RaNaN, zoidberg """ from __future__ import with_statement - from thread import start_new_thread from pycurl import FORM_FILE, LOW_SPEED_TIME +import re +from base64 import b64encode from module.network.RequestFactory import getURL, getRequest -from module.network.HTTPRequest import BadHeader - from module.plugins.Hook import Hook -import re -from base64 import b64encode + class ImageTyperzException(Exception): def __init__(self, err): @@ -40,6 +38,7 @@ class ImageTyperzException(Exception): def __repr__(self): return "<ImageTyperzException %s>" % self.err + class ImageTyperz(Hook): __name__ = "ImageTyperz" __version__ = "0.04" @@ -59,28 +58,25 @@ class ImageTyperz(Hook): self.info = {} def getCredits(self): - response = getURL(self.GETCREDITS_URL, - post = {"action": "REQUESTBALANCE", - "username": self.getConfig("username"), - "password": self.getConfig("passkey")} - ) - + response = getURL(self.GETCREDITS_URL, post={"action": "REQUESTBALANCE", "username": self.getConfig("username"), + "password": self.getConfig("passkey")}) + if response.startswith('ERROR'): raise ImageTyperzException(response) - + try: balance = float(response) except: raise ImageTyperzException("invalid response") - + self.logInfo("Account balance: $%s left" % response) - return balance + return balance def submit(self, captcha, captchaType="file", match=None): req = getRequest() #raise timeout threshold req.c.setopt(LOW_SPEED_TIME, 80) - + try: #workaround multipart-post bug in HTTPRequest.py if re.match("^[A-Za-z0-9]*$", self.getConfig("passkey")): @@ -91,13 +87,11 @@ class ImageTyperz(Hook): with open(captcha, 'rb') as f: data = f.read() data = b64encode(data) - - response = req.load(self.SUBMIT_URL, - post={ "action": "UPLOADCAPTCHA", - "username": self.getConfig("username"), - "password": self.getConfig("passkey"), - "file": data}, - multipart = multipart) + + response = req.load(self.SUBMIT_URL, post={"action": "UPLOADCAPTCHA", + "username": self.getConfig("username"), + "password": self.getConfig("passkey"), "file": data}, + multipart=multipart) finally: req.close() @@ -108,14 +102,14 @@ class ImageTyperz(Hook): if len(data) == 2: ticket, result = data else: - raise ImageTyperzException("Unknown response %s" % response) - + raise ImageTyperzException("Unknown response %s" % response) + return ticket, result def newCaptchaTask(self, task): if "service" in task.data: return False - + if not task.isTextual(): return False @@ -136,17 +130,14 @@ class ImageTyperz(Hook): def captchaInvalid(self, task): if task.data['service'] == self.__name__ and "ticket" in task.data: - response = getURL(self.RESPOND_URL, - post={"action": "SETBADIMAGE", - "username": self.getConfig("username"), - "password": self.getConfig("passkey"), - "imageid": task.data["ticket"]} - ) - + response = getURL(self.RESPOND_URL, post={"action": "SETBADIMAGE", "username": self.getConfig("username"), + "password": self.getConfig("passkey"), + "imageid": task.data["ticket"]}) + if response == "SUCCESS": self.logInfo("Bad captcha solution received, requested refund") else: - self.logError("Bad captcha solution received, refund request failed", response) + self.logError("Bad captcha solution received, refund request failed", response) def processCaptcha(self, task): c = task.captchaFile @@ -157,4 +148,4 @@ class ImageTyperz(Hook): return task.data["ticket"] = ticket - task.setResult(result)
\ No newline at end of file + task.setResult(result) |