From 20226f8cc5889efbefa61209e1adf6184d42cd00 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Fri, 17 Apr 2015 01:21:41 +0200 Subject: Spare code cosmetics (3) --- pyload/webui/app/api.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'pyload/webui/app/api.py') diff --git a/pyload/webui/app/api.py b/pyload/webui/app/api.py index dd8521a07..2ec342fe2 100644 --- a/pyload/webui/app/api.py +++ b/pyload/webui/app/api.py @@ -37,7 +37,7 @@ def call_api(func, args=""): if not s or not s.get("authenticated", False): return HTTPError(403, json.dumps("Forbidden")) - if not PYLOAD.isAuthorized(func, {"role": s["role"], "permission": s["perms"]}): + if not PYLOAD.isAuthorized(func, {"role": s['role'], "permission": s['perms']}): return HTTPError(401, json.dumps("Unauthorized")) args = args.split("/")[1:] @@ -86,7 +86,7 @@ def login(): # get the session id by dirty way, documentations seems wrong try: - sid = s._headers["cookie_out"].split("=")[1].split(";")[0] + sid = s._headers['cookie_out'].split("=")[1].split(";")[0] return json.dumps(sid) except Exception: return json.dumps(True) -- cgit v1.2.3 From 938b7e6141e2895c7d41b0e8ef4b9416912e2e9e Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Fri, 17 Apr 2015 17:28:58 +0200 Subject: Spare code cosmetics (4) --- pyload/webui/app/api.py | 1 + 1 file changed, 1 insertion(+) (limited to 'pyload/webui/app/api.py') diff --git a/pyload/webui/app/api.py b/pyload/webui/app/api.py index 2ec342fe2..267b9b37c 100644 --- a/pyload/webui/app/api.py +++ b/pyload/webui/app/api.py @@ -13,6 +13,7 @@ from pyload.utils import json from SafeEval import const_eval as literal_eval from pyload.api import BaseObject + # json encoder that accepts TBase objects class TBaseEncoder(json.JSONEncoder): -- cgit v1.2.3 From e48abf98766b0a9c5799f17073d867dc09b23663 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Fri, 17 Apr 2015 17:54:19 +0200 Subject: PEP-8, Python Zen, refactor and reduce code (part 3 in master module) Conflicts: module/InitHomeDir.py module/debug.py module/forwarder.py module/unescape.py pyload/datatype/Package.py pyload/manager/Event.py pyload/manager/Thread.py pyload/manager/event/Scheduler.py pyload/utils/__init__.py pyload/webui/filters.py --- pyload/webui/app/api.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'pyload/webui/app/api.py') diff --git a/pyload/webui/app/api.py b/pyload/webui/app/api.py index 267b9b37c..16e8c2447 100644 --- a/pyload/webui/app/api.py +++ b/pyload/webui/app/api.py @@ -14,9 +14,9 @@ from SafeEval import const_eval as literal_eval 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) @@ -45,7 +45,8 @@ def call_api(func, args=""): kwargs = {} for x, y in chain(request.GET.iteritems(), request.POST.iteritems()): - if x == "session": continue + if x == "session": + continue kwargs[x] = unquote(y) try: @@ -64,9 +65,7 @@ def callApi(func, *args, **kwargs): **dict((x, literal_eval(y)) for x, y in kwargs.iteritems())) # null is invalid json response - if result is None: result = True - - return json.dumps(result, cls=TBaseEncoder) + return json.dumps(result or True, cls=TBaseEncoder) # post -> username, password -- cgit v1.2.3 From bb5a115533711fd8bb87f53cb32ff7342137208d Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Sat, 18 Apr 2015 00:29:55 +0200 Subject: Spare code cosmetics (5) --- pyload/webui/app/api.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'pyload/webui/app/api.py') 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/') @route('/api/', method='POST') def call_api(func, args=""): -- cgit v1.2.3