From 92888358e14c0a9e50e5604095a1c148ccc8b80d Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Sun, 17 Nov 2013 19:29:37 +0100 Subject: Internal plugins PEP8 cleanup --- module/plugins/internal/AbstractExtractor.py | 9 +-- module/plugins/internal/CaptchaService.py | 37 ++++++----- module/plugins/internal/DeadCrypter.py | 2 +- module/plugins/internal/DeadHoster.py | 5 +- module/plugins/internal/MultiHoster.py | 97 ++++++++++++++-------------- module/plugins/internal/SimpleHoster.py | 3 +- module/plugins/internal/UnRar.py | 38 ++++++----- module/plugins/internal/UnZip.py | 5 +- module/plugins/internal/XFSPAccount.py | 41 ++++++------ 9 files changed, 123 insertions(+), 114 deletions(-) (limited to 'module/plugins/internal') diff --git a/module/plugins/internal/AbstractExtractor.py b/module/plugins/internal/AbstractExtractor.py index f730a8434..32c137414 100644 --- a/module/plugins/internal/AbstractExtractor.py +++ b/module/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 if needed. Raise ArchiveError if integrity is questionable. diff --git a/module/plugins/internal/CaptchaService.py b/module/plugins/internal/CaptchaService.py index b912436a7..4aa3f7dad 100644 --- a/module/plugins/internal/CaptchaService.py +++ b/module/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,49 +19,53 @@ import re -class CaptchaService(): + +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 __init__(self,plugin): + def __init__(self, plugin): self.plugin = plugin def challenge(self, src): @@ -70,8 +75,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/module/plugins/internal/DeadCrypter.py b/module/plugins/internal/DeadCrypter.py index 805f781af..51e24a00a 100644 --- a/module/plugins/internal/DeadCrypter.py +++ b/module/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/module/plugins/internal/DeadHoster.py b/module/plugins/internal/DeadHoster.py index e180e2384..ba6abc0c5 100644 --- a/module/plugins/internal/DeadHoster.py +++ b/module/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/module/plugins/internal/MultiHoster.py b/module/plugins/internal/MultiHoster.py index a8961aafc..bd6dc7877 100644 --- a/module/plugins/internal/MultiHoster.py +++ b/module/plugins/internal/MultiHoster.py @@ -6,6 +6,7 @@ import re from module.utils import remove_chars from module.plugins.Hook import Hook + class MultiHoster(Hook): """ Generic MultiHoster plugin @@ -14,19 +15,19 @@ class MultiHoster(Hook): __version__ = "0.19" replacements = [("2shared.com", "twoshared.com"), ("4shared.com", "fourshared.com"), ("cloudnator.com", "shragle.com"), - ("ifile.it", "filecloud.io"), ("easy-share.com","crocko.com"), ("freakshare.net","freakshare.com"), - ("hellshare.com", "hellshare.cz"), ("share-rapid.cz","sharerapid.com"), ("sharerapid.cz","sharerapid.com"), - ("ul.to","uploaded.to"), ("uploaded.net","uploaded.to"), ("1fichier.com", "onefichier.com")] + ("ifile.it", "filecloud.io"), ("easy-share.com", "crocko.com"), ("freakshare.net", "freakshare.com"), + ("hellshare.com", "hellshare.cz"), ("share-rapid.cz", "sharerapid.com"), ("sharerapid.cz", "sharerapid.com"), + ("ul.to", "uploaded.to"), ("uploaded.net", "uploaded.to"), ("1fichier.com", "onefichier.com")] ignored = [] - interval = 24 * 60 * 60 # reload hosters daily - + interval = 24 * 60 * 60 #: reload hosters daily + def setup(self): self.hosters = [] self.supported = [] self.new_supported = [] - - def getConfig(self, option, default = ''): - """getConfig with default value - sublass may not implements all config options""" + + def getConfig(self, option, default=''): + """getConfig with default value - sublass may not implements all config options""" try: return self.getConf(option) except KeyError: @@ -40,33 +41,33 @@ class MultiHoster(Hook): except Exception, e: self.logError("%s" % str(e)) return [] - - try: + + try: configMode = self.getConfig('hosterListMode', 'all') if configMode in ("listed", "unlisted"): - configSet = self.toHosterSet(self.getConfig('hosterList', '').replace('|',',').replace(';',',').split(',')) - + configSet = self.toHosterSet(self.getConfig('hosterList', '').replace('|', ',').replace(';', ',').split(',')) + if configMode == "listed": hosterSet &= configSet else: hosterSet -= configSet - + except Exception, e: self.logError("%s" % str(e)) - + self.hosters = list(hosterSet) return self.hosters - + def toHosterSet(self, hosters): hosters = set((str(x).strip().lower() for x in hosters)) - + for rep in self.replacements: if rep[0] in hosters: hosters.remove(rep[0]) hosters.add(rep[1]) - - hosters.discard('') + + hosters.discard('') return hosters def getHoster(self): @@ -75,34 +76,34 @@ class MultiHoster(Hook): :return: List of domain names """ raise NotImplementedError - + def coreReady(self): if self.cb: self.core.scheduler.removeJob(self.cb) - - self.setConfig("activated", True) # config not in sync after plugin reload - - cfg_interval = self.getConfig("interval", None) # reload interval in hours + + self.setConfig("activated", True) #: config not in sync after plugin reload + + cfg_interval = self.getConfig("interval", None) #: reload interval in hours if cfg_interval is not None: - self.interval = cfg_interval * 60 * 60 - + self.interval = cfg_interval * 60 * 60 + if self.interval: self._periodical() else: self.periodical() - + def initPeriodical(self): - pass - + pass + def periodical(self): """reload hoster list periodically""" self.logInfo("Reloading supported hoster list") - + old_supported = self.supported self.supported, self.new_supported, self.hosters = [], [], [] - + self.overridePlugins() - + old_supported = [hoster for hoster in old_supported if hoster not in self.supported] if old_supported: self.logDebug("UNLOAD: %s" % ", ".join(old_supported)) @@ -113,15 +114,15 @@ class MultiHoster(Hook): pluginMap = {} for name in self.core.pluginManager.hosterPlugins.keys(): pluginMap[name.lower()] = name - - accountList = [ name.lower() for name, data in self.core.accountManager.accounts.items() if data ] + + accountList = [name.lower() for name, data in self.core.accountManager.accounts.items() if data] excludedList = [] - + for hoster in self.getHosterCached(): name = remove_chars(hoster.lower(), "-.") if name in accountList: - excludedList.append(hoster) + excludedList.append(hoster) else: if name in pluginMap: self.supported.append(pluginMap[name]) @@ -134,27 +135,27 @@ class MultiHoster(Hook): module = self.core.pluginManager.getPlugin(self.__name__) klass = getattr(module, self.__name__) - + # inject plugin plugin self.logDebug("Overwritten Hosters: %s" % ", ".join(sorted(self.supported))) for hoster in self.supported: dict = self.core.pluginManager.hosterPlugins[hoster] dict["new_module"] = module dict["new_name"] = self.__name__ - + if excludedList: self.logInfo("The following hosters were not overwritten - account exists: %s" % ", ".join(sorted(excludedList))) if self.new_supported: self.logDebug("New Hosters: %s" % ", ".join(sorted(self.new_supported))) - + # create new regexp - regexp = r".*(%s).*" % "|".join([x.replace(".", "\\.") for x in self.new_supported]) + regexp = r".*(%s).*" % "|".join([x.replace(".", "\\.") for x in self.new_supported]) if hasattr(klass, "__pattern__") and isinstance(klass.__pattern__, basestring) and '://' in klass.__pattern__: regexp = r"%s|%s" % (klass.__pattern__, regexp) - + self.logDebug("Regexp: %s" % regexp) - + dict = self.core.pluginManager.hosterPlugins[self.__name__] dict["pattern"] = regexp dict["re"] = re.compile(regexp) @@ -172,18 +173,18 @@ class MultiHoster(Hook): """Remove override for all hosters. Scheduler job is removed by hookmanager""" for hoster in self.supported: self.unloadHoster(hoster) - + # reset pattern klass = getattr(self.core.pluginManager.getPlugin(self.__name__), self.__name__) dict = self.core.pluginManager.hosterPlugins[self.__name__] - dict["pattern"] = getattr(klass, '__pattern__', r"^unmatchable$") - dict["re"] = re.compile(dict["pattern"]) - + dict["pattern"] = getattr(klass, '__pattern__', r"^unmatchable$") + dict["re"] = re.compile(dict["pattern"]) + def downloadFailed(self, pyfile): - """remove plugin override if download fails but not if file is offline/temp.offline""" + """remove plugin override if download fails but not if file is offline/temp.offline""" if pyfile.hasStatus("failed") and self.getConfig("unloadFailing", True): hdict = self.core.pluginManager.hosterPlugins[pyfile.pluginname] if "new_name" in hdict and hdict['new_name'] == self.__name__: - self.logDebug("Unload MultiHoster", pyfile.pluginname, hdict) + self.logDebug("Unload MultiHoster", pyfile.pluginname, hdict) self.unloadHoster(pyfile.pluginname) - pyfile.setStatus("queued") \ No newline at end of file + pyfile.setStatus("queued") diff --git a/module/plugins/internal/SimpleHoster.py b/module/plugins/internal/SimpleHoster.py index 856d3fde6..962d7639e 100644 --- a/module/plugins/internal/SimpleHoster.py +++ b/module/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/module/plugins/internal/UnRar.py b/module/plugins/internal/UnRar.py index 80ee39cdf..ec430c5bc 100644 --- a/module/plugins/internal/UnRar.py +++ b/module/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 . - + @author: RaNaN """ @@ -27,6 +27,7 @@ from string import digits from module.utils import save_join, decode from module.plugins.internal.AbstractExtractor import AbtractExtractor, WrongPassword, ArchiveError, CRCError + class UnRar(AbtractExtractor): __name__ = "UnRar" __version__ = "0.14" @@ -50,7 +51,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() @@ -62,11 +63,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: @@ -74,12 +76,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", self.file) @@ -102,7 +103,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", self.file, password=password) out, err = p.communicate() @@ -111,7 +112,6 @@ class UnRar(AbtractExtractor): return True - def extract(self, progress, password=None): command = "x" if self.fullpath else "e" @@ -144,7 +144,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") @@ -153,7 +153,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)) @@ -169,7 +168,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() @@ -180,26 +179,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(call)) diff --git a/module/plugins/internal/UnZip.py b/module/plugins/internal/UnZip.py index 9aa9ac75c..501962442 100644 --- a/module/plugins/internal/UnZip.py +++ b/module/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 . - + @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/module/plugins/internal/XFSPAccount.py b/module/plugins/internal/XFSPAccount.py index 8333c7265..e4f211216 100644 --- a/module/plugins/internal/XFSPAccount.py +++ b/module/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 . - + @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:([^<]+)' TRAFFIC_LEFT_PATTERN = r'>Traffic available today:([^<]+)' - - 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() -- cgit v1.2.3