summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Walter Purcaro <vuolter@users.noreply.github.com> 2015-05-01 18:11:25 +0200
committerGravatar Walter Purcaro <vuolter@users.noreply.github.com> 2015-05-01 18:11:25 +0200
commitc126f738bd5be581d5321521eedc9b14a8165a0e (patch)
tree418989bfa81bfd30085f09102df53f6f58b00f14
parentUse 'import' instead 'from' (1) (diff)
downloadpyload-c126f738bd5be581d5321521eedc9b14a8165a0e.tar.xz
Use 'import' instead 'from' (2)
-rw-r--r--locale/pavement.py33
-rwxr-xr-xpyload/Core.py52
-rw-r--r--pyload/cli/Cli.py40
-rw-r--r--pyload/config/Parser.py15
-rw-r--r--pyload/database/Backend.py32
-rw-r--r--pyload/database/File.py4
-rw-r--r--pyload/datatype/File.py9
-rw-r--r--pyload/manager/Account.py11
-rw-r--r--pyload/manager/Addon.py4
-rw-r--r--pyload/manager/Captcha.py9
-rw-r--r--pyload/manager/Plugin.py4
-rw-r--r--pyload/manager/Remote.py7
-rw-r--r--pyload/manager/Thread.py30
-rw-r--r--pyload/manager/event/Scheduler.py9
-rw-r--r--pyload/manager/thread/Addon.py10
-rw-r--r--pyload/manager/thread/Decrypter.py16
-rw-r--r--pyload/manager/thread/Download.py22
-rw-r--r--pyload/manager/thread/Info.py16
-rw-r--r--pyload/manager/thread/Plugin.py14
-rw-r--r--pyload/network/Bucket.py6
-rw-r--r--pyload/network/HTTPDownload.py17
-rw-r--r--pyload/network/RequestFactory.py6
-rw-r--r--pyload/plugin/Account.py31
-rw-r--r--pyload/plugin/Addon.py4
-rw-r--r--pyload/plugin/Plugin.py29
-rw-r--r--pyload/plugin/account/TusfilesNet.py2
-rw-r--r--pyload/plugin/addon/ClickNLoad.py5
-rw-r--r--pyload/plugin/addon/HotFolder.py5
-rw-r--r--pyload/plugin/addon/IRCInterface.py4
-rw-r--r--pyload/plugin/extractor/UnRar.py6
-rw-r--r--pyload/plugin/hoster/FilerNet.py1
-rw-r--r--pyload/plugin/hoster/GigapetaCom.py1
-rw-r--r--pyload/plugin/hoster/QuickshareCz.py1
-rw-r--r--pyload/plugin/hoster/UnibytesCom.py1
-rw-r--r--pyload/plugin/internal/XFSHoster.py1
-rw-r--r--pyload/remote/thriftbackend/ThriftClient.py12
-rw-r--r--pyload/utils/__init__.py4
-rw-r--r--pyload/webui/app/api.py18
-rw-r--r--pyload/webui/app/json.py13
-rw-r--r--tests/APIExerciser.py40
40 files changed, 262 insertions, 282 deletions
diff --git a/locale/pavement.py b/locale/pavement.py
index 03acf3dcc..fb52243a6 100644
--- a/locale/pavement.py
+++ b/locale/pavement.py
@@ -7,11 +7,12 @@ from paver.easy import *
from paver.setuputils import setup
from paver.doctools import cog
+import glob
import os
import sys
import shutil
import re
-from glob import glob
+
from tempfile import mkdtemp
from urllib import urlretrieve
from subprocess import call, Popen, PIPE
@@ -133,10 +134,10 @@ def get_source(options):
urlretrieve(options.src, "pyload_src.zip")
zip = ZipFile("pyload_src.zip")
zip.extractall()
- path("pyload_src.zip").remove()
+ path("pyload_src.zip").reshutil.move()
folder = [x for x in path(".").dirs() if x.name.startswith("spoob-pyload-")][0]
- folder.move(pyload)
+ folder.shutil.move(pyload)
change_mode(pyload, 0644)
change_mode(pyload, 0755, folder=True)
@@ -145,8 +146,8 @@ def get_source(options):
if file.name.endswith(".py"):
file.chmod(0755)
- (pyload / ".hgtags").remove()
- (pyload / ".gitignore").remove()
+ (pyload / ".hgtags").reshutil.move()
+ (pyload / ".gitignore").reshutil.move()
#(pyload / "docs").rmtree()
f = open(pyload / "__init__.py", "wb")
@@ -189,7 +190,7 @@ def thrift(options):
p.communicate()
(outdir / "thriftgen").rmtree()
- (outdir / "gen-py").move(outdir / "thriftgen")
+ (outdir / "gen-py").shutil.move(outdir / "thriftgen")
# create light ttypes
from pyload.remote.socketbackend.create_ttypes import main
@@ -246,9 +247,9 @@ def generate_locale():
makepot("django", path("pyload/web"), EXCLUDE, "./%s\n" % trans.relpath(), [".py", ".html"], ["--language=Python"])
- trans.remove()
+ trans.reshutil.move()
- path("includes.txt").remove()
+ path("includes.txt").reshutil.move()
print "Locale generated"
@@ -263,11 +264,11 @@ def upload_translations(options):
""" Uploads the locale files to translation server """
tmp = path(mkdtemp())
- shutil.copy('locale/crowdin.yaml', tmp)
+ shutil.shutil.copy('locale/crowdin.yaml', tmp)
os.mkdir(tmp / 'pyLoad')
- for f in glob('locale/*.pot'):
+ for f in glob.glob('locale/*.pot'):
if os.path.isfile(f):
- shutil.copy(f, tmp / 'pyLoad')
+ shutil.shutil.copy(f, tmp / 'pyLoad')
config = tmp / 'crowdin.yaml'
with open(config, 'rb') as f:
@@ -293,11 +294,11 @@ def download_translations(options):
""" Downloads the translated files from translation server """
tmp = path(mkdtemp())
- shutil.copy('locale/crowdin.yaml', tmp)
+ shutil.shutil.copy('locale/crowdin.yaml', tmp)
os.mkdir(tmp / 'pyLoad')
- for f in glob('locale/*.pot'):
+ for f in glob.glob('locale/*.pot'):
if os.path.isfile(f):
- shutil.copy(f, tmp / 'pyLoad')
+ shutil.shutil.copy(f, tmp / 'pyLoad')
config = tmp / 'crowdin.yaml'
with open(config, 'rb') as f:
@@ -329,7 +330,7 @@ def compile_translations():
if not language.isdir():
continue
- for f in glob(language / 'LC_MESSAGES' / '*.po'):
+ for f in glob.glob(language / 'LC_MESSAGES' / '*.po'):
print "Compiling %s" % f
call(['msgfmt', '-o', f.replace('.po', '.mo'), f])
@@ -408,7 +409,7 @@ def makepot(domain, p, excludes=[], includes="", endings=[".py"], xxargs=[]):
with open("%s.po" % domain, "rb") as f:
content = f.read()
- path("%s.po" % domain).remove()
+ path("%s.po" % domain).reshutil.move()
content = content.replace("charset=CHARSET", "charset=UTF-8")
with open("locale/%s.pot" % domain, "wb") as f:
diff --git a/pyload/Core.py b/pyload/Core.py
index ad4412a87..0de19abbf 100755
--- a/pyload/Core.py
+++ b/pyload/Core.py
@@ -4,43 +4,39 @@
from __future__ import with_statement
-import pyload
-import __builtin__
-
-from getopt import getopt, GetoptError
-import pyload.utils.pylgettext as gettext
-from imp import find_module
import logging
import logging.handlers
import os
-from os import _exit, execl, getcwd, makedirs, remove, sep, walk, chdir, close
-from os.path import exists, join
import signal
import subprocess
import sys
+import traceback
+
+import __builtin__
+import pyload
+import pyload.utils.pylgettext as gettext
+
+from codecs import getwriter
+from getopt import getopt, GetoptError
+from imp import find_module
+from os import _exit, execl, getcwd, makedirs, remove, sep, walk, chdir, close
+from os.path import exists, join
from sys import argv, executable, exit
from time import time, sleep
-from traceback import print_exc
+from pyload import remote
+from pyload.database import DatabaseBackend, FileHandler
+from pyload.config.Parser import ConfigParser
from pyload.manager.Account import AccountManager
from pyload.manager.Captcha import CaptchaManager
-from pyload.config.Parser import ConfigParser
-from pyload.manager.Plugin import PluginManager
from pyload.manager.Event import PullManager
-from pyload.network.RequestFactory import RequestFactory
-from pyload.manager.thread.Server import WebServer
+from pyload.manager.Plugin import PluginManager
+from pyload.manager.Remote import RemoteManager
from pyload.manager.event.Scheduler import Scheduler
+from pyload.manager.thread.Server import WebServer
from pyload.network.JsEngine import JsEngine
-from pyload import remote
-from pyload.manager.Remote import RemoteManager
-from pyload.database import DatabaseBackend, FileHandler
-
-from pyload.utils import freeSpace, formatSize, get_console_encoding
-
-from codecs import getwriter
-
-enc = get_console_encoding(sys.stdout.encoding)
-sys.stdout = getwriter(enc)(sys.stdout, errors="replace")
+from pyload.network.RequestFactory import RequestFactory
+from pyload.utils import freeSpace, formatSize
# TODO List
@@ -178,7 +174,7 @@ class Core(object):
def deletePidFile(self):
if self.checkPidFile():
self.log.debug("Deleting old pidfile %s" % self.pidfile)
- os.remove(self.pidfile)
+ os.reshutil.move(self.pidfile)
def checkPidFile(self):
@@ -245,7 +241,7 @@ class Core(object):
continue
print join(path, f)
- remove(join(path, f))
+ reshutil.move(join(path, f))
def start(self, rpc=True, web=True):
@@ -268,10 +264,10 @@ class Core(object):
print "\nSetup interrupted"
except Exception:
res = False
- print_exc()
+ traceback.print_exc()
print "Setup failed"
if not res:
- remove("pyload.conf")
+ reshutil.move("pyload.conf")
exit()
@@ -615,7 +611,7 @@ class Core(object):
except Exception:
if self.debug:
- print_exc()
+ traceback.print_exc()
self.log.info(_("error while shutting down"))
finally:
diff --git a/pyload/cli/Cli.py b/pyload/cli/Cli.py
index fc5236ff9..812212d31 100644
--- a/pyload/cli/Cli.py
+++ b/pyload/cli/Cli.py
@@ -3,39 +3,29 @@
from __future__ import with_statement
-from getopt import GetoptError, getopt
+import os
+import sys
+import threading
+import traceback
import pyload.utils.pylgettext as gettext
-import os
+
+from codecs import getwriter
+from getopt import GetoptError, getopt
from os import _exit
from os.path import join, exists, basename
-import sys
from sys import exit
-from threading import Thread, Lock
from time import sleep
-from traceback import print_exc
-
-from pyload.config.Parser import ConfigParser
-
-from codecs import getwriter
-import module.common.pylgettext as gettext
-
-if os.name == "nt":
- enc = "cp850"
-else:
- enc = "utf8"
-
-sys.stdout = getwriter(enc)(sys.stdout, errors="replace")
-
-from pyload.cli.printer import *
-from pyload.cli import AddPackage, ManageFiles
+from Getch import Getch
+from rename_process import renameProcess
from pyload.api import Destination
-from pyload.utils import formatSize, decode
+from pyload.cli import AddPackage, ManageFiles
+from pyload.config.Parser import ConfigParser
from pyload.remote.thriftbackend.ThriftClient import ThriftClient, NoConnection, NoSSL, WrongLogin, ConnectionClosed
-from Getch import Getch
-from rename_process import renameProcess
+from pyload.utils import formatSize, decode
+from pyload.utils.printer import *
class Cli(object):
@@ -52,7 +42,7 @@ class Cli(object):
self.lastLowestLine = 0
self.menuline = 0
- self.lock = Lock()
+ self.lock = threading.Lock()
# processor funcions, these will be changed dynamically depending on control flow
self.headerHandler = self #: the download status
@@ -389,7 +379,7 @@ class RefreshThread(Thread):
except Exception, e:
println(2, red(str(e)))
self.cli.reset()
- print_exc()
+ traceback.print_exc()
def print_help(config):
diff --git a/pyload/config/Parser.py b/pyload/config/Parser.py
index 45fb1c8d0..d74238007 100644
--- a/pyload/config/Parser.py
+++ b/pyload/config/Parser.py
@@ -2,11 +2,12 @@
from __future__ import with_statement
-from time import sleep
+import shutil
+import traceback
+
from os.path import exists, join
-from shutil import copy
+from time import sleep
-from traceback import print_exc
from pyload.utils import chmod, encode, decode
@@ -49,7 +50,7 @@ class ConfigParser(object):
"""determines if config need to be copied"""
try:
if not exists("pyload.conf"):
- copy(join(pypath, "pyload", "config", "default.conf"), "pyload.conf")
+ shutil.copy(join(pypath, "pyload", "config", "default.conf"), "pyload.conf")
if not exists("plugin.conf"):
with open("plugin.conf", "wb") as f:
@@ -60,7 +61,7 @@ class ConfigParser(object):
v = v[v.find(":") + 1:].strip()
if not v or int(v) < CONF_VERSION:
- copy(join(pypath, "pyload", "config", "default.conf"), "pyload.conf")
+ shutil.copy(join(pypath, "pyload", "config", "default.conf"), "pyload.conf")
print "Old version of config was replaced"
with open("plugin.conf", "rb") as f:
@@ -95,7 +96,7 @@ class ConfigParser(object):
self.updateValues(homeconf, self.config)
except Exception:
print "Config Warning"
- print_exc()
+ traceback.print_exc()
def parseConfig(self, config):
@@ -177,7 +178,7 @@ class ConfigParser(object):
except Exception, e:
print "Config Warning"
- print_exc()
+ traceback.print_exc()
return conf
diff --git a/pyload/database/Backend.py b/pyload/database/Backend.py
index 1fa7a654c..9acca287c 100644
--- a/pyload/database/Backend.py
+++ b/pyload/database/Backend.py
@@ -3,19 +3,21 @@
from __future__ import with_statement
-from threading import Event, Thread
+try:
+ from pysqlite2 import dbapi2 as sqlite3
+except Exception:
+ import sqlite3
+
+import shutil
+import threading
+import traceback
+
+from Queue import Queue
from os import remove
from os.path import exists
-from shutil import move
-from Queue import Queue
-from traceback import print_exc
from pyload.utils import chmod
-try:
- from pysqlite2 import dbapi2 as sqlite3
-except Exception:
- import sqlite3
DB_VERSION = 4
@@ -67,7 +69,7 @@ class style(object):
class DatabaseJob(object):
def __init__(self, f, *args, **kwargs):
- self.done = Event()
+ self.done = threading.Event()
self.f = f
self.args = args
@@ -98,7 +100,7 @@ class DatabaseJob(object):
try:
self.result = self.f(*self.args, **self.kwargs)
except Exception, e:
- print_exc()
+ traceback.print_exc()
try:
print "Database Error @", self.f.__name__, self.args[1:], self.kwargs, e
except Exception:
@@ -124,7 +126,7 @@ class DatabaseBackend(Thread):
self.jobs = Queue()
- self.setuplock = Event()
+ self.setuplock = threading.Event()
style.setDB(self)
@@ -184,8 +186,8 @@ class DatabaseBackend(Thread):
self.manager.core.log.warning(_("Filedatabase was deleted due to incompatible version."))
except Exception:
print "Filedatabase was deleted due to incompatible version."
- remove("files.version")
- move("files.db", "files.backup.db")
+ reshutil.move("files.version")
+ shutil.move("files.db", "files.backup.db")
with open("files.version", "wb") as f:
f.write(str(DB_VERSION))
@@ -277,7 +279,7 @@ class DatabaseBackend(Thread):
conn.close()
self.c.executemany("INSERT INTO users(name, password, email) VALUES (?, ?, ?)", users)
- move("pyload.db", "pyload.old.db")
+ shutil.move("pyload.db", "pyload.old.db")
def createCursor(self):
@@ -320,7 +322,7 @@ class DatabaseBackend(Thread):
@classmethod
def unregisterSub(cls, klass):
- cls.subs.remove(klass)
+ cls.subs.reshutil.move(klass)
def __getattr__(self, attr):
diff --git a/pyload/database/File.py b/pyload/database/File.py
index 3e930ebcc..db4b13a52 100644
--- a/pyload/database/File.py
+++ b/pyload/database/File.py
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
# @author: RaNaN, mkaay
-from threading import RLock
+import threading
from pyload.utils import formatSize, lock
from pyload.manager.Event import InsertEvent, ReloadAllEvent, RemoveEvent, UpdateEvent
@@ -34,7 +34,7 @@ class FileHandler(object):
self.jobCache = {}
- self.lock = RLock() #@TODO: should be a Lock w/o R
+ self.lock = threading.RLock() #@TODO: should be a Lock w/o R
# self.lock._Verbose__verbose = True
self.filecount = -1 #: if an invalid value is set get current value from db
diff --git a/pyload/datatype/File.py b/pyload/datatype/File.py
index 05d515fd0..f46529d87 100644
--- a/pyload/datatype/File.py
+++ b/pyload/datatype/File.py
@@ -1,12 +1,13 @@
# -*- coding: utf-8 -*-
# @author: RaNaN, mkaay
-from pyload.manager.Event import UpdateEvent
-from pyload.utils import formatSize, lock
+import threading
from time import sleep, time
-from threading import RLock
+from pyload.manager.Event import UpdateEvent
+from pyload.utils import formatSize, lock
+
statusMap = {
"finished" : 0,
@@ -55,7 +56,7 @@ class PyFile(object):
self.order = order
# database information ends here
- self.lock = RLock()
+ self.lock = threading.RLock()
self.plugin = None
# self.download = None
diff --git a/pyload/manager/Account.py b/pyload/manager/Account.py
index ac9944134..ad770a1a8 100644
--- a/pyload/manager/Account.py
+++ b/pyload/manager/Account.py
@@ -2,14 +2,15 @@
from __future__ import with_statement
-from os.path import exists
-from shutil import copy
+import shutil
+import threading
-from threading import Lock
+from os.path import exists
from pyload.manager.Event import AccountUpdateEvent
from pyload.utils import chmod, lock
+
ACC_VERSION = 1
@@ -20,7 +21,7 @@ class AccountManager(object):
"""Constructor"""
self.core = core
- self.lock = Lock()
+ self.lock = threading.Lock()
self.initPlugins()
self.saveAccounts() #: save to add categories to conf
@@ -73,7 +74,7 @@ class AccountManager(object):
version = content[0].split(":")[1].strip() if content else ""
if not version or int(version) < ACC_VERSION:
- copy("accounts.conf", "accounts.backup")
+ shutil.copy("accounts.conf", "accounts.backup")
f.seek(0)
f.write("version: " + str(ACC_VERSION))
diff --git a/pyload/manager/Addon.py b/pyload/manager/Addon.py
index 2a3bc4318..2b3d1c456 100644
--- a/pyload/manager/Addon.py
+++ b/pyload/manager/Addon.py
@@ -4,8 +4,8 @@
import __builtin__
+import threading
import traceback
-from threading import RLock, Thread
from types import MethodType
@@ -59,7 +59,7 @@ class AddonManager(object):
self.addEvent("pluginConfigChanged", self.manageAddon)
- self.lock = RLock()
+ self.lock = threading.RLock()
self.createIndex()
diff --git a/pyload/manager/Captcha.py b/pyload/manager/Captcha.py
index ab9f79b37..748f2e425 100644
--- a/pyload/manager/Captcha.py
+++ b/pyload/manager/Captcha.py
@@ -1,9 +1,10 @@
# -*- coding: utf-8 -*-
# @author: RaNaN, mkaay
+import threading
+import traceback
+
from time import time
-from traceback import print_exc
-from threading import Lock
from pyload.utils import encode
@@ -11,7 +12,7 @@ from pyload.utils import encode
class CaptchaManager(object):
def __init__(self, core):
- self.lock = Lock()
+ self.lock = threading.Lock()
self.core = core
self.tasks = [] #: task store, for outgoing tasks only
self.ids = 0 #: only for internal purpose
@@ -61,7 +62,7 @@ class CaptchaManager(object):
plugin.captchaTask(task)
except Exception:
if self.core.debug:
- print_exc()
+ traceback.print_exc()
if task.handler or cli: #: the captcha was handled
self.tasks.append(task)
diff --git a/pyload/manager/Plugin.py b/pyload/manager/Plugin.py
index c6ba5e81b..0efd238b6 100644
--- a/pyload/manager/Plugin.py
+++ b/pyload/manager/Plugin.py
@@ -4,12 +4,12 @@ from __future__ import with_statement
import re
import sys
+import traceback
from itertools import chain
from os import listdir, makedirs
from os.path import isdir, isfile, join, exists, abspath
from sys import version_info
-from traceback import print_exc
from urllib import unquote
from SafeEval import const_eval as literal_eval
@@ -287,7 +287,7 @@ class PluginManager(object):
self.core.log.error(_("Error importing plugin: [%(type)s] %(name)s (v%(version).2f) | %(errmsg)s")
% {'name': name, 'type': type, 'version': plugins[name]['version'], "errmsg": str(e)})
if self.core.debug:
- print_exc()
+ traceback.print_exc()
else:
plugins[name]['module'] = module # : cache import, maybe unneeded
diff --git a/pyload/manager/Remote.py b/pyload/manager/Remote.py
index c2d254932..3c6dabefa 100644
--- a/pyload/manager/Remote.py
+++ b/pyload/manager/Remote.py
@@ -1,8 +1,7 @@
# -*- coding: utf-8 -*-
# @author: RaNaN
-from threading import Thread
-from traceback import print_exc
+import traceback
class BackendBase(Thread):
@@ -22,7 +21,7 @@ class BackendBase(Thread):
except Exception, e:
self.core.log.error(_("Remote backend error: %s") % e)
if self.core.debug:
- print_exc()
+ traceback.print_exc()
finally:
self.running = False
@@ -77,7 +76,7 @@ class RemoteManager(object):
except Exception, e:
self.core.log.error(_("Failed loading backend %(name)s | %(error)s") % {"name": b, "error": str(e)})
if self.core.debug:
- print_exc()
+ traceback.print_exc()
else:
backend.start()
self.backends.append(backend)
diff --git a/pyload/manager/Thread.py b/pyload/manager/Thread.py
index a2a64c38d..ecfcb3e26 100644
--- a/pyload/manager/Thread.py
+++ b/pyload/manager/Thread.py
@@ -1,20 +1,22 @@
# -*- coding: utf-8 -*-
# @author: RaNaN
-from os.path import exists, join
+import random
import re
-from subprocess import Popen
-from threading import Event, Lock
-from time import sleep, time
-from traceback import print_exc
-from random import choice
+import threading
+import traceback
import pycurl
+from os.path import exists, join
+from random import choice
+from subprocess import Popen
+from time import sleep, time
+
+from pyload.datatype.File import PyFile
from pyload.manager.thread.Decrypter import DecrypterThread
from pyload.manager.thread.Download import DownloadThread
from pyload.manager.thread.Info import InfoThread
-from pyload.datatype.File import PyFile
from pyload.network.RequestFactory import getURL
from pyload.utils import freeSpace, lock
@@ -31,11 +33,11 @@ class ThreadManager(object):
self.pause = True
- self.reconnecting = Event()
+ self.reconnecting = threading.Event()
self.reconnecting.clear()
self.downloaded = 0 #: number of files downloaded since last cleanup
- self.lock = Lock()
+ self.lock = threading.Lock()
# some operations require to fetch url info from hoster, so we caching them so it wont be done twice
# contains a timestamp and will be purged after timeout
@@ -125,7 +127,7 @@ class ThreadManager(object):
self.core.log.error(_("Reconnect Failed: %s") % str(e))
self.reconnecting.clear()
if self.core.debug:
- print_exc()
+ traceback.print_exc()
self.checkThreadCount()
try:
@@ -133,7 +135,7 @@ class ThreadManager(object):
except Exception, e:
self.core.log.warning("Assign job error", e)
if self.core.debug:
- print_exc()
+ traceback.print_exc()
sleep(0.5)
self.assignJob()
@@ -187,7 +189,7 @@ class ThreadManager(object):
self.core.config.set("reconnect", "activated", False)
self.reconnecting.clear()
if self.core.debug:
- print_exc()
+ traceback.print_exc()
return
reconn.wait()
@@ -208,7 +210,7 @@ class ThreadManager(object):
ip = ""
for _i in xrange(10):
try:
- sv = choice(services)
+ sv = random.choice(services)
ip = getURL(sv[0])
ip = re.match(sv[1], ip).group(1)
break
@@ -273,7 +275,7 @@ class ThreadManager(object):
job.initPlugin()
except Exception, e:
self.core.log.critical(str(e))
- print_exc()
+ traceback.print_exc()
job.setStatus("failed")
job.error = str(e)
job.release()
diff --git a/pyload/manager/event/Scheduler.py b/pyload/manager/event/Scheduler.py
index d67d9063a..d7098ae10 100644
--- a/pyload/manager/event/Scheduler.py
+++ b/pyload/manager/event/Scheduler.py
@@ -1,9 +1,10 @@
# -*- coding: utf-8 -*-
# @author: mkaay
-from time import time
+import threading
+
from heapq import heappop, heappush
-from threading import Lock, Thread
+from time import time
class AlreadyCalled(Exception):
@@ -99,7 +100,7 @@ class Job(object):
def start(self):
if self.threaded:
- t = Thread(target=self.run)
+ t = threading.Thread(target=self.run)
t.setDaemon(True)
t.start()
else:
@@ -111,7 +112,7 @@ class PriorityQueue(object):
def __init__(self):
self.queue = []
- self.lock = Lock()
+ self.lock = threading.Lock()
def __iter__(self):
diff --git a/pyload/manager/thread/Addon.py b/pyload/manager/thread/Addon.py
index b176e4e0c..3cda99950 100644
--- a/pyload/manager/thread/Addon.py
+++ b/pyload/manager/thread/Addon.py
@@ -1,19 +1,17 @@
# -*- coding: utf-8 -*-
# @author: RaNaN
+import traceback
+
from Queue import Queue
-from threading import Thread
+from copy import copy
from os import listdir, stat
from os.path import join
-from time import sleep, time, strftime, gmtime
-from traceback import print_exc, format_exc
from pprint import pformat
from sys import exc_info, exc_clear
-from copy import copy
+from time import sleep, time, strftime, gmtime
from types import MethodType
-from pycurl import error
-
from pyload.manager.thread.Plugin import PluginThread
diff --git a/pyload/manager/thread/Decrypter.py b/pyload/manager/thread/Decrypter.py
index 308e94f10..3554feac4 100644
--- a/pyload/manager/thread/Decrypter.py
+++ b/pyload/manager/thread/Decrypter.py
@@ -1,19 +1,17 @@
# -*- coding: utf-8 -*-
# @author: RaNaN
+import traceback
+
from Queue import Queue
-from threading import Thread
+from copy import copy
from os import listdir, stat
from os.path import join
-from time import sleep, time, strftime, gmtime
-from traceback import print_exc, format_exc
from pprint import pformat
from sys import exc_info, exc_clear
-from copy import copy
+from time import sleep, time, strftime, gmtime
from types import MethodType
-from pycurl import error
-
from pyload.manager.thread.Plugin import PluginThread
from pyload.plugin.Plugin import Abort, Fail, Retry
@@ -67,7 +65,7 @@ class DecrypterThread(PluginThread):
pyfile.error = msg
if self.m.core.debug:
- print_exc()
+ traceback.print_exc()
return
except Abort:
@@ -75,7 +73,7 @@ class DecrypterThread(PluginThread):
pyfile.setStatus("aborted")
if self.m.core.debug:
- print_exc()
+ traceback.print_exc()
return
except Retry:
@@ -90,7 +88,7 @@ class DecrypterThread(PluginThread):
pyfile.error = str(e)
if self.m.core.debug:
- print_exc()
+ traceback.print_exc()
self.writeDebugReport(pyfile)
return
diff --git a/pyload/manager/thread/Download.py b/pyload/manager/thread/Download.py
index 293014a2e..04f73b2ed 100644
--- a/pyload/manager/thread/Download.py
+++ b/pyload/manager/thread/Download.py
@@ -1,19 +1,19 @@
# -*- coding: utf-8 -*-
# @author: RaNaN
+import traceback
+
+import pycurl
+
from Queue import Queue
-from threading import Thread
+from copy import copy
from os import listdir, stat
from os.path import join
-from time import sleep, time, strftime, gmtime
-from traceback import print_exc, format_exc
from pprint import pformat
from sys import exc_info, exc_clear
-from copy import copy
+from time import sleep, time, strftime, gmtime
from types import MethodType
-from pycurl import error
-
from pyload.manager.thread.Plugin import PluginThread
from pyload.plugin.Plugin import Abort, Fail, Reconnect, Retry, SkipDownload
@@ -81,7 +81,7 @@ class DownloadThread(PluginThread):
pyfile.setStatus("aborted")
if self.m.core.debug:
- print_exc()
+ traceback.print_exc()
self.clean(pyfile)
continue
@@ -116,13 +116,13 @@ class DownloadThread(PluginThread):
pyfile.error = msg
if self.m.core.debug:
- print_exc()
+ traceback.print_exc()
self.m.core.addonManager.downloadFailed(pyfile)
self.clean(pyfile)
continue
- except error, e:
+ except pycurl.error, e:
if len(e.args) == 2:
code, msg = e.args
else:
@@ -156,7 +156,7 @@ class DownloadThread(PluginThread):
pyfile.setStatus("failed")
self.m.core.log.error("pycurl error %s: %s" % (code, msg))
if self.m.core.debug:
- print_exc()
+ traceback.print_exc()
self.writeDebugReport(pyfile)
self.m.core.addonManager.downloadFailed(pyfile)
@@ -184,7 +184,7 @@ class DownloadThread(PluginThread):
pyfile.error = str(e)
if self.m.core.debug:
- print_exc()
+ traceback.print_exc()
self.writeDebugReport(pyfile)
self.m.core.addonManager.downloadFailed(pyfile)
diff --git a/pyload/manager/thread/Info.py b/pyload/manager/thread/Info.py
index 9d8a3ef5b..856c8facf 100644
--- a/pyload/manager/thread/Info.py
+++ b/pyload/manager/thread/Info.py
@@ -1,22 +1,20 @@
# -*- coding: utf-8 -*-
# @author: RaNaN
+import traceback
+
from Queue import Queue
-from threading import Thread
+from copy import copy
from os import listdir, stat
from os.path import join
-from time import sleep, time, strftime, gmtime
-from traceback import print_exc, format_exc
from pprint import pformat
from sys import exc_info, exc_clear
-from copy import copy
+from time import sleep, time, strftime, gmtime
from types import MethodType
-from pycurl import error
-
+from pyload.api import OnlineStatus
from pyload.datatype.File import PyFile
from pyload.manager.thread.Plugin import PluginThread
-from pyload.api import OnlineStatus
class InfoThread(PluginThread):
@@ -90,7 +88,7 @@ class InfoThread(PluginThread):
try:
data = self.decryptContainer(name, url)
except Exception:
- print_exc()
+ traceback.print_exc()
self.m.log.error("Could not decrypt container.")
data = []
@@ -182,7 +180,7 @@ class InfoThread(PluginThread):
except Exception, e:
self.m.log.warning(_("Info Fetching for %(name)s failed | %(err)s") % {"name": pluginname, "err": str(e)})
if self.m.core.debug:
- print_exc()
+ traceback.print_exc()
# generate default results
if err:
diff --git a/pyload/manager/thread/Plugin.py b/pyload/manager/thread/Plugin.py
index d8319a2ce..2621bc861 100644
--- a/pyload/manager/thread/Plugin.py
+++ b/pyload/manager/thread/Plugin.py
@@ -3,24 +3,22 @@
from __future__ import with_statement
+import traceback
+
from Queue import Queue
-from threading import Thread
+from copy import copy
from os import listdir, stat
from os.path import join
-from time import sleep, time, strftime, gmtime
-from traceback import print_exc, format_exc
from pprint import pformat
from sys import exc_info, exc_clear
-from copy import copy
+from time import sleep, time, strftime, gmtime
from types import MethodType
-from pycurl import error
-
+from pyload.api import OnlineStatus
from pyload.datatype.File import PyFile
from pyload.plugin.Plugin import Abort, Fail, Reconnect, Retry, SkipDownload
from pyload.utils.packagetools import parseNames
from pyload.utils import fs_join
-from pyload.api import OnlineStatus
class PluginThread(Thread):
@@ -74,7 +72,7 @@ class PluginThread(Thread):
def getDebugDump(self, pyfile):
dump = "pyLoad %s Debug Report of %s %s \n\nTRACEBACK:\n %s \n\nFRAMESTACK:\n" % (
- self.m.core.api.getServerVersion(), pyfile.pluginname, pyfile.plugin.__version, format_exc())
+ self.m.core.api.getServerVersion(), pyfile.pluginname, pyfile.plugin.__version, traceback.format_exc())
tb = exc_info()[2]
stack = []
diff --git a/pyload/network/Bucket.py b/pyload/network/Bucket.py
index 2f957fcad..b7f33f993 100644
--- a/pyload/network/Bucket.py
+++ b/pyload/network/Bucket.py
@@ -1,8 +1,10 @@
# -*- coding: utf-8 -*-
# @author: RaNaN
+import threading
+
from time import time
-from threading import Lock
+
MIN_RATE = 10240 #: 10kb minimum rate
@@ -13,7 +15,7 @@ class Bucket(object):
self.rate = 0 #: bytes per second, maximum targeted throughput
self.tokens = 0
self.timestamp = time()
- self.lock = Lock()
+ self.lock = threading.Lock()
def __nonzero__(self):
diff --git a/pyload/network/HTTPDownload.py b/pyload/network/HTTPDownload.py
index 1e74d4476..2276af609 100644
--- a/pyload/network/HTTPDownload.py
+++ b/pyload/network/HTTPDownload.py
@@ -3,12 +3,13 @@
from __future__ import with_statement
+import shutil
+
import pycurl
from os import remove, fsync
from os.path import dirname
from time import sleep, time
-from shutil import move
from logging import getLogger
from pyload.network.HTTPChunk import ChunkInfo, HTTPChunk
@@ -94,16 +95,16 @@ class HTTPDownload(object):
break
fo.write(data)
if fo.tell() < self.info.getChunkRange(i)[1]:
- remove(init)
- self.info.remove() #: there are probably invalid chunks
+ reshutil.move(init)
+ self.info.reshutil.move() #: there are probably invalid chunks
raise Exception("Downloaded content was smaller than expected. Try to reduce download connections.")
- remove(fname) #: remove chunk
+ reshutil.move(fname) #: remove chunk
if self.nameDisposition and self.disposition:
self.filename = fs_join(dirname(self.filename), self.nameDisposition)
- move(init, fs_encode(self.filename))
- self.info.remove() #: remove info file
+ shutil.move(init, fs_encode(self.filename))
+ self.info.reshutil.move() #: remove info file
def download(self, chunks=1, resume=False):
@@ -238,8 +239,8 @@ class HTTPDownload(object):
to_clean = filter(lambda x: x is not init, self.chunks)
for chunk in to_clean:
self.closeChunk(chunk)
- self.chunks.remove(chunk)
- remove(fs_encode(self.info.getChunkName(chunk.id)))
+ self.chunks.reshutil.move(chunk)
+ reshutil.move(fs_encode(self.info.getChunkName(chunk.id)))
# let first chunk load the rest and update the info file
init.resetRange()
diff --git a/pyload/network/RequestFactory.py b/pyload/network/RequestFactory.py
index 5e2c15f4b..d10c35cf0 100644
--- a/pyload/network/RequestFactory.py
+++ b/pyload/network/RequestFactory.py
@@ -1,19 +1,19 @@
# -*- coding: utf-8 -*-
# @author: RaNaN, mkaay
-from threading import Lock
+import threading
from pyload.network.Browser import Browser
from pyload.network.Bucket import Bucket
-from pyload.network.HTTPRequest import HTTPRequest
from pyload.network.CookieJar import CookieJar
+from pyload.network.HTTPRequest import HTTPRequest
from pyload.network.XDCCRequest import XDCCRequest
class RequestFactory(object):
def __init__(self, core):
- self.lock = Lock()
+ self.lock = threading.Lock()
self.core = core
self.bucket = Bucket()
self.updateBucket()
diff --git a/pyload/plugin/Account.py b/pyload/plugin/Account.py
index bb8f7d59a..e4bfd76e8 100644
--- a/pyload/plugin/Account.py
+++ b/pyload/plugin/Account.py
@@ -1,9 +1,9 @@
# -*- coding: utf-8 -*-
-from random import choice
-from time import time
-from traceback import print_exc
-from threading import RLock
+import random
+import threading
+import time
+import traceback
from pyload.plugin.Plugin import Base
from pyload.utils import compare_time, parseFileSize, lock
@@ -40,7 +40,7 @@ class Account(Base):
self.manager = manager
self.accounts = {}
self.infos = {} #: cache for account information
- self.lock = RLock()
+ self.lock = threading.RLock()
self.timestamps = {}
self.init()
@@ -65,7 +65,7 @@ class Account(Base):
@lock
def _login(self, user, data):
# set timestamp for login
- self.timestamps[user] = time()
+ self.timestamps[user] = time.time()
req = self.getAccountRequest(user)
try:
@@ -81,7 +81,7 @@ class Account(Base):
"msg": e})
success = data['valid'] = False
if self.core.debug:
- print_exc()
+ traceback.print_exc()
else:
success = True
finally:
@@ -157,16 +157,16 @@ class Account(Base):
raise Exception("Wrong return format")
except Exception, e:
infos = {"error": str(e)}
- print_exc()
+ traceback.print_exc()
if req:
req.close()
self.logDebug("Account Info: %s" % infos)
- infos['timestamp'] = time()
+ infos['timestamp'] = time.time()
self.infos[name] = infos
- elif "timestamp" in self.infos[name] and self.infos[name]['timestamp'] + self.info_threshold * 60 < time():
+ elif "timestamp" in self.infos[name] and self.infos[name]['timestamp'] + self.info_threshold * 60 < time.time():
self.logDebug("Reached timeout for account data")
self.scheduleRefresh(name)
@@ -239,14 +239,14 @@ class Account(Base):
try:
time_data = data['options']['time'][0]
start, end = time_data.split("-")
- if not compare_time(start.split(":"), end.split(":")):
+ if not compare_time.time(start.split(":"), end.split(":")):
continue
except Exception:
self.logWarning(_("Your Time %s has wrong format, use: 1:22-3:44") % time_data)
if user in self.infos:
if "validuntil" in self.infos[user]:
- if self.infos[user]['validuntil'] > 0 and time() > self.infos[user]['validuntil']:
+ if self.infos[user]['validuntil'] > 0 and time.time() > self.infos[user]['validuntil']:
continue
if "trafficleft" in self.infos[user]:
if self.infos[user]['trafficleft'] == 0:
@@ -256,7 +256,8 @@ class Account(Base):
if not usable:
return None, None
- return choice(usable)
+
+ return random.choice(usable)
def canUse(self):
@@ -285,7 +286,7 @@ class Account(Base):
if user in self.infos:
self.logWarning(_("Account %s is expired, checking again in 1h") % user)
- self.infos[user].update({"validuntil": time() - 1})
+ self.infos[user].update({"validuntil": time.time() - 1})
self.scheduleRefresh(user, 60 * 60)
@@ -299,7 +300,7 @@ class Account(Base):
def checkLogin(self, user):
""" checks if user is still logged in """
if user in self.timestamps:
- if self.login_timeout > 0 and self.timestamps[user] + self.login_timeout * 60 < time():
+ if self.login_timeout > 0 and self.timestamps[user] + self.login_timeout * 60 < time.time():
self.logDebug("Reached login timeout for %s" % user)
return self.relogin(user)
else:
diff --git a/pyload/plugin/Addon.py b/pyload/plugin/Addon.py
index 66f2c6379..cf3397002 100644
--- a/pyload/plugin/Addon.py
+++ b/pyload/plugin/Addon.py
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
-from traceback import print_exc
+import traceback
from pyload.plugin.Plugin import Base
from pyload.utils import has_method
@@ -94,7 +94,7 @@ class Addon(Base):
except Exception, e:
self.logError(_("Error executing addon: %s") % e)
if self.core.debug:
- print_exc()
+ traceback.print_exc()
self.cb = self.core.scheduler.addJob(self.interval, self._periodical, [threaded], threaded=threaded)
diff --git a/pyload/plugin/Plugin.py b/pyload/plugin/Plugin.py
index a14bb1e9c..26590c9da 100644
--- a/pyload/plugin/Plugin.py
+++ b/pyload/plugin/Plugin.py
@@ -2,14 +2,16 @@
from __future__ import with_statement
-from time import time, sleep
-from random import randint
+import traceback
import os
+import random
import re
+import time
import urllib
import urlparse
+from itertools import islice
from os import remove, makedirs, chmod, stat
from os.path import exists, join
@@ -18,9 +20,6 @@ if os.name != "nt":
from pwd import getpwnam
from grp import getgrnam
-from itertools import islice
-from traceback import print_exc
-
from pyload.utils import fs_decode, fs_encode, safe_filename, fs_join, encode
@@ -198,7 +197,7 @@ class Plugin(Base):
self.chunkLimit = 1
self.resumeDownload = False
- #: time() + wait in seconds
+ #: time.time() + wait in seconds
self.waitUntil = 0
self.waiting = False
@@ -326,7 +325,7 @@ class Plugin(Base):
:param reconnect: True if a reconnect would avoid wait time
"""
wait_time = int(seconds) + 1
- wait_until = time() + wait_time
+ wait_until = time.time() + wait_time
self.logDebug("Set waitUntil to: %f (previous: %f)" % (wait_until, self.pyfile.waitUntil),
"Wait: %d seconds" % wait_time)
@@ -353,19 +352,19 @@ class Plugin(Base):
status = pyfile.status
pyfile.setStatus("waiting")
- self.logInfo(_("Wait: %d seconds") % (pyfile.waitUntil - time()),
+ self.logInfo(_("Wait: %d seconds") % (pyfile.waitUntil - time.time()),
_("Reconnect: %s") % self.wantReconnect)
if self.account:
self.logDebug("Ignore reconnection due account logged")
- while pyfile.waitUntil > time():
+ while pyfile.waitUntil > time.time():
if pyfile.abort:
self.abort()
- sleep(1)
+ time.sleep(1)
else:
- while pyfile.waitUntil > time():
+ while pyfile.waitUntil > time.time():
self.thread.m.reconnecting.wait(2)
if pyfile.abort:
@@ -376,7 +375,7 @@ class Plugin(Base):
self.wantReconnect = False
raise Reconnect
- sleep(1)
+ time.sleep(1)
self.waiting = False
@@ -467,7 +466,7 @@ class Plugin(Base):
img = self.load(url, get=get, post=post, cookies=cookies)
- id = ("%.2f" % time())[-6:].replace(".", "")
+ id = ("%.2f" % time.time())[-6:].replace(".", "")
with open(join("tmp", "tmpCaptcha_%s_%s.%s" % (self.getClassName(), id, imgtype)), "wb") as tmpCaptcha:
tmpCaptcha.write(img)
@@ -480,7 +479,7 @@ class Plugin(Base):
Ocr = None
if Ocr and not forceUser:
- sleep(randint(3000, 5000) / 1000.0)
+ time.sleep(random.randint(3000, 5000) / 1000.0)
if self.pyfile.abort:
self.abort()
@@ -496,7 +495,7 @@ class Plugin(Base):
if self.pyfile.abort:
captchaManager.removeTask(task)
self.abort()
- sleep(1)
+ time.sleep(1)
captchaManager.removeTask(task)
diff --git a/pyload/plugin/account/TusfilesNet.py b/pyload/plugin/account/TusfilesNet.py
index f651fa0e1..df22a36e6 100644
--- a/pyload/plugin/account/TusfilesNet.py
+++ b/pyload/plugin/account/TusfilesNet.py
@@ -1,7 +1,5 @@
# -*- coding: utf-8 -*-
-import time
-
from pyload.plugin.internal.XFSAccount import XFSAccount
diff --git a/pyload/plugin/addon/ClickNLoad.py b/pyload/plugin/addon/ClickNLoad.py
index 4e1be807d..9e62072ba 100644
--- a/pyload/plugin/addon/ClickNLoad.py
+++ b/pyload/plugin/addon/ClickNLoad.py
@@ -1,10 +1,9 @@
# -*- coding: utf-8 -*-
import socket
+import threading
import time
-from threading import Lock
-
from pyload.plugin.Addon import Addon, threaded
@@ -55,7 +54,7 @@ class ClickNLoad(Addon):
self._server(ip, webport, cnlport)
- lock = Lock()
+ lock = threading.Lock()
lock.acquire()
lock.acquire()
diff --git a/pyload/plugin/addon/HotFolder.py b/pyload/plugin/addon/HotFolder.py
index 14d0a7ce3..f7f543c3a 100644
--- a/pyload/plugin/addon/HotFolder.py
+++ b/pyload/plugin/addon/HotFolder.py
@@ -3,10 +3,9 @@
from __future__ import with_statement
import os
+import shutil
import time
-from shutil import move
-
from pyload.plugin.Addon import Addon
from pyload.utils import fs_encode, fs_join
@@ -65,7 +64,7 @@ class HotFolder(Addon):
continue
newpath = os.path.join(folder, "finished", f if self.getConfig('keep') else "tmp_" + f)
- move(path, newpath)
+ shutil.move(path, newpath)
self.logInfo(_("Added %s from HotFolder") % f)
self.core.api.addPackage(f, [newpath], 1)
diff --git a/pyload/plugin/addon/IRCInterface.py b/pyload/plugin/addon/IRCInterface.py
index 051d30aa9..3cf21b409 100644
--- a/pyload/plugin/addon/IRCInterface.py
+++ b/pyload/plugin/addon/IRCInterface.py
@@ -1,14 +1,14 @@
# -*- coding: utf-8 -*-
-import pycurl
import re
import socket
import ssl
import time
import traceback
+import pycurl
+
from select import select
-from threading import Thread
from pyload.api import PackageDoesNotExists, FileDoesNotExists
from pyload.network.RequestFactory import getURL
diff --git a/pyload/plugin/extractor/UnRar.py b/pyload/plugin/extractor/UnRar.py
index 83821cdc1..2efba9cd4 100644
--- a/pyload/plugin/extractor/UnRar.py
+++ b/pyload/plugin/extractor/UnRar.py
@@ -2,11 +2,9 @@
import os
import re
+import string
import subprocess
-from glob import glob
-from string import digits
-
from pyload.plugin.Extractor import Extractor, ArchiveError, CRCError, PasswordError
from pyload.utils import fs_decode, fs_encode, fs_join
@@ -136,7 +134,7 @@ class UnRar(Extractor):
self.notifyProgress(int(s))
s = ""
# not reading a digit -> therefore restart
- elif c not in digits:
+ elif c not in string.digits:
s = ""
# add digit to progressstring
else:
diff --git a/pyload/plugin/hoster/FilerNet.py b/pyload/plugin/hoster/FilerNet.py
index be8445fad..106dd2ade 100644
--- a/pyload/plugin/hoster/FilerNet.py
+++ b/pyload/plugin/hoster/FilerNet.py
@@ -4,7 +4,6 @@
# http://filer.net/get/ivgf5ztw53et3ogd
# http://filer.net/get/hgo14gzcng3scbvv
-import pycurl
import re
import urlparse
diff --git a/pyload/plugin/hoster/GigapetaCom.py b/pyload/plugin/hoster/GigapetaCom.py
index a85074e79..6314a17c8 100644
--- a/pyload/plugin/hoster/GigapetaCom.py
+++ b/pyload/plugin/hoster/GigapetaCom.py
@@ -1,6 +1,5 @@
# -*- coding: utf-8 -*-
-import pycurl
import random
import re
diff --git a/pyload/plugin/hoster/QuickshareCz.py b/pyload/plugin/hoster/QuickshareCz.py
index 57b419688..9d66147f6 100644
--- a/pyload/plugin/hoster/QuickshareCz.py
+++ b/pyload/plugin/hoster/QuickshareCz.py
@@ -1,6 +1,5 @@
# -*- coding: utf-8 -*-
-import pycurl
import re
from pyload.plugin.internal.SimpleHoster import SimpleHoster
diff --git a/pyload/plugin/hoster/UnibytesCom.py b/pyload/plugin/hoster/UnibytesCom.py
index d8092ae08..4a2592941 100644
--- a/pyload/plugin/hoster/UnibytesCom.py
+++ b/pyload/plugin/hoster/UnibytesCom.py
@@ -1,6 +1,5 @@
# -*- coding: utf-8 -*-
-import pycurl
import re
import urlparse
from pyload.plugin.internal.SimpleHoster import SimpleHoster
diff --git a/pyload/plugin/internal/XFSHoster.py b/pyload/plugin/internal/XFSHoster.py
index 06d91f4d6..3f7aeeee8 100644
--- a/pyload/plugin/internal/XFSHoster.py
+++ b/pyload/plugin/internal/XFSHoster.py
@@ -1,6 +1,5 @@
# -*- coding: utf-8 -*-
-import pycurl
import random
import re
from pyload.plugin.captcha.ReCaptcha import ReCaptcha
diff --git a/pyload/remote/thriftbackend/ThriftClient.py b/pyload/remote/thriftbackend/ThriftClient.py
index b018fbcc4..ecd4086fa 100644
--- a/pyload/remote/thriftbackend/ThriftClient.py
+++ b/pyload/remote/thriftbackend/ThriftClient.py
@@ -2,17 +2,15 @@
import sys
import thrift
+import traceback
+from Protocol import Protocol
+from Socket import Socket
from socket import error
-from traceback import print_exc
-
from thrift.transport import TTransport
# from thrift.transport.TZlibTransport import TZlibTransport
-from Socket import Socket
-from Protocol import Protocol
# modules should import ttypes from here, when want to avoid importing API
-
from pyload.remote.thriftbackend.thriftgen.pyload import Pyload
from pyload.remote.thriftbackend.thriftgen.pyload.ttypes import *
@@ -42,7 +40,7 @@ class ThriftClient(object):
if e.args and e.args[0] in (111, 10061):
raise NoConnection
else:
- print_exc()
+ traceback.print_exc()
raise NoConnection
try:
@@ -66,7 +64,7 @@ class ThriftClient(object):
elif e.args and e.args[0] == 32:
raise NoConnection
else:
- print_exc()
+ traceback.print_exc()
raise NoConnection
if not correct:
diff --git a/pyload/utils/__init__.py b/pyload/utils/__init__.py
index da84fe51c..5033780c0 100644
--- a/pyload/utils/__init__.py
+++ b/pyload/utils/__init__.py
@@ -256,8 +256,10 @@ def versiontuple(v): #: By kindall (http://stackoverflow.com/a/11887825)
def load_translation(name, locale, default="en"):
""" Load language and return its translation object or None """
- from traceback import print_exc
+
from os.path import join
+ from traceback import print_exc
+
try:
gettext.setpaths([join(os.sep, "usr", "share", "pyload", "locale"), None])
translation = gettext.translation(name, join(pypath, "locale"),
diff --git a/pyload/webui/app/api.py b/pyload/webui/app/api.py
index 70d86c112..7f1b230da 100644
--- a/pyload/webui/app/api.py
+++ b/pyload/webui/app/api.py
@@ -1,17 +1,17 @@
# -*- coding: utf-8 -*-
-from urllib import unquote
+import traceback
+
from itertools import chain
-from traceback import format_exc, print_exc
+from urllib import unquote
+from SafeEval import const_eval as literal_eval
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
-
+from pyload.utils import json
+from pyload.webui import PYLOAD
+from pyload.webui.app.utils import toDict, set_session
# json encoder that accepts TBase objects
@@ -51,8 +51,8 @@ def call_api(func, args=""):
try:
return callApi(func, *args, **kwargs)
except Exception, e:
- print_exc()
- return HTTPError(500, json.dumps({"error": e.message, "traceback": format_exc()}))
+ traceback.print_exc()
+ return HTTPError(500, json.dumps({"error": e.message, "traceback": traceback.format_exc()}))
def callApi(func, *args, **kwargs):
diff --git a/pyload/webui/app/json.py b/pyload/webui/app/json.py
index 3b72cb7ce..400eba624 100644
--- a/pyload/webui/app/json.py
+++ b/pyload/webui/app/json.py
@@ -2,15 +2,16 @@
from __future__ import with_statement
+import shutil
+import traceback
+
from os.path import join
-from traceback import print_exc
-from shutil import copyfileobj
from bottle import route, request, HTTPError
+from pyload.utils import decode, formatSize
from pyload.webui import PYLOAD
from pyload.webui.app.utils import login_required, render_to_response, toDict
-from pyload.utils import decode, formatSize
def format_time(seconds):
@@ -60,7 +61,7 @@ def links():
data = {'links': links, 'ids': ids}
return data
except Exception, e:
- print_exc()
+ traceback.print_exc()
return HTTPError()
@@ -113,7 +114,7 @@ def package(id):
return data
except Exception:
- print_exc()
+ traceback.print_exc()
return HTTPError()
@@ -167,7 +168,7 @@ def add_package():
fpath = join(PYLOAD.getConfigValue("general", "download_folder"), "tmp_" + f.filename)
with open(fpath, 'wb') as destination:
- copyfileobj(f.file, destination)
+ shutil.copyfileobj(f.file, destination)
links.insert(0, fpath)
except Exception:
pass
diff --git a/tests/APIExerciser.py b/tests/APIExerciser.py
index f4b082479..9ff37bdc9 100644
--- a/tests/APIExerciser.py
+++ b/tests/APIExerciser.py
@@ -3,13 +3,13 @@
from __future__ import with_statement
+import gc
+import random
import string
-from threading import Thread
-from random import choice, sample, randint
-from time import time
+import traceback
+
from math import floor
-import gc
-from traceback import print_exc, format_exc
+from time import time
from pyload.remote.thriftbackend.ThriftClient import ThriftClient, Destination
@@ -17,12 +17,12 @@ from pyload.remote.thriftbackend.ThriftClient import ThriftClient, Destination
def createURLs():
""" create some urls, some may fail """
urls = []
- for x in xrange(0, randint(20, 100)):
+ for x in xrange(0, random.randint(20, 100)):
name = "DEBUG_API"
- if randint(0, 5) == 5:
+ if random.randint(0, 5) == 5:
name = "" #: this link will fail
- urls.append(name + "".join(sample(string.ascii_letters, randint(10, 20))))
+ urls.append(name + "".join(random.sample(string.ascii_letters, random.randint(10, 20))))
return urls
@@ -72,8 +72,8 @@ class APIExerciser(Thread):
self.testAPI()
except Exception:
self.core.log.error("Excerciser %d throw an execption" % self.id)
- print_exc()
- out.write(format_exc() + 2 * "\n")
+ traceback.print_exc()
+ out.write(traceback.format_exc() + 2 * "\n")
out.flush()
if not self.count % 100:
@@ -97,7 +97,7 @@ class APIExerciser(Thread):
"deletePackages", "getQueue", "getCollector", "getQueueData", "getCollectorData", "isCaptchaWaiting",
"getCaptchaTask", "stopAllDownloads", "getAllInfo", "getServices", "getAccounts", "getAllUserData"]
- method = choice(m)
+ method = random.choice(m)
# print "Testing:", method
if hasattr(self, method):
@@ -112,10 +112,10 @@ class APIExerciser(Thread):
def addPackage(self):
- name = "".join(sample(string.ascii_letters, 10))
+ name = "".join(random.sample(string.ascii_letters, 10))
urls = createURLs()
- self.api.addPackage(name, urls, choice([Destination.Queue, Destination.Collector]))
+ self.api.addPackage(name, urls, random.choice([Destination.Queue, Destination.Collector]))
def deleteFiles(self):
@@ -123,37 +123,37 @@ class APIExerciser(Thread):
if not info:
return
- pack = choice(info)
+ pack = random.choice(info)
fids = pack.links
if len(fids):
- fids = [f.fid for f in sample(fids, randint(1, max(len(fids) / 2, 1)))]
+ fids = [f.fid for f in random.sample(fids, random.randint(1, max(len(fids) / 2, 1)))]
self.api.deleteFiles(fids)
def deletePackages(self):
- info = choice([self.api.getQueue(), self.api.getCollector()])
+ info = random.choice([self.api.getQueue(), self.api.getCollector()])
if not info:
return
pids = [p.pid for p in info]
if pids:
- pids = sample(pids, randint(1, max(floor(len(pids) / 2.5), 1)))
+ pids = random.sample(pids, random.randint(1, max(floor(len(pids) / 2.5), 1)))
self.api.deletePackages(pids)
def getFileData(self):
info = self.api.getQueueData()
if info:
- p = choice(info)
+ p = random.choice(info)
if p.links:
- self.api.getFileData(choice(p.links).fid)
+ self.api.getFileData(random.choice(p.links).fid)
def getPackageData(self):
info = self.api.getQueue()
if info:
- self.api.getPackageData(choice(info).pid)
+ self.api.getPackageData(random.choice(info).pid)
def getAccounts(self):