summaryrefslogtreecommitdiffstats
path: root/pyload/webui/app
diff options
context:
space:
mode:
Diffstat (limited to 'pyload/webui/app')
-rw-r--r--pyload/webui/app/api.py1
-rw-r--r--pyload/webui/app/cnl.py11
-rw-r--r--pyload/webui/app/json.py12
-rw-r--r--pyload/webui/app/pyloadweb.py35
-rw-r--r--pyload/webui/app/utils.py9
5 files changed, 28 insertions, 40 deletions
diff --git a/pyload/webui/app/api.py b/pyload/webui/app/api.py
index 0e36b7c1f..70d86c112 100644
--- a/pyload/webui/app/api.py
+++ b/pyload/webui/app/api.py
@@ -8,7 +8,6 @@ from bottle import route, request, response, HTTPError
from pyload.webui.app.utils import toDict, set_session
from pyload.webui import PYLOAD
-
from pyload.utils import json
from SafeEval import const_eval as literal_eval
from pyload.api import BaseObject
diff --git a/pyload/webui/app/cnl.py b/pyload/webui/app/cnl.py
index 73087ad2d..635d4030c 100644
--- a/pyload/webui/app/cnl.py
+++ b/pyload/webui/app/cnl.py
@@ -1,4 +1,7 @@
# -*- coding: utf-8 -*-
+
+from __future__ import with_statement
+
from os.path import join
import re
from urllib import unquote
@@ -6,6 +9,7 @@ from base64 import standard_b64decode
from binascii import unhexlify
from bottle import route, request, HTTPError
+
from pyload.webui import PYLOAD, DL_ROOT, JS
@@ -57,9 +61,8 @@ def addcrypted():
dlc = request.forms['crypted'].replace(" ", "+")
dlc_path = join(DL_ROOT, package.replace("/", "").replace("\\", "").replace(":", "") + ".dlc")
- dlc_file = open(dlc_path, "wb")
- dlc_file.write(dlc)
- dlc_file.close()
+ with open(dlc_path, "wb") as dlc_file:
+ dlc_file.write(dlc)
try:
PYLOAD.addPackage(package, [dlc_path], 0)
@@ -85,7 +88,7 @@ def addcrypted2():
try:
jk = re.findall(r"return ('|\")(.+)('|\")", jk)[0][1]
except Exception:
- ## Test for some known js functions to decode
+ # Test for some known js functions to decode
if jk.find("dec") > -1 and jk.find("org") > -1:
org = re.findall(r"var org = ('|\")([^\"']+)", jk)[0][1]
jk = list(org)
diff --git a/pyload/webui/app/json.py b/pyload/webui/app/json.py
index 0805e9f5b..3b72cb7ce 100644
--- a/pyload/webui/app/json.py
+++ b/pyload/webui/app/json.py
@@ -1,5 +1,7 @@
# -*- coding: utf-8 -*-
+from __future__ import with_statement
+
from os.path import join
from traceback import print_exc
from shutil import copyfileobj
@@ -7,9 +9,7 @@ from shutil import copyfileobj
from bottle import route, request, HTTPError
from pyload.webui import PYLOAD
-
from pyload.webui.app.utils import login_required, render_to_response, toDict
-
from pyload.utils import decode, formatSize
@@ -166,9 +166,8 @@ def add_package():
name = f.name
fpath = join(PYLOAD.getConfigValue("general", "download_folder"), "tmp_" + f.filename)
- destination = open(fpath, 'wb')
- copyfileobj(f.file, destination)
- destination.close()
+ with open(fpath, 'wb') as destination:
+ copyfileobj(f.file, destination)
links.insert(0, fpath)
except Exception:
pass
@@ -226,7 +225,7 @@ def set_captcha():
if task.tid >= 0:
src = "data:image/%s;base64,%s" % (task.type, task.data)
- return {'captcha': True, 'id': task.tid, 'src': src, 'result_type' : task.resultType}
+ return {'captcha': True, 'id': task.tid, 'src': src, 'result_type': task.resultType}
else:
return {'captcha': False}
@@ -306,7 +305,6 @@ def update_accounts():
@route('/json/change_password', method='POST')
def change_password():
-
user = request.POST['user_login']
oldpw = request.POST['login_current_password']
newpw = request.POST['login_new_password']
diff --git a/pyload/webui/app/pyloadweb.py b/pyload/webui/app/pyloadweb.py
index 154409655..7f2317bd1 100644
--- a/pyload/webui/app/pyloadweb.py
+++ b/pyload/webui/app/pyloadweb.py
@@ -274,12 +274,12 @@ def config():
data.trafficleft = formatSize(data.trafficleft)
if data.validuntil == -1:
- data.validuntil = _("unlimited")
+ data.validuntil = _("unlimited")
elif not data.validuntil:
- data.validuntil = _("not available")
+ data.validuntil = _("not available")
else:
t = time.localtime(data.validuntil)
- data.validuntil = time.strftime("%d.%m.%Y - %H:%M:%S", t)
+ data.validuntil = time.strftime("%d.%m.%Y - %H:%M:%S", t)
try:
data.options['time'] = data.options['time'][0]
@@ -292,7 +292,8 @@ def config():
data.options['limitdl'] = "0"
return render_to_response('settings.html',
- {'conf': {'plugin': plugin_menu, 'general': conf_menu, 'accs': accs}, 'types': PYLOAD.getAccountTypes()},
+ {'conf': {'plugin': plugin_menu, 'general': conf_menu, 'accs': accs},
+ 'types': PYLOAD.getAccountTypes()},
[pre_processor])
@@ -302,10 +303,7 @@ def config():
@route('/pathchooser/<path:path>')
@login_required('STATUS')
def path(file="", path=""):
- if file:
- type = "file"
- else:
- type = "folder"
+ type = "file" if file else "folder"
path = os.path.normpath(unquotepath(path))
@@ -360,10 +358,7 @@ def path(file="", path=""):
except Exception:
continue
- if os.path.isdir(join(cwd, f)):
- data['type'] = 'dir'
- else:
- data['type'] = 'file'
+ data['type'] = 'dir' if os.path.isdir(join(cwd, f)) else 'file'
if os.path.isfile(join(cwd, f)):
data['size'] = os.path.getsize(join(cwd, f))
@@ -434,7 +429,7 @@ def logs(item=-1):
if item < 1 or type(item) is not int:
item = 1 if len(log) - perpage + 1 < 1 else len(log) - perpage + 1
- if type(fro) is datetime: # we will search for datetime
+ if type(fro) is datetime: #: we will search for datetime
item = -1
data = []
@@ -454,16 +449,16 @@ def logs(item=-1):
level = '?'
message = l
if item == -1 and dtime is not None and fro <= dtime:
- item = counter # found our datetime
+ item = counter #: found our datetime
if item >= 0:
data.append({'line': counter, 'date': date + " " + time, 'level': level, 'message': message})
perpagecheck += 1
- if fro is None and dtime is not None: # if fro not set set it to first showed line
+ if fro is None and dtime is not None: #: if fro not set set it to first showed line
fro = dtime
if perpagecheck >= perpage > 0:
break
- if fro is None: # still not set, empty log?
+ if fro is None: #: still not set, empty log?
fro = datetime.now()
if reversed:
data.reverse()
@@ -486,7 +481,7 @@ def admin():
for data in user.itervalues():
data['perms'] = {}
get_permission(data['perms'], data['permission'])
- data['perms']['admin'] = True if data['role'] is 0 else False
+ data['perms']['admin'] = data['role'] is 0
s = request.environ.get('beaker.session')
if request.environ.get('REQUEST_METHOD', "GET") == "POST":
@@ -520,11 +515,7 @@ def setup():
@route('/info')
def info():
conf = PYLOAD.getConfigDict()
-
- if hasattr(os, "uname"):
- extra = os.uname()
- else:
- extra = tuple()
+ extra = os.uname() if hasattr(os, "uname") else tuple()
data = {"python" : sys.version,
"os" : " ".join((os.name, sys.platform) + extra),
diff --git a/pyload/webui/app/utils.py b/pyload/webui/app/utils.py
index 69067d8fe..2753b7feb 100644
--- a/pyload/webui/app/utils.py
+++ b/pyload/webui/app/utils.py
@@ -80,8 +80,8 @@ def set_session(request, info):
def parse_userdata(session):
- return {"name": session.get("name", "Anonymous"),
- "is_admin": True if session.get("role", 1) == 0 else False,
+ return {"name" : session.get("name", "Anonymous"),
+ "is_admin" : session.get("role", 1) == 0,
"is_authenticated": session.get("authenticated", False)}
@@ -115,10 +115,7 @@ def login_required(perm=None):
def toDict(obj):
- ret = {}
- for att in obj.__slots__:
- ret[att] = getattr(obj, att)
- return ret
+ return {att: getattr(obj, att) for att in obj.__slots__}
class CherryPyWSGI(ServerAdapter):