diff options
author | Walter Purcaro <vuolter@users.noreply.github.com> | 2015-04-18 00:29:55 +0200 |
---|---|---|
committer | Walter Purcaro <vuolter@users.noreply.github.com> | 2015-04-18 00:29:55 +0200 |
commit | bb5a115533711fd8bb87f53cb32ff7342137208d (patch) | |
tree | 476600f9896fae029880e4049eb4c5e6021b202d | |
parent | PEP-8, Python Zen, refactor and reduce code (part 6 in master module/common) (diff) | |
download | pyload-bb5a115533711fd8bb87f53cb32ff7342137208d.tar.xz |
Spare code cosmetics (5)
45 files changed, 134 insertions, 64 deletions
diff --git a/docs/docs.conf b/docs/docs.conf index 51bab49fb..61a2c45ee 100644 --- a/docs/docs.conf +++ b/docs/docs.conf @@ -1,5 +1,5 @@ -# usage: epydoc --conf docs.conf , results goes to ~/.pyload/docs +#@NOTE: usage: epydoc --conf docs.conf , results goes to ~/.pyload/docs [epydoc] diff --git a/docs/write_addons.rst b/docs/write_addons.rst index cc39ab259..b7f6dfdb8 100644 --- a/docs/write_addons.rst +++ b/docs/write_addons.rst @@ -63,6 +63,7 @@ A basic excerpt would look like: :: def activate(self): print "Yay, the core is ready let's do some work." + def downloadFinished(self, pyfile): print "A Download just finished." @@ -80,16 +81,20 @@ It requires a `dict` that maps event names to function names or a `list` of func """ Your Addon code here. """ + event_map = {'downloadFinished': "doSomeWork", 'allDownloadsFnished': "someMethod", 'activate': "initialize"} + def initialize(self): print "Initialized." + def doSomeWork(self, pyfile): print "This is equivalent to the above example." + def someMethod(self): print "The underlying event (allDownloadsFinished) for this method is not available through the base class" @@ -147,6 +152,7 @@ Just store everything in ``self.info``. :: def setup(self): self.info = {'running': False} + def activate(self): self.info['running'] = True diff --git a/locale/pavement.py b/locale/pavement.py index 5e24ce9f2..06a4f9775 100644 --- a/locale/pavement.py +++ b/locale/pavement.py @@ -101,6 +101,7 @@ xargs = ["--language=Python", "--add-comments=L10N", "--from-code=utf-8", "--copyright-holder=pyLoad Team", "--package-name=pyLoad", "--package-version=%s" % options.version, "--msgid-bugs-address='bugs@pyload.org'"] + @task @needs('cog') def html(): @@ -116,6 +117,8 @@ def html(): ('rev=', 'r', "HG revision"), ("clean", 'c', 'Delete old source folder') ]) + + def get_source(options): """ Downloads pyload source from bitbucket tip or given rev""" if options.rev: options.url = "https://bitbucket.org/spoob/pyload/get/%s.zip" % options.rev @@ -164,6 +167,8 @@ def sdist(): ('path=', 'p', 'Thrift path'), ('gen=', 'g', "Extra --gen option") ]) + + def thrift(options): """ Generate Thrift stubs """ @@ -190,6 +195,7 @@ def thrift(options): from pyload.remote.socketbackend.create_ttypes import main main() + @task def compile_js(): """ Compile .coffee files to javascript""" @@ -224,7 +230,8 @@ def generate_locale(): strings = set() for fi in path("pyload/web").walkfiles(): - if not fi.name.endswith(".js") and not fi.endswith(".coffee"): continue + if not fi.name.endswith(".js") and not fi.endswith(".coffee"): + continue with open(fi, "rb") as c: content = c.read() @@ -250,6 +257,8 @@ def generate_locale(): @cmdopts([ ('key=', 'k', 'api key') ]) + + def upload_translations(options): """ Uploads the locale files to translation server """ tmp = path(mkdtemp()) @@ -278,6 +287,8 @@ def upload_translations(options): @cmdopts([ ('key=', 'k', 'api key') ]) + + def download_translations(options): """ Downloads the translated files from translation server """ tmp = path(mkdtemp()) @@ -327,6 +338,7 @@ def compile_translations(): def tests(): call(["nosetests2"]) + @task def virtualenv(options): """Setup virtual environment""" @@ -362,12 +374,15 @@ def clean(): # helper functions + def walk_trans(path, EXCLUDE, endings=[".py"]): result = "" for f in path.walkfiles(): - if [True for x in EXCLUDE if x in f.dirname().relpath()]: continue - if f.name in EXCLUDE: continue + if [True for x in EXCLUDE if x in f.dirname().relpath()]: + continue + if f.name in EXCLUDE: + continue for e in endings: if f.name.endswith(e): diff --git a/pyload/Core.py b/pyload/Core.py index cd210344d..e6f6fefcb 100755 --- a/pyload/Core.py +++ b/pyload/Core.py @@ -197,7 +197,8 @@ class Core(object): def isAlreadyRunning(self): pid = self.checkPidFile() - if not pid or os.name == "nt": return False + if not pid or os.name == "nt": + return False try: os.kill(pid, 0) # 0 - default signal (does nothing) except Exception: @@ -277,7 +278,8 @@ class Core(object): exit() try: signal.signal(signal.SIGQUIT, self.quit) - except Exception: pass + except Exception: + pass self.config = ConfigParser() diff --git a/pyload/api/__init__.py b/pyload/api/__init__.py index 676e76d7b..62af70cf8 100644 --- a/pyload/api/__init__.py +++ b/pyload/api/__init__.py @@ -38,6 +38,7 @@ permMap = {} # decorator only called on init, never initialized, so has no effect on runtime def permission(bits): class _Dec(object): + def __new__(cls, func, *args, **kwargs): permMap[func.__name__] = bits return func diff --git a/pyload/cli/Cli.py b/pyload/cli/Cli.py index a5348a776..84725b625 100644 --- a/pyload/cli/Cli.py +++ b/pyload/cli/Cli.py @@ -366,7 +366,8 @@ class Cli(object): print "%-45s %-12s\t %-15s\t %s" % (status.name, formatSize(status.size), status.plugin, check) - if result.rid == -1: break + if result.rid == -1: + break class RefreshThread(Thread): diff --git a/pyload/cli/ManageFiles.py b/pyload/cli/ManageFiles.py index b95e6f2db..c010895c5 100644 --- a/pyload/cli/ManageFiles.py +++ b/pyload/cli/ManageFiles.py @@ -113,7 +113,7 @@ class ManageFiles(Handler): i += 1 except Exception: pass - for _ in range(5 - i): + for _i in range(5 - i): println(line, "") line += 1 else: @@ -128,7 +128,7 @@ class ManageFiles(Handler): i += 1 except Exception, e: pass - for _ in range(5 - i): + for _i in range(5 - i): println(line, "") line += 1 diff --git a/pyload/config/Parser.py b/pyload/config/Parser.py index d2ec9bde2..b26af6202 100644 --- a/pyload/config/Parser.py +++ b/pyload/config/Parser.py @@ -214,7 +214,8 @@ class ConfigParser(object): f.write('\n%s - "%s":\n' % (section, config[section]['desc'])) for option, data in config[section].iteritems(): - if option in ("desc", "outline"): continue + if option in ("desc", "outline"): + continue if isinstance(data['value'], list): value = "[ \n" diff --git a/pyload/database/Backend.py b/pyload/database/Backend.py index cfdee058e..b0e94711e 100644 --- a/pyload/database/Backend.py +++ b/pyload/database/Backend.py @@ -81,7 +81,7 @@ class DatabaseJob(object): from os.path import basename frame = self.frame.f_back output = "" - for i in range(5): + for _i in range(5): output += "\t%s:%s, %s\n" % (basename(frame.f_code.co_filename), frame.f_lineno, frame.f_code.co_name) frame = frame.f_back del frame diff --git a/pyload/database/File.py b/pyload/database/File.py index faf68b246..7cbe1890a 100644 --- a/pyload/database/File.py +++ b/pyload/database/File.py @@ -87,7 +87,8 @@ class FileHandler(object): data.update([(x.id, x.toDbDict()[x.id]) for x in self.cache.values()]) for x in self.packageCache.itervalues(): - if x.queue != queue or x.id not in packs: continue + if x.queue != queue or x.id not in packs: + continue packs[x.id].update(x.toDict()[x.id]) for key, value in data.iteritems(): @@ -103,7 +104,8 @@ class FileHandler(object): packs = self.db.getAllPackages(queue) for x in self.packageCache.itervalues(): - if x.queue != queue or x.id not in packs: continue + if x.queue != queue or x.id not in packs: + continue packs[x.id].update(x.toDict()[x.id]) return packs @@ -493,7 +495,8 @@ class FileHandler(object): packs = self.packageCache.values() for pack in packs: - if pack.queue != p.queue or pack.order < 0 or pack == p: continue + if pack.queue != p.queue or pack.order < 0 or pack == p: + continue if p.order > position: if pack.order >= position and pack.order < p.order: pack.order += 1 @@ -523,7 +526,8 @@ class FileHandler(object): pyfiles = self.cache.values() for pyfile in pyfiles: - if pyfile.packageid != f['package'] or pyfile.order < 0: continue + if pyfile.packageid != f['package'] or pyfile.order < 0: + continue if f['order'] > position: if pyfile.order >= position and pyfile.order < f['order']: pyfile.order += 1 @@ -871,7 +875,8 @@ class FileMethods(object): """return package instance from id""" self.c.execute("SELECT name, folder, site, password, queue, packageorder FROM packages WHERE id=?", (str(id),)) r = self.c.fetchone() - if not r: return None + if not r: + return None return PyPackage(self.manager, id, * r) @@ -882,7 +887,8 @@ class FileMethods(object): """return link instance from id""" self.c.execute("SELECT url, name, size, status, error, plugin, package, linkorder FROM links WHERE id=?", (str(id),)) r = self.c.fetchone() - if not r: return None + if not r: + return None r = list(r) r[5] = tuple(r[5].split('.')) return PyFile(self.manager, id, * r) diff --git a/pyload/database/User.py b/pyload/database/User.py index 374570fb7..e11961e32 100644 --- a/pyload/database/User.py +++ b/pyload/database/User.py @@ -30,7 +30,7 @@ class UserMethods(object): @style.queue def addUser(db, user, password): - salt = reduce(lambda x, y: x + y, [str(random.randint(0, 9)) for i in range(0, 5)]) + salt = reduce(lambda x, y: x + y, [str(random.randint(0, 9)) for _i in range(0, 5)]) h = sha1(salt + password) password = salt + h.hexdigest() @@ -53,7 +53,7 @@ class UserMethods(object): pw = r[2][5:] h = sha1(salt + oldpw) if h.hexdigest() == pw: - salt = reduce(lambda x, y: x + y, [str(random.randint(0, 9)) for i in range(0, 5)]) + salt = reduce(lambda x, y: x + y, [str(random.randint(0, 9)) for _i in range(0, 5)]) h = sha1(salt + newpw) password = salt + h.hexdigest() diff --git a/pyload/datatype/File.py b/pyload/datatype/File.py index 713442265..93aa636d7 100644 --- a/pyload/datatype/File.py +++ b/pyload/datatype/File.py @@ -217,7 +217,8 @@ class PyFile(object): """ formats and return wait time in humanreadable format """ seconds = self.waitUntil - time() - if seconds < 0: return "00:00:00" + if seconds < 0: + return "00:00:00" hours, seconds = divmod(seconds, 3600) minutes, seconds = divmod(seconds, 60) @@ -233,7 +234,8 @@ class PyFile(object): """ formats eta to readable format """ seconds = self.getETA() - if seconds < 0: return "00:00:00" + if seconds < 0: + return "00:00:00" hours, seconds = divmod(seconds, 3600) minutes, seconds = divmod(seconds, 60) diff --git a/pyload/manager/Account.py b/pyload/manager/Account.py index 4e4a82aed..44a5e5c65 100644 --- a/pyload/manager/Account.py +++ b/pyload/manager/Account.py @@ -90,9 +90,12 @@ class AccountManager(object): for line in content[1:]: line = line.strip() - if not line: continue - if line.startswith("#"): continue - if line.startswith("version"): continue + if not line: + continue + if line.startswith("#"): + continue + if line.startswith("version"): + continue if line.endswith(":") and line.count(":") == 1: plugin = line[:-1] diff --git a/pyload/manager/Addon.py b/pyload/manager/Addon.py index cf23715b6..5ac56a349 100644 --- a/pyload/manager/Addon.py +++ b/pyload/manager/Addon.py @@ -41,8 +41,6 @@ class AddonManager(object): | Notes: | all_downloads-processed is *always* called before all_downloads-finished. | config-changed is *always* called before pluginConfigChanged. - - """ def __init__(self, core): diff --git a/pyload/manager/Plugin.py b/pyload/manager/Plugin.py index e99b1cea6..905ce524e 100644 --- a/pyload/manager/Plugin.py +++ b/pyload/manager/Plugin.py @@ -313,7 +313,8 @@ class PluginManager(object): else: user = 0 # used as bool and int split = fullname.split(".") - if len(split) != 4 - user: return + if len(split) != 4 - user: + return type, name = split[2 - user:4 - user] if type in self.plugins and name in self.plugins[type]: diff --git a/pyload/manager/Remote.py b/pyload/manager/Remote.py index b18035a00..c2d254932 100644 --- a/pyload/manager/Remote.py +++ b/pyload/manager/Remote.py @@ -61,6 +61,7 @@ class RemoteManager(object): # else: # self.available.append("SocketBackend") + def startBackends(self): host = self.core.config.get("remote", "listenaddr") port = self.core.config.get("remote", "port") diff --git a/pyload/manager/Thread.py b/pyload/manager/Thread.py index b255523d6..a8550e504 100644 --- a/pyload/manager/Thread.py +++ b/pyload/manager/Thread.py @@ -250,10 +250,12 @@ class ThreadManager(object): def assignJob(self): """assing a job to a thread if possible""" - if self.pause or not self.core.api.isTimeDownload(): return + if self.pause or not self.core.api.isTimeDownload(): + return # if self.downloaded > 20: - # if not self.cleanPyCurl(): return + # if not self.cleanPyCurl(): + return free = [x for x in self.threads if not x.active] diff --git a/pyload/network/Browser.py b/pyload/network/Browser.py index 59cc9dcb0..d8617fabc 100644 --- a/pyload/network/Browser.py +++ b/pyload/network/Browser.py @@ -68,7 +68,8 @@ class Browser(object): @property def percent(self): - if not self.size: return 0 + if not self.size: + return 0 return (self.arrived * 100) / self.size diff --git a/pyload/network/HTTPChunk.py b/pyload/network/HTTPChunk.py index 8a9c4803f..784b64349 100644 --- a/pyload/network/HTTPChunk.py +++ b/pyload/network/HTTPChunk.py @@ -177,7 +177,8 @@ class HTTPChunk(HTTPRequest): if self.range: # do nothing if chunk already finished - if self.arrived + self.range[0] >= self.range[1]: return None + if self.arrived + self.range[0] >= self.range[1]: + return None if self.id == len(self.p.info.chunks) - 1: #: as last chunk dont set end range, so we get everything range = "%i-" % (self.arrived + self.range[0]) diff --git a/pyload/network/HTTPDownload.py b/pyload/network/HTTPDownload.py index 32c165f82..13666195a 100644 --- a/pyload/network/HTTPDownload.py +++ b/pyload/network/HTTPDownload.py @@ -72,7 +72,8 @@ class HTTPDownload(object): @property def percent(self): - if not self.size: return 0 + if not self.size: + return 0 return (self.arrived * 100) / self.size @@ -134,7 +135,8 @@ class HTTPDownload(object): finally: self.close() - if self.nameDisposition and self.disposition: return self.nameDisposition + if self.nameDisposition and self.disposition: + return self.nameDisposition return None @@ -295,7 +297,8 @@ class HTTPDownload(object): def findChunk(self, handle): """ linear search to find a chunk (should be ok since chunk size is usually low) """ for chunk in self.chunks: - if chunk.c == handle: return chunk + if chunk.c == handle: + return chunk def closeChunk(self, chunk): diff --git a/pyload/network/RequestFactory.py b/pyload/network/RequestFactory.py index 49cfedce6..0591c5162 100644 --- a/pyload/network/RequestFactory.py +++ b/pyload/network/RequestFactory.py @@ -122,6 +122,7 @@ class RequestFactory(object): else: self.bucket.setRate(self.core.config.get("download", "max_speed") * 1024) + # needs pyreq in global namespace def getURL(*args, **kwargs): return pyreq.getURL(*args, **kwargs) diff --git a/pyload/network/XDCCRequest.py b/pyload/network/XDCCRequest.py index ccaeebe5f..dff500749 100644 --- a/pyload/network/XDCCRequest.py +++ b/pyload/network/XDCCRequest.py @@ -145,7 +145,8 @@ class XDCCRequest(object): @property def percent(self): - if not self.filesize: return 0 + if not self.filesize: + return 0 return (self.recv * 100) / self.filesize diff --git a/pyload/plugin/Account.py b/pyload/plugin/Account.py index bc13c0497..c46eae5e3 100644 --- a/pyload/plugin/Account.py +++ b/pyload/plugin/Account.py @@ -231,7 +231,8 @@ class Account(Base): """ returns an valid account name and data""" usable = [] for user, data in self.accounts.iteritems(): - if not data['valid']: continue + if not data['valid']: + continue if "time" in data['options'] and data['options']['time']: time_data = "" @@ -253,7 +254,8 @@ class Account(Base): usable.append((user, data)) - if not usable: return None, None + if not usable: + return None, None return choice(usable) diff --git a/pyload/plugin/Addon.py b/pyload/plugin/Addon.py index 35f010f29..bb90428e4 100644 --- a/pyload/plugin/Addon.py +++ b/pyload/plugin/Addon.py @@ -16,7 +16,6 @@ class Expose(object): def threaded(fn): - def run(*args,**kwargs): addonManager.startThread(fn, *args, **kwargs) diff --git a/pyload/plugin/Plugin.py b/pyload/plugin/Plugin.py index c18e16643..54963447c 100644 --- a/pyload/plugin/Plugin.py +++ b/pyload/plugin/Plugin.py @@ -57,6 +57,7 @@ class Base(object): A Base class with log/config/db methods *all* plugin types can use """ + def __init__(self, core): #: Core instance self.core = core @@ -568,7 +569,8 @@ class Plugin(Base): header = {"code": self.req.code} for line in res.splitlines(): line = line.strip() - if not line or ":" not in line: continue + if not line or ":" not in line: + continue key, none, value = line.partition(":") key = key.strip().lower() @@ -693,8 +695,10 @@ class Plugin(Base): size = stat(lastDownload) size = size.st_size - if api_size and api_size <= size: return None - elif size > max_size and not read_size: return None + if api_size and api_size <= size: + return None + elif size > max_size and not read_size: + return None self.logDebug("Download Check triggered") with open(lastDownload, "rb") as f: @@ -720,7 +724,8 @@ class Plugin(Base): def getPassword(self): """ get the password the user provided in the package""" password = self.pyfile.package().password - if not password: return "" + if not password: + return "" return password diff --git a/pyload/plugin/account/NoPremiumPl.py b/pyload/plugin/account/NoPremiumPl.py index 98f472848..6cefed550 100644 --- a/pyload/plugin/account/NoPremiumPl.py +++ b/pyload/plugin/account/NoPremiumPl.py @@ -37,7 +37,7 @@ class NoPremiumPl(Account): try: result = json_loads(self.runAuthQuery()) except Exception: - # todo: return or let it be thrown? + #@TODO: return or let it be thrown? return premium = False diff --git a/pyload/plugin/account/RapideoPl.py b/pyload/plugin/account/RapideoPl.py index d1cb47826..c58414b53 100644 --- a/pyload/plugin/account/RapideoPl.py +++ b/pyload/plugin/account/RapideoPl.py @@ -37,7 +37,7 @@ class RapideoPl(Account): try: result = json_loads(self.runAuthQuery()) except Exception: - # todo: return or let it be thrown? + #@TODO: return or let it be thrown? return premium = False diff --git a/pyload/plugin/hoster/BitshareCom.py b/pyload/plugin/hoster/BitshareCom.py index afea970eb..0d26c2d53 100644 --- a/pyload/plugin/hoster/BitshareCom.py +++ b/pyload/plugin/hoster/BitshareCom.py @@ -114,7 +114,7 @@ class BitshareCom(SimpleHoster): recaptcha = ReCaptcha(self) # Try up to 3 times - for i in xrange(3): + for _i in xrange(3): response, challenge = recaptcha.challenge() res = self.load("http://bitshare.com/files-ajax/" + self.file_id + "/request.html", post={"request" : "validateCaptcha", diff --git a/pyload/plugin/hoster/MegaRapidoNet.py b/pyload/plugin/hoster/MegaRapidoNet.py index d0c3ad917..311189d1c 100644 --- a/pyload/plugin/hoster/MegaRapidoNet.py +++ b/pyload/plugin/hoster/MegaRapidoNet.py @@ -8,7 +8,7 @@ from pyload.plugin.internal.MultiHoster import MultiHoster def random_with_N_digits(n): rand = "0." not_zero = 0 - for i in range(1, n + 1): + for _i in range(1, n + 1): r = randint(0, 9) if(r > 0): not_zero += 1 diff --git a/pyload/plugin/hoster/SimplyPremiumCom.py b/pyload/plugin/hoster/SimplyPremiumCom.py index 51b5ac577..327bfdcc1 100644 --- a/pyload/plugin/hoster/SimplyPremiumCom.py +++ b/pyload/plugin/hoster/SimplyPremiumCom.py @@ -46,7 +46,7 @@ class SimplyPremiumCom(MultiHoster): def handlePremium(self, pyfile): - for i in xrange(5): + for _i in xrange(5): self.html = self.load("http://www.simply-premium.com/premium.php", get={'info': "", 'link': self.pyfile.url}) if self.html: diff --git a/pyload/plugin/hoster/UpstoreNet.py b/pyload/plugin/hoster/UpstoreNet.py index 27fc68dc6..adf63e382 100644 --- a/pyload/plugin/hoster/UpstoreNet.py +++ b/pyload/plugin/hoster/UpstoreNet.py @@ -43,7 +43,7 @@ class UpstoreNet(SimpleHoster): recaptcha = ReCaptcha(self) # try the captcha 5 times - for i in xrange(5): + for _i in xrange(5): m = re.search(self.WAIT_PATTERN, self.html) if m is None: self.error(_("Wait pattern not found")) diff --git a/pyload/plugin/hoster/Xdcc.py b/pyload/plugin/hoster/Xdcc.py index f2b5d0b8f..42491404f 100644 --- a/pyload/plugin/hoster/Xdcc.py +++ b/pyload/plugin/hoster/Xdcc.py @@ -117,7 +117,7 @@ class Xdcc(Hoster): sock.send("PRIVMSG %s :xdcc send #%s\r\n" % (bot, pack)) else: - if (dl_time + self.timeout) < time.time(): # todo: add in config + if (dl_time + self.timeout) < time.time(): #@TODO: add in config sock.send("QUIT :byebye\r\n") sock.close() self.fail(_("XDCC Bot did not answer")) diff --git a/pyload/plugin/internal/SimpleHoster.py b/pyload/plugin/internal/SimpleHoster.py index 642ec2df7..930f5a313 100644 --- a/pyload/plugin/internal/SimpleHoster.py +++ b/pyload/plugin/internal/SimpleHoster.py @@ -652,9 +652,8 @@ class SimpleHoster(Hoster): self.checkStatus(getinfo=False) - #: Deprecated - + #: Deprecated def getFileInfo(self): self.info = {} self.checkInfo() diff --git a/pyload/remote/SocketBackend.py b/pyload/remote/SocketBackend.py index 05b2d8425..8b74d19ff 100644 --- a/pyload/remote/SocketBackend.py +++ b/pyload/remote/SocketBackend.py @@ -6,6 +6,7 @@ from pyload.manager.Remote import BackendBase class RequestHandler(SocketServer.BaseRequestHandler): + def setup(self): pass @@ -15,6 +16,7 @@ class RequestHandler(SocketServer.BaseRequestHandler): class SocketBackend(BackendBase): + def setup(self, host, port): # local only self.server = SocketServer.ThreadingTCPServer(("localhost", port), RequestHandler) diff --git a/pyload/remote/socketbackend/create_ttypes.py b/pyload/remote/socketbackend/create_ttypes.py index 722da8d56..9b001f1bf 100644 --- a/pyload/remote/socketbackend/create_ttypes.py +++ b/pyload/remote/socketbackend/create_ttypes.py @@ -49,7 +49,8 @@ class BaseObject(object): f.write("class %s:\n" % name) for attr in dir(enum): - if attr.startswith("_") or attr in ("read", "write"): continue + if attr.startswith("_") or attr in ("read", "write"): + continue f.write("\t%s = %s\n" % (attr, getattr(enum, attr))) @@ -73,7 +74,8 @@ class BaseObject(object): f.write("class Iface(object):\n") for name in dir(Iface): - if name.startswith("_"): continue + if name.startswith("_"): + continue func = inspect.getargspec(getattr(Iface, name)) diff --git a/pyload/remote/thriftbackend/Protocol.py b/pyload/remote/thriftbackend/Protocol.py index cc5352d40..ecf0680ad 100644 --- a/pyload/remote/thriftbackend/Protocol.py +++ b/pyload/remote/thriftbackend/Protocol.py @@ -27,6 +27,7 @@ class Protocol(TBinaryProtocol.TBinaryProtocol): class ProtocolFactory(TBinaryProtocol.TBinaryProtocolFactory): + def getProtocol(self, trans): prot = Protocol(trans, self.strictRead, self.strictWrite) return prot diff --git a/pyload/remote/thriftbackend/ThriftTest.py b/pyload/remote/thriftbackend/ThriftTest.py index fb8dd03c9..0c5ea4783 100644 --- a/pyload/remote/thriftbackend/ThriftTest.py +++ b/pyload/remote/thriftbackend/ThriftTest.py @@ -22,9 +22,10 @@ from time import time import xmlrpclib + def bench(f, *args, **kwargs): s = time() - ret = [f(*args, **kwargs) for i in range(0, 100)] + ret = [f(*args, **kwargs) for _i in range(0, 100)] e = time() try: print "%s: %f s" % (f._Method__name, e-s) diff --git a/pyload/utils/packagetools.py b/pyload/utils/packagetools.py index 9dbde9b50..0ab68a869 100644 --- a/pyload/utils/packagetools.py +++ b/pyload/utils/packagetools.py @@ -136,7 +136,7 @@ def parseNames(files): else: name = "" - # fallback: package by hoster + #@NOTE: fallback: package by hoster if not name: name = urlparse(file).netloc if name: diff --git a/pyload/utils/printer.py b/pyload/utils/printer.py index 5d333e238..1122c7f4c 100644 --- a/pyload/utils/printer.py +++ b/pyload/utils/printer.py @@ -5,6 +5,7 @@ import colorama colorama.init(autoreset=True) + def color(color, text): return colorama.Fore.(c.upper())(text) diff --git a/pyload/webui/__init__.py b/pyload/webui/__init__.py index 2035bea90..841e5abd9 100644 --- a/pyload/webui/__init__.py +++ b/pyload/webui/__init__.py @@ -102,6 +102,7 @@ if PREFIX: import pyload.webui.app + def run_simple(host="0.0.0.0", port="8000"): run(app=web, host=host, port=port, quiet=True) diff --git a/pyload/webui/app/api.py b/pyload/webui/app/api.py index 16e8c2447..0e36b7c1f 100644 --- a/pyload/webui/app/api.py +++ b/pyload/webui/app/api.py @@ -17,6 +17,7 @@ from pyload.api import BaseObject # json encoder that accepts TBase objects class TBaseEncoder(json.JSONEncoder): + def default(self, o): if isinstance(o, BaseObject): return toDict(o) @@ -24,7 +25,6 @@ class TBaseEncoder(json.JSONEncoder): # accepting positional arguments, as well as kwargs via post and get - @route('/api/<func><args:re:[a-zA-Z0-9\-_/\"\'\[\]%{},]*>') @route('/api/<func><args:re:[a-zA-Z0-9\-_/\"\'\[\]%{},]*>', method='POST') def call_api(func, args=""): diff --git a/pyload/webui/app/json.py b/pyload/webui/app/json.py index 51159ddf3..12dce2484 100644 --- a/pyload/webui/app/json.py +++ b/pyload/webui/app/json.py @@ -241,7 +241,8 @@ def load_config(category, section): conf = PYLOAD.getPluginConfigDict() for key, option in conf[section].iteritems(): - if key in ("desc", "outline"): continue + if key in ("desc", "outline"): + continue if ";" in option['type']: option['list'] = option['type'].split(";") @@ -282,12 +283,14 @@ def update_accounts(): for name, value in request.POST.iteritems(): value = value.strip() - if not value: continue + if not value: + continue tmp, user = name.split(";") plugin, action = tmp.split("|") - if (plugin, user) in deleted: continue + if (plugin, user) in deleted: + continue if action == "password": PYLOAD.updateAccount(plugin, user, value) @@ -299,6 +302,7 @@ def update_accounts(): deleted.append((plugin,user)) PYLOAD.removeAccount(plugin, user) + @route('/json/change_password', method='POST') def change_password(): diff --git a/pyload/webui/app/utils.py b/pyload/webui/app/utils.py index f9931f531..69067d8fe 100644 --- a/pyload/webui/app/utils.py +++ b/pyload/webui/app/utils.py @@ -9,6 +9,7 @@ from pyload.webui import env, THEME from pyload.api import has_permission, PERMS, ROLE + def render_to_response(file, args={}, proc=[]): for p in proc: args.update(p()) @@ -56,7 +57,8 @@ def set_permission(perms): """ permission = 0 for name in dir(PERMS): - if name.startswith("_"): continue + if name.startswith("_"): + continue if name in perms and perms[name]: permission |= getattr(PERMS, name) diff --git a/tests/APIExerciser.py b/tests/APIExerciser.py index 32a3304c0..d17f81ae2 100644 --- a/tests/APIExerciser.py +++ b/tests/APIExerciser.py @@ -32,11 +32,12 @@ sumCalled = 0 def startApiExerciser(core, n): - for _ in range(n): + for _i in range(n): APIExerciser(core).start() class APIExerciser(Thread): + def __init__(self, core, thrift=False, user=None, pw=None): global idPool @@ -114,9 +115,11 @@ class APIExerciser(Thread): self.api.addPackage(name, urls, choice([Destination.Queue, Destination.Collector])) + def deleteFiles(self): info = self.api.getQueueData() - if not info: return + if not info: + return pack = choice(info) fids = pack.links @@ -125,9 +128,11 @@ class APIExerciser(Thread): fids = [f.fid for f in sample(fids, randint(1, max(len(fids) / 2, 1)))] self.api.deleteFiles(fids) + def deletePackages(self): info = choice([self.api.getQueue(), self.api.getCollector()]) - if not info: return + if not info: + return pids = [p.pid for p in info] if pids: diff --git a/tests/test_api.py b/tests/test_api.py index 9c12da51c..13e783d54 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -20,5 +20,5 @@ class TestApi(object): @nottest def test_random(self): - for _ in range(0, 100): + for _i in range(0, 100): self.api.testAPI() |