diff options
author | Stefano <l.stickell@yahoo.it> | 2013-11-25 12:27:49 +0100 |
---|---|---|
committer | Stefano <l.stickell@yahoo.it> | 2013-12-15 22:13:47 +0100 |
commit | d7254f602f1ba5140603e2651fb9e2950690a7a5 (patch) | |
tree | 8a098bc89b61a1cff351084de913a0e52972610e /pyload | |
parent | Merge pull request #412 from vuolter/s/crypter/EasybytezComFolder (diff) | |
download | pyload-d7254f602f1ba5140603e2651fb9e2950690a7a5.tar.xz |
Merge pull request #418 from vuolter/s/internal_PEP8cleanup
Internal plugins code cleanup according to PEP8 guidelines
(cherry picked from commit cfe3b21334f3eef319a667a477634c025e757fbf)
Conflicts:
module/plugins/internal/MultiHoster.py
pyload/plugins/internal/CaptchaService.py
Diffstat (limited to 'pyload')
-rw-r--r-- | pyload/plugins/internal/AbstractExtractor.py | 9 | ||||
-rw-r--r-- | pyload/plugins/internal/CaptchaService.py | 33 | ||||
-rw-r--r-- | pyload/plugins/internal/DeadCrypter.py | 2 | ||||
-rw-r--r-- | pyload/plugins/internal/DeadHoster.py | 5 | ||||
-rw-r--r-- | pyload/plugins/internal/SimpleHoster.py | 3 | ||||
-rw-r--r-- | pyload/plugins/internal/UnRar.py | 38 | ||||
-rw-r--r-- | pyload/plugins/internal/UnZip.py | 5 | ||||
-rw-r--r-- | pyload/plugins/internal/XFSPAccount.py | 41 |
8 files changed, 72 insertions, 64 deletions
diff --git a/pyload/plugins/internal/AbstractExtractor.py b/pyload/plugins/internal/AbstractExtractor.py index 3ce76b6fa..90d6dd75e 100644 --- a/pyload/plugins/internal/AbstractExtractor.py +++ b/pyload/plugins/internal/AbstractExtractor.py @@ -1,15 +1,19 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- + class ArchiveError(Exception): pass + class CRCError(Exception): pass + class WrongPassword(Exception): pass + class AbtractExtractor: __version__ = "0.1" @@ -29,7 +33,6 @@ class AbtractExtractor: """ raise NotImplementedError - def __init__(self, m, file, out, fullpath, overwrite, excludefiles, renice): """Initialize extractor for specific file @@ -47,14 +50,12 @@ class AbtractExtractor: self.overwrite = overwrite self.excludefiles = excludefiles self.renice = renice - self.files = [] # Store extracted files here - + self.files = [] #: Store extracted files here def init(self): """ Initialize additional data structures """ pass - def checkArchive(self): """Check if password is needed. Raise ArchiveError if integrity is questionable. diff --git a/pyload/plugins/internal/CaptchaService.py b/pyload/plugins/internal/CaptchaService.py index 4f903e3e6..d4d0c9979 100644 --- a/pyload/plugins/internal/CaptchaService.py +++ b/pyload/plugins/internal/CaptchaService.py @@ -1,4 +1,5 @@ # -*- 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 @@ -18,47 +19,51 @@ import re + class CaptchaService(): __version__ = "0.02" - + def __init__(self, plugin): self.plugin = plugin - + + class ReCaptcha(): def __init__(self, plugin): self.plugin = plugin - + def challenge(self, id): - js = self.plugin.req.load("http://www.google.com/recaptcha/api/challenge", get={"k":id}, cookies=True) - + js = self.plugin.req.load("http://www.google.com/recaptcha/api/challenge", get={"k": id}, cookies=True) + try: challenge = re.search("challenge : '(.*?)',", js).group(1) server = re.search("server : '(.*?)',", js).group(1) except: self.plugin.fail("recaptcha error") - result = self.result(server,challenge) - + result = self.result(server, challenge) + return challenge, result def result(self, server, challenge): - return self.plugin.decryptCaptcha("%simage"%server, get={"c":challenge}, cookies=True, forceUser=True, imgtype="jpg") + return self.plugin.decryptCaptcha("%simage" % server, get={"c": challenge}, cookies=True, forceUser=True, imgtype="jpg") + class AdsCaptcha(CaptchaService): def challenge(self, src): js = self.plugin.req.load(src, cookies=True) - + try: challenge = re.search("challenge: '(.*?)',", js).group(1) server = re.search("server: '(.*?)',", js).group(1) except: self.plugin.fail("adscaptcha error") - result = self.result(server,challenge) - + result = self.result(server, challenge) + return challenge, result def result(self, server, challenge): return self.plugin.decryptCaptcha("%sChallenge.aspx" % server, get={"cid": challenge, "dummy": random()}, cookies=True, imgtype="jpg") + class SolveMedia(CaptchaService): def challenge(self, src): @@ -68,8 +73,8 @@ class SolveMedia(CaptchaService): except: self.plugin.fail("solvmedia error") result = self.result(challenge) - + return challenge, result - def result(self,challenge): - return self.plugin.decryptCaptcha("http://api.solvemedia.com/papi/media?c=%s" % challenge,imgtype="gif")
\ No newline at end of file + def result(self, challenge): + return self.plugin.decryptCaptcha("http://api.solvemedia.com/papi/media?c=%s" % challenge, imgtype="gif") diff --git a/pyload/plugins/internal/DeadCrypter.py b/pyload/plugins/internal/DeadCrypter.py index 805f781af..51e24a00a 100644 --- a/pyload/plugins/internal/DeadCrypter.py +++ b/pyload/plugins/internal/DeadCrypter.py @@ -9,6 +9,6 @@ class DeadCrypter(_Crypter): __description__ = """Crypter is no longer available""" __author_name__ = ("stickell") __author_mail__ = ("l.stickell@yahoo.it") - + def setup(self): self.fail("Crypter is no longer available") diff --git a/pyload/plugins/internal/DeadHoster.py b/pyload/plugins/internal/DeadHoster.py index e180e2384..ba6abc0c5 100644 --- a/pyload/plugins/internal/DeadHoster.py +++ b/pyload/plugins/internal/DeadHoster.py @@ -5,6 +5,7 @@ def create_getInfo(plugin): yield [('#N/A: ' + url, 0, 1, url) for url in urls] return getInfo + class DeadHoster(_Hoster): __name__ = "DeadHoster" __type__ = "hoster" @@ -13,6 +14,6 @@ class DeadHoster(_Hoster): __description__ = """Hoster is no longer available""" __author_name__ = ("zoidberg") __author_mail__ = ("zoidberg@mujmail.cz") - + def setup(self): - self.fail("Hoster is no longer available")
\ No newline at end of file + self.fail("Hoster is no longer available") diff --git a/pyload/plugins/internal/SimpleHoster.py b/pyload/plugins/internal/SimpleHoster.py index 856d3fde6..962d7639e 100644 --- a/pyload/plugins/internal/SimpleHoster.py +++ b/pyload/plugins/internal/SimpleHoster.py @@ -213,7 +213,8 @@ class SimpleHoster(Hoster): self.handleFree() def load(self, url, get={}, post={}, ref=True, cookies=True, just_header=False, decode=False): - if type(url) == unicode: url = url.encode('utf8') + if type(url) == unicode: + url = url.encode('utf8') return Hoster.load(self, url=url, get=get, post=post, ref=ref, cookies=cookies, just_header=just_header, decode=decode) diff --git a/pyload/plugins/internal/UnRar.py b/pyload/plugins/internal/UnRar.py index e406f124e..8635483e6 100644 --- a/pyload/plugins/internal/UnRar.py +++ b/pyload/plugins/internal/UnRar.py @@ -13,7 +13,7 @@ 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: RaNaN """ @@ -26,6 +26,7 @@ from string import digits from module.utils.fs import save_join, decode, fs_encode from module.plugins.internal.AbstractExtractor import AbtractExtractor, WrongPassword, ArchiveError, CRCError + class UnRar(AbtractExtractor): __name__ = "UnRar" __version__ = "0.14" @@ -49,7 +50,7 @@ class UnRar(AbtractExtractor): p.communicate() except OSError: - #fallback to rar + # fallback to rar UnRar.CMD = "rar" p = Popen([UnRar.CMD], stdout=PIPE, stderr=PIPE) p.communicate() @@ -61,11 +62,12 @@ class UnRar(AbtractExtractor): result = [] for file, id in files_ids: - if not file.endswith(".rar"): continue + if not file.endswith(".rar"): + continue match = UnRar.re_splitfile.findall(file) if match: - #only add first parts + # only add first parts if int(match[0][1]) == 1: result.append((file, id)) else: @@ -73,12 +75,11 @@ class UnRar(AbtractExtractor): return result - def init(self): self.passwordProtected = False - self.headerProtected = False #list files will not work without password - self.smallestFile = None #small file to test passwords - self.password = "" #save the correct password + self.headerProtected = False #: list files will not work without password + self.smallestFile = None #: small file to test passwords + self.password = "" #: save the correct password def checkArchive(self): p = self.call_unrar("l", "-v", fs_encode(self.file)) @@ -101,7 +102,7 @@ class UnRar(AbtractExtractor): return False def checkPassword(self, password): - #at this point we can only verify header protected files + # at this point we can only verify header protected files if self.headerProtected: p = self.call_unrar("l", "-v", fs_encode(self.file), password=password) out, err = p.communicate() @@ -110,7 +111,6 @@ class UnRar(AbtractExtractor): return True - def extract(self, progress, password=None): command = "x" if self.fullpath else "e" @@ -143,7 +143,7 @@ class UnRar(AbtractExtractor): raise CRCError elif "CRC failed" in err: raise WrongPassword - if err.strip(): #raise error if anything is on stderr + if err.strip(): #: raise error if anything is on stderr raise ArchiveError(err.strip()) if p.returncode: raise ArchiveError("Process terminated") @@ -152,7 +152,6 @@ class UnRar(AbtractExtractor): self.password = password self.listContent() - def getDeleteFiles(self): if ".part" in self.file: return glob(re.sub("(?<=\.part)([01]+)", "*", self.file, re.IGNORECASE)) @@ -168,7 +167,7 @@ class UnRar(AbtractExtractor): if "Cannot open" in err: raise ArchiveError("Cannot open file") - if err.strip(): # only log error at this point + if err.strip(): #: only log error at this point self.m.logError(err.strip()) result = set() @@ -179,26 +178,25 @@ class UnRar(AbtractExtractor): self.files = result - def call_unrar(self, command, *xargs, **kwargs): args = [] - #overwrite flag + # overwrite flag args.append("-o+") if self.overwrite else args.append("-o-") - + if self.excludefiles: for word in self.excludefiles.split(';'): - args.append("-x%s" % word ) - + args.append("-x%s" % word) + # assume yes on all queries args.append("-y") - #set a password + # set a password if "password" in kwargs and kwargs["password"]: args.append("-p%s" % kwargs["password"]) else: args.append("-p-") - #NOTE: return codes are not reliable, some kind of threading, cleanup whatever issue + # NOTE: return codes are not reliable, some kind of threading, cleanup whatever issue call = [self.CMD, command] + args + list(xargs) self.m.logDebug(" ".join([decode(arg) for arg in call])) diff --git a/pyload/plugins/internal/UnZip.py b/pyload/plugins/internal/UnZip.py index 9aa9ac75c..501962442 100644 --- a/pyload/plugins/internal/UnZip.py +++ b/pyload/plugins/internal/UnZip.py @@ -13,7 +13,7 @@ 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: RaNaN """ @@ -22,6 +22,7 @@ import sys from module.plugins.internal.AbstractExtractor import AbtractExtractor + class UnZip(AbtractExtractor): __name__ = "UnZip" __version__ = "0.1" @@ -46,4 +47,4 @@ class UnZip(AbtractExtractor): z.extractall(self.out) def getDeleteFiles(self): - return [self.file]
\ No newline at end of file + return [self.file] diff --git a/pyload/plugins/internal/XFSPAccount.py b/pyload/plugins/internal/XFSPAccount.py index 8333c7265..e4f211216 100644 --- a/pyload/plugins/internal/XFSPAccount.py +++ b/pyload/plugins/internal/XFSPAccount.py @@ -13,7 +13,7 @@ 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: zoidberg """ @@ -23,6 +23,7 @@ from module.plugins.Account import Account from module.plugins.internal.SimpleHoster import parseHtmlForm from module.utils import parseFileSize + class XFSPAccount(Account): __name__ = "XFSPAccount" __version__ = "0.05" @@ -30,18 +31,18 @@ class XFSPAccount(Account): __description__ = """XFileSharingPro account base""" __author_name__ = ("zoidberg") __author_mail__ = ("zoidberg@mujmail.cz") - + MAIN_PAGE = None - + VALID_UNTIL_PATTERN = r'>Premium.[Aa]ccount expire:</TD><TD><b>([^<]+)</b>' TRAFFIC_LEFT_PATTERN = r'>Traffic available today:</TD><TD><b>([^<]+)</b>' - - def loadAccountInfo(self, user, req): - html = req.load(self.MAIN_PAGE + "?op=my_account", decode = True) - + + def loadAccountInfo(self, user, req): + html = req.load(self.MAIN_PAGE + "?op=my_account", decode=True) + validuntil = trafficleft = None premium = True if '>Renew premium<' in html else False - + found = re.search(self.VALID_UNTIL_PATTERN, html) if found: premium = True @@ -58,22 +59,22 @@ class XFSPAccount(Account): if "Unlimited" in trafficleft: premium = True else: - trafficleft = parseFileSize(trafficleft) / 1024 - + trafficleft = parseFileSize(trafficleft) / 1024 + return ({"validuntil": validuntil, "trafficleft": trafficleft, "premium": premium}) - + def login(self, user, data, req): - html = req.load('%slogin.html' % self.MAIN_PAGE, decode = True) - + html = req.load('%slogin.html' % self.MAIN_PAGE, decode=True) + action, inputs = parseHtmlForm('name="FL"', html) if not inputs: inputs = {"op": "login", - "redirect": self.MAIN_PAGE} - + "redirect": self.MAIN_PAGE} + inputs.update({"login": user, "password": data['password']}) - - html = req.load(self.MAIN_PAGE, post = inputs, decode = True) - - if 'Incorrect Login or Password' in html or '>Error<' in html: - self.wrongPassword()
\ No newline at end of file + + html = req.load(self.MAIN_PAGE, post=inputs, decode=True) + + if 'Incorrect Login or Password' in html or '>Error<' in html: + self.wrongPassword() |