summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Walter Purcaro <vuolter@users.noreply.github.com> 2015-04-17 17:54:19 +0200
committerGravatar Walter Purcaro <vuolter@users.noreply.github.com> 2015-04-17 17:54:19 +0200
commite48abf98766b0a9c5799f17073d867dc09b23663 (patch)
tree08e907597b172e5879c59eea4421b58a4b73fd46
parentSpare code cosmetics (4) (diff)
downloadpyload-e48abf98766b0a9c5799f17073d867dc09b23663.tar.xz
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
-rw-r--r--pyload/manager/Thread.py7
-rw-r--r--pyload/utils/__init__.py14
-rw-r--r--pyload/webui/app/api.py9
-rw-r--r--pyload/webui/filters.py9
4 files changed, 23 insertions, 16 deletions
diff --git a/pyload/manager/Thread.py b/pyload/manager/Thread.py
index e24b20d59..b255523d6 100644
--- a/pyload/manager/Thread.py
+++ b/pyload/manager/Thread.py
@@ -51,7 +51,7 @@ class ThreadManager(object):
pycurl.global_init(pycurl.GLOBAL_DEFAULT)
- for i in range(0, self.core.config.get("download", "max_downloads")):
+ for _i in range(0, self.core.config.get("download", "max_downloads")):
self.createThread()
@@ -206,7 +206,7 @@ class ThreadManager(object):
("http://checkip.dyndns.org/", ".*Current IP Address: (\S+)</body>.*")]
ip = ""
- for i in range(10):
+ for _i in range(10):
try:
sv = choice(services)
ip = getURL(sv[0])
@@ -285,7 +285,7 @@ class ThreadManager(object):
if free and not self.pause:
thread = free[0]
- #self.downloaded += 1
+ # self.downloaded += 1
thread.put(job)
else:
@@ -299,7 +299,6 @@ class ThreadManager(object):
if job:
job.initPlugin()
thread = DecrypterThread(self, job)
-
else:
thread = DecrypterThread(self, job)
diff --git a/pyload/utils/__init__.py b/pyload/utils/__init__.py
index 648432c26..2e23bf99b 100644
--- a/pyload/utils/__init__.py
+++ b/pyload/utils/__init__.py
@@ -116,13 +116,17 @@ def compare_time(start, end):
start = map(int, start)
end = map(int, end)
- if start == end: return True
+ if start == end:
+ return True
now = list(time.localtime()[3:5])
- if start < now < end: return True
- elif start > end and (now > start or now < end): return True
- elif start < now > end < start: return True
- else: return False
+ if start < now < end:
+ return True
+ elif start > end and (now > start or now < end):
+ return True
+ elif start < now > end < start:
+ return True
+ return False
def formatSize(size):
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
diff --git a/pyload/webui/filters.py b/pyload/webui/filters.py
index c784b248d..ea4b159fa 100644
--- a/pyload/webui/filters.py
+++ b/pyload/webui/filters.py
@@ -18,7 +18,7 @@ except Exception:
path_list = abspath(path).split(sep)
# Work out how much of the filepath is shared by start and path.
i = len(commonprefix([start_list, path_list]))
- rel_list = [pardir] * (len(start_list)-i) + path_list[i:]
+ rel_list = [pardir] * (len(start_list) - i) + path_list[i:]
if not rel_list:
return curdir
return join(*rel_list)
@@ -32,6 +32,7 @@ def quotepath(path):
except Exception:
return ""
+
def unquotepath(path):
try:
return path.replace(quotechar, "../")
@@ -40,6 +41,7 @@ def unquotepath(path):
except Exception:
return ""
+
def path_make_absolute(path):
p = os.path.abspath(path)
if p[-1] == os.path.sep:
@@ -47,6 +49,7 @@ def path_make_absolute(path):
else:
return p + os.path.sep
+
def path_make_relative(path):
p = relpath(path)
if p[-1] == os.path.sep:
@@ -54,10 +57,12 @@ def path_make_relative(path):
else:
return p + os.path.sep
+
def truncate(value, n):
if (n - len(value)) < 3:
- return value[:n]+"..."
+ return value[:n] + "..."
return value
+
def date(date, format):
return date