From 1873b51db68b2c936d7b67f23dea4a5e49186568 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Thu, 11 Dec 2014 21:25:47 +0100 Subject: Spare code fixes --- pyload/config/Parser.py | 34 ++++++++++++++++++++++++++------- pyload/network/Bucket.py | 2 +- pyload/plugins/captcha/AdYouLike.py | 4 ++-- pyload/plugins/captcha/AdsCaptcha.py | 2 +- pyload/plugins/captcha/ReCaptcha.py | 2 +- pyload/plugins/captcha/SolveMedia.py | 2 +- pyload/plugins/crypter/Go4UpCom.py | 2 +- pyload/plugins/hoster/ShareonlineBiz.py | 2 +- pyload/plugins/internal/SimpleHoster.py | 2 +- 9 files changed, 36 insertions(+), 16 deletions(-) diff --git a/pyload/config/Parser.py b/pyload/config/Parser.py index ed9f1f897..e21eaba9f 100644 --- a/pyload/config/Parser.py +++ b/pyload/config/Parser.py @@ -9,8 +9,10 @@ from shutil import copy from traceback import print_exc from pyload.utils import chmod, encode, decode + CONF_VERSION = 1 + class ConfigParser(object): """ holds and manage the configuration @@ -28,7 +30,6 @@ class ConfigParser(object): desc: } - """ def __init__(self): @@ -42,6 +43,8 @@ class ConfigParser(object): self.checkVersion() self.readConfig() + + def checkVersion(self, n=0): """determines if config need to be copied""" try: @@ -78,6 +81,7 @@ class ConfigParser(object): sleep(0.3) self.checkVersion(n + 1) + def readConfig(self): """reads the config file""" self.config = self.parseConfig(join(pypath, "pyload", "config", "default.conf")) @@ -96,6 +100,7 @@ class ConfigParser(object): print "Config Warning" print_exc() + def parseConfig(self, config): """parses a given configfile""" @@ -178,23 +183,26 @@ class ConfigParser(object): f.close() return conf + def updateValues(self, config, dest): """sets the config values from a parsed config file to values in destination""" for section in config.iterkeys(): if section in dest: for option in config[section].iterkeys(): - if option in ("desc", "outline"): continue + if option in ("desc", "outline"): + continue if option in dest[section]: dest[section][option]["value"] = config[section][option]["value"] - # else: - # dest[section][option] = config[section][option] + # else: + # dest[section][option] = config[section][option] - #else: - # dest[section] = config[section] + # else: + # dest[section] = config[section] + def saveConfig(self, config, filename): """saves config to filename""" @@ -220,7 +228,8 @@ class ConfigParser(object): try: f.write('\t%s %s : "%s" = %s' % (data["type"], option, data["desc"], value)) except UnicodeEncodeError: - f.write('\t%s %s : "%s" = %s' % (data["type"], option, data["desc"], encode(value)) + f.write('\t%s %s : "%s" = %s' % (data["type"], option, data["desc"], encode(value))) + def cast(self, typ, value): """cast value to given format""" @@ -242,20 +251,24 @@ class ConfigParser(object): else: return value + def save(self): """saves the configs to disk""" self.saveConfig(self.config, "pyload.conf") self.saveConfig(self.plugin, "plugin.conf") + def __getitem__(self, section): """provides dictonary like access: c['section']['option']""" return Section(self, section) + def get(self, section, option): """get value""" value = self.config[section][option]["value"] return decode(value) + def set(self, section, option, value): """set value""" @@ -264,11 +277,13 @@ class ConfigParser(object): self.config[section][option]["value"] = value self.save() + def getPlugin(self, plugin, option): """gets a value for a plugin""" value = self.plugin[plugin][option]["value"] return encode(value) + def setPlugin(self, plugin, option, value): """sets a value for a plugin""" @@ -279,10 +294,12 @@ class ConfigParser(object): self.plugin[plugin][option]["value"] = value self.save() + def getMetaData(self, section, option): """ get all config data for an option """ return self.config[section][option] + def addPluginConfig(self, name, config, outline=""): """adds config options with tuples (name, type, desc, default)""" if name not in self.plugin: @@ -310,6 +327,7 @@ class ConfigParser(object): if item not in values: del conf[item] + def deleteConfig(self, name): """Removes a plugin config""" if name in self.plugin: @@ -324,10 +342,12 @@ class Section(object): self.parser = parser self.section = section + def __getitem__(self, item): """getitem""" return self.parser.get(self.section, item) + def __setitem__(self, item, value): """setitem""" self.parser.set(self.section, item, value) diff --git a/pyload/network/Bucket.py b/pyload/network/Bucket.py index 3aef2c733..33aa7c42e 100644 --- a/pyload/network/Bucket.py +++ b/pyload/network/Bucket.py @@ -8,7 +8,7 @@ from time import time MIN_RATE = 10240 -class Bucket: +class Bucket(object): def __init__(self): self.rate = 0 # bytes per second, maximum targeted throughput diff --git a/pyload/plugins/captcha/AdYouLike.py b/pyload/plugins/captcha/AdYouLike.py index 9c74e9348..be688e65d 100644 --- a/pyload/plugins/captcha/AdYouLike.py +++ b/pyload/plugins/captcha/AdYouLike.py @@ -61,7 +61,7 @@ class AdYouLike(Captcha): 'callback': callback}) try: challenge = json_loads(re.search(callback + r'\s*\((.+?)\)', html).group(1)) - except: + except Exception: errmsg = _("AdYouLike challenge pattern not found") self.plugin.error(errmsg) raise ValueError(errmsg) @@ -91,7 +91,7 @@ class AdYouLike(Captcha): try: instructions_visual = challenge['translations'][server['all']['lang']]['instructions_visual'] result = re.search(u'«(.+?)»', instructions_visual).group(1).strip() - except: + except Exception: errmsg = _("AdYouLike result not found") self.plugin.error(errmsg) raise ValueError(errmsg) diff --git a/pyload/plugins/captcha/AdsCaptcha.py b/pyload/plugins/captcha/AdsCaptcha.py index 239d61a19..8655e4f7b 100644 --- a/pyload/plugins/captcha/AdsCaptcha.py +++ b/pyload/plugins/captcha/AdsCaptcha.py @@ -56,7 +56,7 @@ class AdsCaptcha(Captcha): try: challenge = re.search("challenge: '(.+?)',", html).group(1) server = re.search("server: '(.+?)',", html).group(1) - except: + except Exception: errmsg = _("AdsCaptcha challenge pattern not found") self.plugin.error(errmsg) raise ValueError(errmsg) diff --git a/pyload/plugins/captcha/ReCaptcha.py b/pyload/plugins/captcha/ReCaptcha.py index 7a2ba9362..e12aba36d 100644 --- a/pyload/plugins/captcha/ReCaptcha.py +++ b/pyload/plugins/captcha/ReCaptcha.py @@ -51,7 +51,7 @@ class ReCaptcha(Captcha): try: challenge = re.search("challenge : '(.+?)',", html).group(1) server = re.search("server : '(.+?)',", html).group(1) - except: + except Exception: errmsg = _("ReCaptcha challenge pattern not found") self.plugin.error(errmsg) raise ValueError(errmsg) diff --git a/pyload/plugins/captcha/SolveMedia.py b/pyload/plugins/captcha/SolveMedia.py index 63db60627..cc48c801b 100644 --- a/pyload/plugins/captcha/SolveMedia.py +++ b/pyload/plugins/captcha/SolveMedia.py @@ -32,7 +32,7 @@ class SolveMedia(Captcha): challenge = re.search(r'', html).group(1) server = "http://api.solvemedia.com/papi/media" - except: + except Exception: errmsg = _("SolveMedia challenge pattern not found") self.plugin.error(errmsg) raise ValueError(errmsg) diff --git a/pyload/plugins/crypter/Go4UpCom.py b/pyload/plugins/crypter/Go4UpCom.py index cab32eb61..44c25c88a 100644 --- a/pyload/plugins/crypter/Go4UpCom.py +++ b/pyload/plugins/crypter/Go4UpCom.py @@ -40,7 +40,7 @@ class Go4UpCom(SimpleCrypter): for html in pages: try: links.append(re.search(r'