summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Walter Purcaro <vuolter@users.noreply.github.com> 2015-05-12 12:22:20 +0200
committerGravatar Walter Purcaro <vuolter@users.noreply.github.com> 2015-05-12 12:22:20 +0200
commit906bb7c1ecc5c34aa93148894eef763f27eba98e (patch)
tree2f09a639cdd9e414e8f165a667c71a837288d4de
parentRevert damaged logo.png (diff)
downloadpyload-906bb7c1ecc5c34aa93148894eef763f27eba98e.tar.xz
Other import fixes
-rw-r--r--locale/pavement.py4
-rwxr-xr-xpyload/Core.py13
-rw-r--r--pyload/Database/Backend.py5
-rw-r--r--pyload/Thread/Addon.py6
-rw-r--r--pyload/Thread/Decrypter.py3
-rw-r--r--pyload/Thread/Download.py5
-rw-r--r--pyload/Thread/Info.py3
-rw-r--r--pyload/Thread/Plugin.py3
-rw-r--r--pyload/__init__.py4
-rw-r--r--pyload/manager/Plugin.py6
-rw-r--r--pyload/network/HTTPRequest.py6
-rw-r--r--pyload/network/XDCCRequest.py5
-rw-r--r--pyload/plugin/Plugin.py7
-rw-r--r--pyload/plugin/addon/ExtractArchive.py3
-rw-r--r--pyload/plugin/addon/IRCInterface.py5
-rw-r--r--pyload/plugin/addon/UpdateManager.py5
-rw-r--r--pyload/plugin/hoster/LuckyShareNet.py3
-rw-r--r--pyload/plugin/hoster/Xdcc.py5
-rw-r--r--pyload/remote/ClickNLoadBackend.py4
-rw-r--r--pyload/utils/__init__.py15
-rw-r--r--pyload/webui/__init__.py34
-rw-r--r--pyload/webui/app/api.py29
-rw-r--r--pyload/webui/app/cnl.py39
-rw-r--r--pyload/webui/app/json.py62
-rw-r--r--pyload/webui/app/pyloadweb.py83
-rw-r--r--pyload/webui/app/utils.py10
-rwxr-xr-xsetup.py5
-rw-r--r--tests/APIExerciser.py7
-rw-r--r--tests/test_api.py6
29 files changed, 178 insertions, 207 deletions
diff --git a/locale/pavement.py b/locale/pavement.py
index 4a9b523be..6bb9fcfcc 100644
--- a/locale/pavement.py
+++ b/locale/pavement.py
@@ -15,8 +15,8 @@ import re
import subprocess
import tempfile
import urllib
+import zipfile
-from zipfile import ZipFile
PROJECT_DIR = path(__file__).dirname()
sys.path.append(PROJECT_DIR)
@@ -128,7 +128,7 @@ def get_source(options):
pyload.rmtree()
urllib.urlretrieve(options.src, "pyload_src.zip")
- zip = ZipFile("pyload_src.zip")
+ zip = zipfile.ZipFile("pyload_src.zip")
zip.extractall()
path("pyload_src.zip").remove()
diff --git a/pyload/Core.py b/pyload/Core.py
index 545c1d63d..1ec6ee5ed 100755
--- a/pyload/Core.py
+++ b/pyload/Core.py
@@ -5,6 +5,9 @@
from __future__ import with_statement
import __builtin__
+import codecs
+import getopt
+import imp
import logging
import os
import signal
@@ -16,10 +19,6 @@ import traceback
import pyload
import pyload.utils.pylgettext as gettext
-from codecs import getwriter
-from getopt import getopt, GetoptError
-from imp import find_module
-
from pyload import remote
from pyload.Database import DatabaseBackend, FileHandler
from pyload.config.Parser import ConfigParser
@@ -53,7 +52,7 @@ class Core(object):
if len(argv) > 1:
try:
- options, args = getopt(argv[1:], 'vchdusqp:',
+ options, args = getopt.getopt(argv[1:], 'vchdusqp:',
["version", "clear", "clean", "help", "debug", "user",
"setup", "configdir=", "changedir", "daemon",
"quit", "status", "no-remote","pidfile="])
@@ -111,7 +110,7 @@ class Core(object):
elif option == "--no-remote":
self.remote = False
- except GetoptError:
+ except getopt.GetoptError:
print 'Unknown Argument(s) "%s"' % " ".join(argv[1:])
self.print_help()
sys.exit()
@@ -520,7 +519,7 @@ class Core(object):
"""check wether needed tools are installed"""
try:
if python:
- find_module(check_name)
+ imp.find_module(check_name)
else:
pipe = subprocess.PIPE
subprocess.Popen(check_name, stdout=pipe, stderr=pipe)
diff --git a/pyload/Database/Backend.py b/pyload/Database/Backend.py
index 0fc961973..622880e65 100644
--- a/pyload/Database/Backend.py
+++ b/pyload/Database/Backend.py
@@ -8,12 +8,11 @@ try:
except Exception:
import sqlite3
+import Queue
import shutil
import threading
import traceback
-from Queue import Queue
-
from pyload.utils import chmod
@@ -122,7 +121,7 @@ class DatabaseBackend(threading.Thread):
self.setDaemon(True)
self.core = core
- self.jobs = Queue()
+ self.jobs = Queue.Queue()
self.setuplock = threading.Event()
diff --git a/pyload/Thread/Addon.py b/pyload/Thread/Addon.py
index 35168f615..e28fafd29 100644
--- a/pyload/Thread/Addon.py
+++ b/pyload/Thread/Addon.py
@@ -1,13 +1,13 @@
# -*- coding: utf-8 -*-
# @author: RaNaN
+import Queue
+import copy
import os
import sys
import time
import traceback
-from Queue import Queue
-from copy import copy
from pprint import pformat
from types import MethodType
@@ -62,7 +62,7 @@ class AddonThread(PluginThread):
del self.kwargs['thread']
self.f(*self.args, **self.kwargs)
finally:
- local = copy(self.active)
+ local = copy.copy(self.active)
for x in local:
self.finishFile(x)
diff --git a/pyload/Thread/Decrypter.py b/pyload/Thread/Decrypter.py
index b0c4d44e8..d4afac730 100644
--- a/pyload/Thread/Decrypter.py
+++ b/pyload/Thread/Decrypter.py
@@ -1,13 +1,12 @@
# -*- coding: utf-8 -*-
# @author: RaNaN
+import Queue
import os
import sys
import time
import traceback
-from Queue import Queue
-from copy import copy
from pprint import pformat
from types import MethodType
diff --git a/pyload/Thread/Download.py b/pyload/Thread/Download.py
index c7c2470dd..c20c7277e 100644
--- a/pyload/Thread/Download.py
+++ b/pyload/Thread/Download.py
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
# @author: RaNaN
+import Queue
import os
import sys
import time
@@ -8,8 +9,6 @@ import traceback
import pycurl
-from Queue import Queue
-from copy import copy
from pprint import pformat
from types import MethodType
@@ -24,7 +23,7 @@ class DownloadThread(PluginThread):
"""Constructor"""
PluginThread.__init__(self, manager)
- self.queue = Queue() #: job queue
+ self.queue = Queue.Queue() #: job queue
self.active = False
self.start()
diff --git a/pyload/Thread/Info.py b/pyload/Thread/Info.py
index c1960fa9a..780a384bb 100644
--- a/pyload/Thread/Info.py
+++ b/pyload/Thread/Info.py
@@ -1,13 +1,12 @@
# -*- coding: utf-8 -*-
# @author: RaNaN
+import Queue
import os
import sys
import time
import traceback
-from Queue import Queue
-from copy import copy
from pprint import pformat
from types import MethodType
diff --git a/pyload/Thread/Plugin.py b/pyload/Thread/Plugin.py
index 0f1b14d26..ee1418a7d 100644
--- a/pyload/Thread/Plugin.py
+++ b/pyload/Thread/Plugin.py
@@ -3,14 +3,13 @@
from __future__ import with_statement
+import Queue
import os
import sys
import threading
import time
import traceback
-from Queue import Queue
-from copy import copy
from pprint import pformat
from types import MethodType
diff --git a/pyload/__init__.py b/pyload/__init__.py
index 32235c68f..fe1e04437 100644
--- a/pyload/__init__.py
+++ b/pyload/__init__.py
@@ -51,11 +51,11 @@ sys.path.append(os.path.join(pypath, "lib", "Python", "Lib"))
sys.path.append(os.path.join(pypath, "lib"))
-from codecs import getwriter
+import codecs
from pyload.utils import get_console_encoding
-sys.stdout = getwriter(get_console_encoding(sys.stdout.encoding))(sys.stdout, errors="replace")
+sys.stdout = codecs.getwriter(get_console_encoding(sys.stdout.encoding))(sys.stdout, errors="replace")
if homedir == "~" and os.name == "nt":
diff --git a/pyload/manager/Plugin.py b/pyload/manager/Plugin.py
index 02ecc89a5..03bf9cacc 100644
--- a/pyload/manager/Plugin.py
+++ b/pyload/manager/Plugin.py
@@ -8,9 +8,7 @@ import sys
import traceback
import urllib
-from itertools import chain
-
-from SafeEval import const_eval as literal_eval
+import SafeEval
class PluginManager(object):
@@ -153,7 +151,7 @@ class PluginManager(object):
config = self.CONFIG.findall(content)
if config:
try:
- config = literal_eval(config[0].strip().replace("\n", "").replace("\r", ""))
+ config = SafeEval.const_eval(config[0].strip().replace("\n", "").replace("\r", ""))
desc = self.DESC.findall(content)
desc = desc[0][1] if desc else ""
diff --git a/pyload/network/HTTPRequest.py b/pyload/network/HTTPRequest.py
index a27c59ff2..22a4cc604 100644
--- a/pyload/network/HTTPRequest.py
+++ b/pyload/network/HTTPRequest.py
@@ -3,12 +3,12 @@
from __future__ import with_statement
+import codecs
import logging
import urllib
import pycurl
-from codecs import getincrementaldecoder, lookup, BOM_UTF8
from httplib import responses
from cStringIO import StringIO
@@ -267,10 +267,10 @@ class HTTPRequest(object):
try:
# self.log.debug("Decoded %s" % encoding )
- if lookup(encoding).name == 'utf-8' and rep.startswith(BOM_UTF8):
+ if codecs.lookup(encoding).name == 'utf-8' and rep.startswith(codecs.BOM_UTF8):
encoding = 'utf-8-sig'
- decoder = getincrementaldecoder(encoding)("replace")
+ decoder = codecs.getincrementaldecoder(encoding)("replace")
rep = decoder.decode(rep, True)
# TODO: html_unescape as default
diff --git a/pyload/network/XDCCRequest.py b/pyload/network/XDCCRequest.py
index 0d8e90db9..470ab96a7 100644
--- a/pyload/network/XDCCRequest.py
+++ b/pyload/network/XDCCRequest.py
@@ -2,12 +2,11 @@
# @author: jeix
import os
+import select
import socket
import struct
import time
-from select import select
-
from pyload.plugin.Plugin import Abort
@@ -110,7 +109,7 @@ class XDCCRequest(object):
def _keepAlive(self, sock, *readbuffer):
- fdset = select([sock], [], [], 0)
+ fdset = select.select([sock], [], [], 0)
if sock not in fdset[0]:
return
diff --git a/pyload/plugin/Plugin.py b/pyload/plugin/Plugin.py
index 7eeec996f..6648c574f 100644
--- a/pyload/plugin/Plugin.py
+++ b/pyload/plugin/Plugin.py
@@ -4,6 +4,7 @@ from __future__ import with_statement
import traceback
+import itertools
import os
import random
import re
@@ -11,8 +12,6 @@ import time
import urllib
import urlparse
-from itertools import islice
-
if os.name != "nt":
from pwd import getpwnam
from grp import getgrnam
@@ -22,10 +21,10 @@ from pyload.utils import fs_decode, fs_encode, safe_filename, fs_join, encode
def chunks(iterable, size):
it = iter(iterable)
- item = list(islice(it, size))
+ item = list(itertools.islice(it, size))
while item:
yield item
- item = list(islice(it, size))
+ item = list(itertools.islice(it, size))
class Abort(Exception):
diff --git a/pyload/plugin/addon/ExtractArchive.py b/pyload/plugin/addon/ExtractArchive.py
index a2b22e90c..53bf5559d 100644
--- a/pyload/plugin/addon/ExtractArchive.py
+++ b/pyload/plugin/addon/ExtractArchive.py
@@ -51,7 +51,6 @@ try:
except ImportError:
pass
-from copy import copy
if os.name != "nt":
from grp import getgrnam
from pwd import getpwnam
@@ -145,7 +144,7 @@ class ExtractArchive(Addon):
def setup(self):
- self.queue = ArchiveQueue(self, "Queue")
+ self.queue = ArchiveQueue(self, "Queue.Queue")
self.failed = ArchiveQueue(self, "Failed")
self.interval = 60
diff --git a/pyload/plugin/addon/IRCInterface.py b/pyload/plugin/addon/IRCInterface.py
index eb015c362..0c8f2ce8b 100644
--- a/pyload/plugin/addon/IRCInterface.py
+++ b/pyload/plugin/addon/IRCInterface.py
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
import re
+import select
import socket
import ssl
import time
@@ -9,8 +10,6 @@ import traceback
import pycurl
-from select import select
-
from pyload.Api import PackageDoesNotExists, FileDoesNotExists
from pyload.network.RequestFactory import getURL
from pyload.plugin.Addon import Addon
@@ -112,7 +111,7 @@ class IRCInterface(Thread, Addon):
readbuffer = ""
while True:
time.sleep(1)
- fdset = select([self.sock], [], [], 0)
+ fdset = select.select([self.sock], [], [], 0)
if self.sock not in fdset[0]:
continue
diff --git a/pyload/plugin/addon/UpdateManager.py b/pyload/plugin/addon/UpdateManager.py
index 84d282bde..ec147a29a 100644
--- a/pyload/plugin/addon/UpdateManager.py
+++ b/pyload/plugin/addon/UpdateManager.py
@@ -2,13 +2,12 @@
from __future__ import with_statement
+import operator
import os
import re
import sys
import time
-from operator import itemgetter
-
from pyload.network.RequestFactory import getURL
from pyload.plugin.Addon import Expose, Addon, threaded
from pyload.utils import fs_join
@@ -220,7 +219,7 @@ class UpdateManager(Addon):
'name': n,
})
- for plugin in sorted(updatelist, key=itemgetter("type", "name")):
+ for plugin in sorted(updatelist, key=operator.itemgetter("type", "name")):
filename = plugin['name']
type = plugin['type']
version = plugin['version']
diff --git a/pyload/plugin/hoster/LuckyShareNet.py b/pyload/plugin/hoster/LuckyShareNet.py
index b199ab468..d07500d93 100644
--- a/pyload/plugin/hoster/LuckyShareNet.py
+++ b/pyload/plugin/hoster/LuckyShareNet.py
@@ -2,10 +2,9 @@
import re
-from bottle import json_loads
-
from pyload.plugin.captcha.ReCaptcha import ReCaptcha
from pyload.plugin.internal.SimpleHoster import SimpleHoster
+from pyload.utils import json_loads
class LuckyShareNet(SimpleHoster):
diff --git a/pyload/plugin/hoster/Xdcc.py b/pyload/plugin/hoster/Xdcc.py
index d7593a936..85f416aba 100644
--- a/pyload/plugin/hoster/Xdcc.py
+++ b/pyload/plugin/hoster/Xdcc.py
@@ -1,13 +1,12 @@
# -*- coding: utf-8 -*-
import re
+import select
import socket
import struct
import sys
import time
-from select import select
-
from pyload.plugin.Hoster import Hoster
from pyload.utils import fs_join
@@ -120,7 +119,7 @@ class Xdcc(Hoster):
sock.close()
self.fail(_("XDCC Bot did not answer"))
- fdset = select([sock], [], [], 0)
+ fdset = select.select([sock], [], [], 0)
if sock not in fdset[0]:
continue
diff --git a/pyload/remote/ClickNLoadBackend.py b/pyload/remote/ClickNLoadBackend.py
index d9db5b845..99571fe8b 100644
--- a/pyload/remote/ClickNLoadBackend.py
+++ b/pyload/remote/ClickNLoadBackend.py
@@ -2,12 +2,12 @@
# @author: RaNaN
import base64
+import binascii
import re
import urllib
from BaseHTTPServer import HTTPServer, BaseHTTPRequestHandler
from cgi import FieldStorage
-from binascii import unhexlify
try:
from Crypto.Cipher import AES
@@ -134,7 +134,7 @@ class CNLHandler(BaseHTTPRequestHandler):
crypted = base64.standard_b64decode(urllib.unquote(crypted.replace(" ", "+")))
jk = "%s f()" % jk
jk = js.eval(jk)
- Key = unhexlify(jk)
+ Key = binascii.unhexlify(jk)
IV = Key
obj = AES.new(Key, AES.MODE_CBC, IV)
diff --git a/pyload/utils/__init__.py b/pyload/utils/__init__.py
index 864a214cc..3c525caeb 100644
--- a/pyload/utils/__init__.py
+++ b/pyload/utils/__init__.py
@@ -4,6 +4,7 @@
""" Store all useful functions here """
import bitmath
+import htmlentitydefs
import os
import re
import string
@@ -11,18 +12,10 @@ import sys
import time
import urllib
-# from gettext import gettext
-import pylgettext as gettext
-from htmlentitydefs import name2codepoint
+import pyload.utils.pylgettext as gettext
# abstraction layer for json operations
-try:
- import simplejson as json
-except ImportError:
- import json
-
-json_loads = json.loads
-json_dumps = json.dumps
+from bottle import json_loads
def os.chmod(*args):
@@ -232,7 +225,7 @@ def fixup(m):
# named entity
try:
name = text[1:-1]
- text = unichr(name2codepoint[name])
+ text = unichr(htmlentitydefs.name2codepoint[name])
except KeyError:
pass
diff --git a/pyload/webui/__init__.py b/pyload/webui/__init__.py
index 58d60b5cc..472e1a4f7 100644
--- a/pyload/webui/__init__.py
+++ b/pyload/webui/__init__.py
@@ -3,27 +3,27 @@
import os
import sys
-import pyload.utils.pylgettext as gettext
-THEME_DIR = os.path.abspath(os.path.join(dirname(__file__), "themes"))
-PYLOAD_DIR = os.path.abspath(os.path.join(THEME_DIR, "..", "..", ".."))
+import bottle
-sys.path.append(PYLOAD_DIR)
+import pyload.utils.pylgettext as gettext
+
+from jinja2 import Environment, FileSystemLoader, PrefixLoader, FileSystemBytecodeCache
+from pyload.Thread import Server
+from pyload.Webui.middlewares import StripPathMiddleware, GZipMiddleWare, PrefixMiddleware
+from pyload.network.JsEngine import JsEngine
from pyload.utils import decode, formatSize
-import bottle
-from bottle import run, app
-from jinja2 import Environment, FileSystemLoader, PrefixLoader, FileSystemBytecodeCache
-from middlewares import StripPathMiddleware, GZipMiddleWare, PrefixMiddleware
+THEME_DIR = os.path.abspath(os.path.join(dirname(__file__), "themes"))
+PYLOAD_DIR = os.path.abspath(os.path.join(THEME_DIR, "..", "..", ".."))
+
+sys.path.append(PYLOAD_DIR)
SETUP = None
PYLOAD = None
-from pyload.Thread import Server
-from pyload.network.JsEngine import JsEngine
-
if not Server.core:
if Server.setup:
SETUP = Server.setup
@@ -91,7 +91,7 @@ session_opts = {
'session.auto': False
}
-web = StripPathMiddleware(SessionMiddleware(app(), session_opts))
+web = StripPathMiddleware(SessionMiddleware(bottle.app(), session_opts))
web = GZipMiddleWare(web)
if PREFIX:
@@ -101,11 +101,11 @@ import pyload.webui.app
def run_auto(host="0.0.0.0", port="8000"):
- run(app=web, host=host, port=port, server="auto", quiet=True)
+ bottle.run(app=web, host=host, port=port, server="auto", quiet=True)
def run_lightweight(host="0.0.0.0", port="8000"):
- run(app=web, host=host, port=port, server="bjoern", quiet=True)
+ bottle.run(app=web, host=host, port=port, server="bjoern", quiet=True)
def run_threaded(host="0.0.0.0", port="8000", theads=3, cert="", key=""):
@@ -119,10 +119,8 @@ def run_threaded(host="0.0.0.0", port="8000", theads=3, cert="", key=""):
from pyload.webui.app.utils import CherryPyWSGI
- run(app=web, host=host, port=port, server=CherryPyWSGI, quiet=True)
+ bottle.run(app=web, host=host, port=port, server=CherryPyWSGI, quiet=True)
def run_fcgi(host="0.0.0.0", port="8000"):
- from bottle import FlupFCGIServer
-
- run(app=web, host=host, port=port, server=FlupFCGIServer, quiet=True)
+ bottle.run(app=web, host=host, port=port, server=bottle.FlupFCGIServer, quiet=True)
diff --git a/pyload/webui/app/api.py b/pyload/webui/app/api.py
index 35dbe9009..99a7c2998 100644
--- a/pyload/webui/app/api.py
+++ b/pyload/webui/app/api.py
@@ -1,12 +1,11 @@
# -*- coding: utf-8 -*-
+import itertools
import traceback
import urllib
-from itertools import chain
-
-from SafeEval import const_eval as literal_eval
-from bottle import route, request, response, HTTPError
+import SafeEval
+import bottle
from pyload.Api import BaseObject
from pyload.utils import json
@@ -24,8 +23,8 @@ 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')
+@bottle.route('/api/<func><args:re:[a-zA-Z0-9\-_/\"\'\[\]%{},]*>')
+@bottle.route('/api/<func><args:re:[a-zA-Z0-9\-_/\"\'\[\]%{},]*>', method='POST')
def call_api(func, args=""):
response.headers.replace("Content-type", "application/json")
response.headers.append("Cache-Control", "no-cache, must-revalidate")
@@ -35,15 +34,15 @@ def call_api(func, args=""):
s = s.get_by_id(request.POST['session'])
if not s or not s.get("authenticated", False):
- return HTTPError(403, json.dumps("Forbidden"))
+ return bottle.HTTPError(403, json.dumps("Forbidden"))
if not PYLOAD.isAuthorized(func, {"role": s['role'], "permission": s['perms']}):
- return HTTPError(401, json.dumps("Unauthorized"))
+ return bottle.HTTPError(401, json.dumps("Unauthorized"))
args = args.split("/")[1:]
kwargs = {}
- for x, y in chain(request.GET.iteritems(), request.POST.iteritems()):
+ for x, y in itertools.chain(request.GET.iteritems(), request.POST.iteritems()):
if x == "session":
continue
kwargs[x] = urllib.unquote(y)
@@ -52,23 +51,23 @@ def call_api(func, args=""):
return callApi(func, *args, **kwargs)
except Exception, e:
traceback.print_exc()
- return HTTPError(500, json.dumps({"error": e.message, "traceback": traceback.format_exc()}))
+ return bottle.HTTPError(500, json.dumps({"error": e.message, "traceback": traceback.format_exc()}))
def callApi(func, *args, **kwargs):
if not hasattr(PYLOAD.EXTERNAL, func) or func.startswith("_"):
print "Invalid API call", func
- return HTTPError(404, json.dumps("Not Found"))
+ return bottle.HTTPError(404, json.dumps("Not Found"))
- result = getattr(PYLOAD, func)(*[literal_eval(x) for x in args],
- **dict((x, literal_eval(y)) for x, y in kwargs.iteritems()))
+ result = getattr(PYLOAD, func)(*[SafeEval.const_eval(x) for x in args],
+ **dict((x, SafeEval.const_eval(y)) for x, y in kwargs.iteritems()))
# null is invalid json response
return json.dumps(result or True, cls=TBaseEncoder)
# post -> username, password
-@route('/api/login', method='POST')
+@bottle.route('/api/login', method='POST')
def login():
response.headers.replace("Content-type", "application/json")
response.headers.append("Cache-Control", "no-cache, must-revalidate")
@@ -91,7 +90,7 @@ def login():
return json.dumps(True)
-@route('/api/logout')
+@bottle.route('/api/logout')
def logout():
response.headers.replace("Content-type", "application/json")
response.headers.append("Cache-Control", "no-cache, must-revalidate")
diff --git a/pyload/webui/app/cnl.py b/pyload/webui/app/cnl.py
index 7202a2db4..465e087e5 100644
--- a/pyload/webui/app/cnl.py
+++ b/pyload/webui/app/cnl.py
@@ -3,13 +3,12 @@
from __future__ import with_statement
import base64
+import binascii
import os
import re
import urllib
-from binascii import unhexlify
-
-from bottle import route, request, HTTPError
+import bottle
from pyload.webui import PYLOAD, DL_ROOT, JS
@@ -28,20 +27,20 @@ def local_check(function):
or request.environ.get("HTTP_HOST", "0") in ("127.0.0.1:9666", "localhost:9666"):
return function(*args, **kwargs)
else:
- return HTTPError(403, "Forbidden")
+ return bottle.HTTPError(403, "Forbidden")
return _view
-@route('/flash')
-@route('/flash/<id>')
-@route('/flash', method='POST')
+@bottle.route('/flash')
+@bottle.route('/flash/<id>')
+@bottle.route('/flash', method='POST')
@local_check
def flash(id="0"):
return "JDownloader\r\n"
-@route('/flash/add', method='POST')
+@bottle.route('/flash/add', method='POST')
@local_check
def add(request):
package = request.POST.get('referer', None)
@@ -55,7 +54,7 @@ def add(request):
return ""
-@route('/flash/addcrypted', method='POST')
+@bottle.route('/flash/addcrypted', method='POST')
@local_check
def addcrypted():
package = request.forms.get('referer', 'ClickNLoad Package')
@@ -68,12 +67,12 @@ def addcrypted():
try:
PYLOAD.addPackage(package, [dlc_path], 0)
except Exception:
- return HTTPError()
+ return bottle.HTTPError()
else:
return "success\r\n"
-@route('/flash/addcrypted2', method='POST')
+@bottle.route('/flash/addcrypted2', method='POST')
@local_check
def addcrypted2():
package = request.forms.get("source", None)
@@ -99,7 +98,7 @@ def addcrypted2():
print "Could not decrypt key, please install py-spidermonkey or ossp-js"
try:
- Key = unhexlify(jk)
+ Key = binascii.unhexlify(jk)
except Exception:
print "Could not decrypt key, please install py-spidermonkey or ossp-js"
return "failed"
@@ -122,14 +121,14 @@ def addcrypted2():
return "success\r\n"
-@route('/flashgot_pyload')
-@route('/flashgot_pyload', method='POST')
-@route('/flashgot')
-@route('/flashgot', method='POST')
+@bottle.route('/flashgot_pyload')
+@bottle.route('/flashgot_pyload', method='POST')
+@bottle.route('/flashgot')
+@bottle.route('/flashgot', method='POST')
@local_check
def flashgot():
if request.environ['HTTP_REFERER'] not in ("http://localhost:9666/flashgot", "http://127.0.0.1:9666/flashgot"):
- return HTTPError()
+ return bottle.HTTPError()
autostart = int(request.forms.get('autostart', 0))
package = request.forms.get('package', None)
@@ -144,7 +143,7 @@ def flashgot():
return ""
-@route('/crossdomain.xml')
+@bottle.route('/crossdomain.xml')
@local_check
def crossdomain():
rep = "<?xml version=\"1.0\"?>\n"
@@ -155,7 +154,7 @@ def crossdomain():
return rep
-@route('/flash/checkSupportForUrl')
+@bottle.route('/flash/checkSupportForUrl')
@local_check
def checksupport():
url = request.GET.get("url")
@@ -165,7 +164,7 @@ def checksupport():
return str(supported).lower()
-@route('/jdcheck.js')
+@bottle.route('/jdcheck.js')
@local_check
def jdcheck():
rep = "jdownloader=true;\n"
diff --git a/pyload/webui/app/json.py b/pyload/webui/app/json.py
index 24952cc34..a7fe8dcfb 100644
--- a/pyload/webui/app/json.py
+++ b/pyload/webui/app/json.py
@@ -6,7 +6,7 @@ import os
import shutil
import traceback
-from bottle import route, request, HTTPError
+import bottle
from pyload.utils import decode, formatSize
from pyload.webui import PYLOAD
@@ -25,8 +25,8 @@ def get_sort_key(item):
return item['order']
-@route('/json/status')
-@route('/json/status', method='POST')
+@bottle.route('/json/status')
+@bottle.route('/json/status', method='POST')
@login_required('LIST')
def status():
try:
@@ -34,11 +34,11 @@ def status():
status['captcha'] = PYLOAD.isCaptchaWaiting()
return status
except Exception:
- return HTTPError()
+ return bottle.HTTPError()
-@route('/json/links')
-@route('/json/links', method='POST')
+@bottle.route('/json/links')
+@bottle.route('/json/links', method='POST')
@login_required('LIST')
def links():
try:
@@ -61,10 +61,10 @@ def links():
return data
except Exception, e:
traceback.print_exc()
- return HTTPError()
+ return bottle.HTTPError()
-@route('/json/packages')
+@bottle.route('/json/packages')
@login_required('LIST')
def packages():
print "/json/packages"
@@ -79,10 +79,10 @@ def packages():
return data
except Exception:
- return HTTPError()
+ return bottle.HTTPError()
-@route('/json/package/<id:int>')
+@bottle.route('/json/package/<id:int>')
@login_required('LIST')
def package(id):
try:
@@ -114,10 +114,10 @@ def package(id):
except Exception:
traceback.print_exc()
- return HTTPError()
+ return bottle.HTTPError()
-@route('/json/package_order/<ids>')
+@bottle.route('/json/package_order/<ids>')
@login_required('ADD')
def package_order(ids):
try:
@@ -125,20 +125,20 @@ def package_order(ids):
PYLOAD.orderPackage(int(pid), int(pos))
return {"response": "success"}
except Exception:
- return HTTPError()
+ return bottle.HTTPError()
-@route('/json/abort_link/<id:int>')
+@bottle.route('/json/abort_link/<id:int>')
@login_required('DELETE')
def abort_link(id):
try:
PYLOAD.stopDownloads([id])
return {"response": "success"}
except Exception:
- return HTTPError()
+ return bottle.HTTPError()
-@route('/json/link_order/<ids>')
+@bottle.route('/json/link_order/<ids>')
@login_required('ADD')
def link_order(ids):
try:
@@ -146,11 +146,11 @@ def link_order(ids):
PYLOAD.orderFile(int(pid), int(pos))
return {"response": "success"}
except Exception:
- return HTTPError()
+ return bottle.HTTPError()
-@route('/json/add_package')
-@route('/json/add_package', method='POST')
+@bottle.route('/json/add_package')
+@bottle.route('/json/add_package', method='POST')
@login_required('ADD')
def add_package():
name = request.forms.get("add_name", "New Package").strip()
@@ -184,17 +184,17 @@ def add_package():
PYLOAD.setPackageData(pack, data)
-@route('/json/move_package/<dest:int>/<id:int>')
+@bottle.route('/json/move_package/<dest:int>/<id:int>')
@login_required('MODIFY')
def move_package(dest, id):
try:
PYLOAD.movePackage(dest, id)
return {"response": "success"}
except Exception:
- return HTTPError()
+ return bottle.HTTPError()
-@route('/json/edit_package', method='POST')
+@bottle.route('/json/edit_package', method='POST')
@login_required('MODIFY')
def edit_package():
try:
@@ -207,11 +207,11 @@ def edit_package():
return {"response": "success"}
except Exception:
- return HTTPError()
+ return bottle.HTTPError()
-@route('/json/set_captcha')
-@route('/json/set_captcha', method='POST')
+@bottle.route('/json/set_captcha')
+@bottle.route('/json/set_captcha', method='POST')
@login_required('ADD')
def set_captcha():
if request.environ.get('REQUEST_METHOD', "GET") == "POST":
@@ -230,7 +230,7 @@ def set_captcha():
return {'captcha': False}
-@route('/json/load_config/<category>/<section>')
+@bottle.route('/json/load_config/<category>/<section>')
@login_required("SETTINGS")
def load_config(category, section):
conf = None
@@ -252,7 +252,7 @@ def load_config(category, section):
"skey": section, "section": conf[section]})
-@route('/json/save_config/<category>', method='POST')
+@bottle.route('/json/save_config/<category>', method='POST')
@login_required("SETTINGS")
def save_config(category):
for key, value in request.POST.iteritems():
@@ -266,7 +266,7 @@ def save_config(category):
PYLOAD.setConfigValue(section, option, decode(value), category)
-@route('/json/add_account', method='POST')
+@bottle.route('/json/add_account', method='POST')
@login_required("ACCOUNTS")
def add_account():
login = request.POST['account_login']
@@ -276,7 +276,7 @@ def add_account():
PYLOAD.updateAccount(type, login, password)
-@route('/json/update_accounts', method='POST')
+@bottle.route('/json/update_accounts', method='POST')
@login_required("ACCOUNTS")
def update_accounts():
deleted = [] #: dont update deleted accs or they will be created again
@@ -303,7 +303,7 @@ def update_accounts():
PYLOAD.removeAccount(plugin, user)
-@route('/json/change_password', method='POST')
+@bottle.route('/json/change_password', method='POST')
def change_password():
user = request.POST['user_login']
oldpw = request.POST['login_current_password']
@@ -311,4 +311,4 @@ def change_password():
if not PYLOAD.changePassword(user, oldpw, newpw):
print "Wrong password"
- return HTTPError()
+ return bottle.HTTPError()
diff --git a/pyload/webui/app/pyloadweb.py b/pyload/webui/app/pyloadweb.py
index 8974e0896..27532b86e 100644
--- a/pyload/webui/app/pyloadweb.py
+++ b/pyload/webui/app/pyloadweb.py
@@ -2,14 +2,13 @@
# @author: RaNaN
import datetime
+import operator
import os
import sys
import time
import urllib
-from operator import itemgetter, attrgetter
-
-from bottle import route, static_file, request, response, redirect, error
+import bottle
from pyload.webui import PYLOAD, PYLOAD_DIR, THEME_DIR, THEME, SETUP, env
@@ -57,17 +56,17 @@ def base(messages):
# Views
-@error(403)
+@bottle.error(403)
def error403(code):
return "The parameter you passed has the wrong format"
-@error(404)
+@bottle.error(404)
def error404(code):
return "Sorry, this page does not exist"
-@error(500)
+@bottle.error(500)
def error500(error):
traceback = error.traceback
if traceback:
@@ -76,7 +75,7 @@ def error500(error):
traceback.replace("\n", "<br>") if traceback else "No Traceback"])
-@route('/<theme>/<file:re:(.+/)?[^/]+\.min\.[^/]+>')
+@bottle.route('/<theme>/<file:re:(.+/)?[^/]+\.min\.[^/]+>')
def server_min(theme, file):
filename = os.path.join(THEME_DIR, THEME, theme, file)
if not os.path.isfile(filename):
@@ -87,7 +86,7 @@ def server_min(theme, file):
return server_static(theme, file)
-@route('/<theme>/<file:re:.+\.js>')
+@bottle.route('/<theme>/<file:re:.+\.js>')
def server_js(theme, file):
response.headers['Content-Type'] = "text/javascript; charset=UTF-8"
@@ -102,34 +101,34 @@ def server_js(theme, file):
return server_static(theme, file)
-@route('/<theme>/<file:path>')
+@bottle.route('/<theme>/<file:path>')
def server_static(theme, file):
response.headers['Expires'] = time.strftime("%a, %d %b %Y %H:%M:%S GMT",
time.gmtime(time.time() + 24 * 7 * 60 * 60))
response.headers['Cache-control'] = "public"
- return static_file(file, root=join(THEME_DIR, THEME, theme))
+ return bottle.static_file(file, root=join(THEME_DIR, THEME, theme))
-@route('/favicon.ico')
+@bottle.route('/favicon.ico')
def favicon():
- return static_file("icon.ico", root=join(PYLOAD_DIR, "docs", "resources"))
+ return bottle.static_file("icon.ico", root=join(PYLOAD_DIR, "docs", "resources"))
-@route('/login', method="GET")
+@bottle.route('/login', method="GET")
def login():
if not PYLOAD and SETUP:
- redirect("/setup")
+ bottle.redirect("/setup")
else:
return render_to_response("login.html", proc=[pre_processor])
-@route('/nopermission')
+@bottle.route('/nopermission')
def nopermission():
return base([_("You dont have permission to access this page.")])
-@route('/login', method='POST')
+@bottle.route('/login', method='POST')
def login_post():
user = request.forms.get("username")
password = request.forms.get("password")
@@ -140,18 +139,18 @@ def login_post():
return render_to_response("login.html", {"errors": True}, [pre_processor])
set_session(request, info)
- return redirect("/")
+ return bottle.redirect("/")
-@route('/logout')
+@bottle.route('/logout')
def logout():
s = request.environ.get('beaker.session')
s.delete()
return render_to_response("logout.html", proc=[pre_processor])
-@route('/')
-@route('/home')
+@bottle.route('/')
+@bottle.route('/home')
@login_required("LIST")
def home():
try:
@@ -159,7 +158,7 @@ def home():
except Exception:
s = request.environ.get('beaker.session')
s.delete()
- return redirect("/login")
+ return bottle.redirect("/login")
for link in res:
if link['status'] == 12:
@@ -168,27 +167,27 @@ def home():
return render_to_response("home.html", {"res": res}, [pre_processor])
-@route('/queue')
+@bottle.route('/queue')
@login_required("LIST")
def queue():
queue = PYLOAD.getQueue()
- queue.sort(key=attrgetter("order"))
+ queue.sort(key=operator.attrgetter("order"))
return render_to_response('queue.html', {'content': queue, 'target': 1}, [pre_processor])
-@route('/collector')
+@bottle.route('/collector')
@login_required('LIST')
def collector():
queue = PYLOAD.getCollector()
- queue.sort(key=attrgetter("order"))
+ queue.sort(key=operator.attrgetter("order"))
return render_to_response('queue.html', {'content': queue, 'target': 0}, [pre_processor])
-@route('/downloads')
+@bottle.route('/downloads')
@login_required('DOWNLOAD')
def downloads():
root = PYLOAD.getConfigValue("general", "download_folder")
@@ -224,7 +223,7 @@ def downloads():
return render_to_response('downloads.html', {'files': data}, [pre_processor])
-@route('/downloads/get/<path:path>')
+@bottle.route('/downloads/get/<path:path>')
@login_required("DOWNLOAD")
def get_download(path):
path = urllib.unquote(path).decode("utf8")
@@ -233,10 +232,10 @@ def get_download(path):
root = PYLOAD.getConfigValue("general", "download_folder")
path = path.replace("..", "")
- return static_file(fs_encode(path), fs_encode(root))
+ return bottle.static_file(fs_encode(path), fs_encode(root))
-@route('/settings')
+@bottle.route('/settings')
@login_required('SETTINGS')
def config():
conf = PYLOAD.getConfig()
@@ -294,10 +293,10 @@ def config():
[pre_processor])
-@route('/filechooser')
-@route('/pathchooser')
-@route('/filechooser/<file:path>')
-@route('/pathchooser/<path:path>')
+@bottle.route('/filechooser')
+@bottle.route('/pathchooser')
+@bottle.route('/filechooser/<file:path>')
+@bottle.route('/pathchooser/<path:path>')
@login_required('STATUS')
def os.path(file="", path=""):
type = "file" if file else "folder"
@@ -371,17 +370,17 @@ def os.path(file="", path=""):
files.append(data)
- files = sorted(files, key=itemgetter('type', 'sort'))
+ files = sorted(files, key=operator.itemgetter('type', 'sort'))
return render_to_response('pathchooser.html',
{'cwd': cwd, 'files': files, 'parentdir': parentdir, 'type': type, 'oldfile': oldfile,
'absolute': abs}, [])
-@route('/logs')
-@route('/logs', method='POST')
-@route('/logs/<item>')
-@route('/logs/<item>', method='POST')
+@bottle.route('/logs')
+@bottle.route('/logs', method='POST')
+@bottle.route('/logs/<item>')
+@bottle.route('/logs/<item>', method='POST')
@login_required('LOGS')
def logs(item=-1):
s = request.environ.get('beaker.session')
@@ -467,8 +466,8 @@ def logs(item=-1):
[pre_processor])
-@route('/admin')
-@route('/admin', method='POST')
+@bottle.route('/admin')
+@bottle.route('/admin', method='POST')
@login_required("ADMIN")
def admin():
# convert to dict
@@ -504,12 +503,12 @@ def admin():
return render_to_response("admin.html", {"users": user, "permlist": perms}, [pre_processor])
-@route('/setup')
+@bottle.route('/setup')
def setup():
return base([_("Run pyload.py -s to access the setup.")])
-@route('/info')
+@bottle.route('/info')
def info():
conf = PYLOAD.getConfigDict()
extra = os.uname() if hasattr(os, "uname") else tuple()
diff --git a/pyload/webui/app/utils.py b/pyload/webui/app/utils.py
index 695162f91..3526f2615 100644
--- a/pyload/webui/app/utils.py
+++ b/pyload/webui/app/utils.py
@@ -3,7 +3,7 @@
import os
-from bottle import request, HTTPError, redirect, ServerAdapter
+import bottle
from pyload.Api import has_permission, PERMS, ROLE
from pyload.webui import env, THEME
@@ -97,16 +97,16 @@ def login_required(perm=None):
perms = parse_permissions(s)
if perm not in perms or not perms[perm]:
if request.headers.get('X-Requested-With') == 'XMLHttpRequest':
- return HTTPError(403, "Forbidden")
+ return bottle.HTTPError(403, "Forbidden")
else:
- return redirect("/nopermission")
+ return bottle.redirect("/nopermission")
return func(*args, **kwargs)
else:
if request.headers.get('X-Requested-With') == 'XMLHttpRequest':
- return HTTPError(403, "Forbidden")
+ return bottle.HTTPError(403, "Forbidden")
else:
- return redirect("/login")
+ return bottle.redirect("/login")
return _view
diff --git a/setup.py b/setup.py
index 6e2efe85c..319f23be4 100755
--- a/setup.py
+++ b/setup.py
@@ -2,16 +2,15 @@
# -*- coding: utf-8 -*-
import os
+import setuptools
import sys
import pyload
-from setuptools import setup
-
PROJECT_DIR = path.abspath(path.join(__file__, ".."))
-setup(
+setuptools.setup(
name="pyload",
version=pyload.__version__,
diff --git a/tests/APIExerciser.py b/tests/APIExerciser.py
index 02bfef20d..d2a069c78 100644
--- a/tests/APIExerciser.py
+++ b/tests/APIExerciser.py
@@ -4,14 +4,13 @@
from __future__ import with_statement
import gc
+import math
import random
import string
import threading
import time
import traceback
-from math import floor
-
from pyload.remote.thriftbackend.ThriftClient import ThriftClient, Destination
@@ -116,7 +115,7 @@ class APIExerciser(threading.Thread):
name = "".join(random.sample(string.ascii_letters, 10))
urls = createURLs()
- self.api.addPackage(name, urls, random.choice([Destination.Queue, Destination.Collector]))
+ self.api.addPackage(name, urls, random.choice([Destination.Queue.Queue, Destination.Collector]))
def deleteFiles(self):
@@ -139,7 +138,7 @@ class APIExerciser(threading.Thread):
pids = [p.pid for p in info]
if pids:
- pids = random.sample(pids, random.randint(1, max(floor(len(pids) / 2.5), 1)))
+ pids = random.sample(pids, random.randint(1, max(math.floor(len(pids) / 2.5), 1)))
self.api.deletePackages(pids)
diff --git a/tests/test_api.py b/tests/test_api.py
index 1e02d8aa3..ca02f7a2c 100644
--- a/tests/test_api.py
+++ b/tests/test_api.py
@@ -1,9 +1,9 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
-import APIExerciser
+import nose
-from nose.tools import nottest
+import APIExerciser
class TestApi(object):
@@ -18,7 +18,7 @@ class TestApi(object):
# takes really long, only test when needed
- @nottest
+ @nose.tools.nottest
def test_random(self):
for _i in xrange(0, 100):
self.api.testAPI()