summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Walter Purcaro <vuolter@users.noreply.github.com> 2015-05-12 02:17:30 +0200
committerGravatar Walter Purcaro <vuolter@users.noreply.github.com> 2015-05-12 03:22:32 +0200
commit000426c9d890ba2a71625a7454f9c573f10b9bae (patch)
tree8fa66da5061b850778f72f84038d9bb8bfa31f2f
parent'from os' -> 'import os' and so on... (diff)
downloadpyload-000426c9d890ba2a71625a7454f9c573f10b9bae.tar.xz
'from time' -> 'import time' and so on...
-rw-r--r--locale/pavement.py4
-rwxr-xr-xpyload/Core.py12
-rw-r--r--pyload/Thread/Addon.py2
-rw-r--r--pyload/Thread/Decrypter.py2
-rw-r--r--pyload/Thread/Download.py10
-rw-r--r--pyload/Thread/Info.py4
-rw-r--r--pyload/Thread/Plugin.py6
-rw-r--r--pyload/api/__init__.py10
-rw-r--r--pyload/config/Parser.py5
-rw-r--r--pyload/datatype/File.py9
-rw-r--r--pyload/manager/Captcha.py7
-rw-r--r--pyload/manager/Event.py9
-rw-r--r--pyload/manager/Plugin.py4
-rw-r--r--pyload/manager/Scheduler.py6
-rw-r--r--pyload/manager/Thread.py18
-rw-r--r--pyload/network/Bucket.py7
-rw-r--r--pyload/network/CookieJar.py4
-rw-r--r--pyload/network/HTTPChunk.py11
-rw-r--r--pyload/network/HTTPDownload.py6
-rw-r--r--pyload/network/HTTPRequest.py9
-rw-r--r--pyload/network/JsEngine.py11
-rw-r--r--pyload/network/XDCCRequest.py6
-rw-r--r--pyload/remote/ClickNLoadBackend.py5
-rw-r--r--pyload/remote/thriftbackend/Socket.py7
-rw-r--r--pyload/remote/thriftbackend/ThriftTest.py12
-rw-r--r--pyload/remote/thriftbackend/thriftgen/pyload/Pyload-remote5
-rw-r--r--pyload/utils/__init__.py8
-rw-r--r--pyload/utils/packagetools.py5
-rw-r--r--pyload/webui/app/api.py4
-rw-r--r--pyload/webui/app/cnl.py4
-rw-r--r--pyload/webui/app/pyloadweb.py4
-rw-r--r--tests/APIExerciser.py8
-rw-r--r--tests/test_json.py18
33 files changed, 116 insertions, 126 deletions
diff --git a/locale/pavement.py b/locale/pavement.py
index 02aa110b5..2a238a968 100644
--- a/locale/pavement.py
+++ b/locale/pavement.py
@@ -12,9 +12,9 @@ import os
import sys
import shutil
import re
+import urllib
from tempfile import mkdtemp
-from urllib import urlretrieve
from subprocess import call, Popen, PIPE
from zipfile import ZipFile
@@ -127,7 +127,7 @@ def get_source(options):
elif pyload.exists():
pyload.rmtree()
- urlretrieve(options.src, "pyload_src.zip")
+ urllib.urlretrieve(options.src, "pyload_src.zip")
zip = ZipFile("pyload_src.zip")
zip.extractall()
path("pyload_src.zip").remove()
diff --git a/pyload/Core.py b/pyload/Core.py
index 231959b07..1e938f01c 100755
--- a/pyload/Core.py
+++ b/pyload/Core.py
@@ -10,6 +10,7 @@ import os
import signal
import subprocess
import sys
+import time
import traceback
import __builtin__
@@ -20,7 +21,6 @@ from codecs import getwriter
from getopt import getopt, GetoptError
from imp import find_module
from sys import argv, executable, exit
-from time import time, sleep
from pyload import remote
from pyload.Database import DatabaseBackend, FileHandler
@@ -212,11 +212,11 @@ class Core(object):
try:
os.kill(pid, 3) #: SIGUIT
- t = time()
+ t = time.time()
print "waiting for pyLoad to quit"
- whileself.pidfile) and t + 10 > time():
- sleep(0.25)
+ whileself.pidfile) and t + 10 > time.time():
+ time.sleep(0.25)
if not os.path.exists(self.pidfile):
print "pyLoad successfully stopped"
@@ -426,7 +426,7 @@ class Core(object):
locals().clear()
while True:
- sleep(2)
+ time.sleep(2)
if self.do_restart:
self.log.info(_("restarting pyLoad"))
self.restart()
@@ -575,7 +575,7 @@ class Core(object):
def isClientConnected(self):
- return (self.lastClientConnected + 30) > time()
+ return (self.lastClientConnected + 30) > time.time()
def restart(self):
diff --git a/pyload/Thread/Addon.py b/pyload/Thread/Addon.py
index 49d470a8a..0b46345e8 100644
--- a/pyload/Thread/Addon.py
+++ b/pyload/Thread/Addon.py
@@ -2,13 +2,13 @@
# @author: RaNaN
import os
+import time
import traceback
from Queue import Queue
from copy import copy
from pprint import pformat
from sys import exc_info, exc_clear
-from time import sleep, time, strftime, gmtime
from types import MethodType
from pyload.Thread.Plugin import PluginThread
diff --git a/pyload/Thread/Decrypter.py b/pyload/Thread/Decrypter.py
index 62891433e..83403e8fa 100644
--- a/pyload/Thread/Decrypter.py
+++ b/pyload/Thread/Decrypter.py
@@ -2,13 +2,13 @@
# @author: RaNaN
import os
+import time
import traceback
from Queue import Queue
from copy import copy
from pprint import pformat
from sys import exc_info, exc_clear
-from time import sleep, time, strftime, gmtime
from types import MethodType
from pyload.Thread.Plugin import PluginThread
diff --git a/pyload/Thread/Download.py b/pyload/Thread/Download.py
index be9a1c7ef..d7a55ad24 100644
--- a/pyload/Thread/Download.py
+++ b/pyload/Thread/Download.py
@@ -2,6 +2,7 @@
# @author: RaNaN
import os
+import time
import traceback
import pycurl
@@ -10,7 +11,6 @@ from Queue import Queue
from copy import copy
from pprint import pformat
from sys import exc_info, exc_clear
-from time import sleep, time, strftime, gmtime
from types import MethodType
from pyload.Thread.Plugin import PluginThread
@@ -90,7 +90,7 @@ class DownloadThread(PluginThread):
# pyfile.req.clearCookies()
while self.m.reconnecting.isSet():
- sleep(0.5)
+ time.sleep(0.5)
continue
@@ -132,12 +132,12 @@ class DownloadThread(PluginThread):
if code in (7, 18, 28, 52, 56):
self.m.core.log.warning(_("Couldn't connect to host or connection reset, waiting 1 minute and retry."))
- wait = time() + 60
+ wait = time.time() + 60
pyfile.waitUntil = wait
pyfile.setStatus("waiting")
- while time() < wait:
- sleep(1)
+ while time.time() < wait:
+ time.sleep(1)
if pyfile.abort:
break
diff --git a/pyload/Thread/Info.py b/pyload/Thread/Info.py
index fbd60908e..09b562659 100644
--- a/pyload/Thread/Info.py
+++ b/pyload/Thread/Info.py
@@ -2,13 +2,13 @@
# @author: RaNaN
import os
+import time
import traceback
from Queue import Queue
from copy import copy
from pprint import pformat
from sys import exc_info, exc_clear
-from time import sleep, time, strftime, gmtime
from types import MethodType
from pyload.api import OnlineStatus
@@ -116,7 +116,7 @@ class InfoThread(PluginThread):
self.m.infoResults[self.rid]['ALL_INFO_FETCHED'] = {}
- self.m.timestamp = time() + 5 * 60
+ self.m.timestamp = time.time() + 5 * 60
def updateDB(self, plugin, result):
diff --git a/pyload/Thread/Plugin.py b/pyload/Thread/Plugin.py
index 264deb84c..9d61c9a12 100644
--- a/pyload/Thread/Plugin.py
+++ b/pyload/Thread/Plugin.py
@@ -5,13 +5,13 @@ from __future__ import with_statement
import os
import threading
+import time
import traceback
from Queue import Queue
from copy import copy
from pprint import pformat
from sys import exc_info, exc_clear
-from time import sleep, time, strftime, gmtime
from types import MethodType
from pyload.api import OnlineStatus
@@ -36,7 +36,7 @@ class PluginThread(threading.Thread):
:return:
"""
- dump_name = "debug_%s_%s.zip" % (pyfile.pluginname, strftime("%d-%m-%Y_%H-%M-%S"))
+ dump_name = "debug_%s_%s.zip" % (pyfile.pluginname, time.strftime("%d-%m-%Y_%H-%M-%S"))
dump = self.getDebugDump(pyfile)
try:
@@ -51,7 +51,7 @@ class PluginThread(threading.Thread):
except Exception:
pass
- info = zipfile.ZipInfo(fs_join(pyfile.pluginname, "debug_Report.txt"), gmtime())
+ info = zipfile.ZipInfo(fs_join(pyfile.pluginname, "debug_Report.txt"), time.gmtime())
info.external_attr = 0644 << 16L #: change permissions
zip.writestr(info, dump)
diff --git a/pyload/api/__init__.py b/pyload/api/__init__.py
index 9fd0735d2..01586bc4a 100644
--- a/pyload/api/__init__.py
+++ b/pyload/api/__init__.py
@@ -5,10 +5,10 @@ from __future__ import with_statement
import os
import re
+import time
import urlparse
from base64 import standard_b64encode
-from time import time
from pyload.Datatype import PyFile
from pyload.utils.packagetools import parseNames
@@ -804,7 +804,7 @@ class Api(Iface):
:return: bool
"""
- self.core.lastClientConnected = time()
+ self.core.lastClientConnected = time.time()
task = self.core.captchaManager.getTask()
return not task is None
@@ -816,7 +816,7 @@ class Api(Iface):
:param exclusive: unused
:return: `CaptchaTask`
"""
- self.core.lastClientConnected = time()
+ self.core.lastClientConnected = time.time()
task = self.core.captchaManager.getTask()
if task:
task.setWatingForUser(exclusive=exclusive)
@@ -833,7 +833,7 @@ class Api(Iface):
:param tid: task id
:return: string
"""
- self.core.lastClientConnected = time()
+ self.core.lastClientConnected = time.time()
task = self.core.captchaManager.getTaskByID(tid)
return task.getStatus() if task else ""
@@ -845,7 +845,7 @@ class Api(Iface):
:param tid: task id
:param result: captcha result
"""
- self.core.lastClientConnected = time()
+ self.core.lastClientConnected = time.time()
task = self.core.captchaManager.getTaskByID(tid)
if task:
task.setResult(result)
diff --git a/pyload/config/Parser.py b/pyload/config/Parser.py
index 6cd998024..f834e4b4e 100644
--- a/pyload/config/Parser.py
+++ b/pyload/config/Parser.py
@@ -4,10 +4,9 @@ from __future__ import with_statement
import os
import shutil
+import time
import traceback
-from time import sleep
-
from pyload.utils import chmod, encode, decode
@@ -76,7 +75,7 @@ class ConfigParser(object):
except Exception:
if n >= 3:
raise
- sleep(0.3)
+ time.sleep(0.3)
self.checkVersion(n + 1)
diff --git a/pyload/datatype/File.py b/pyload/datatype/File.py
index f46529d87..cb6989d98 100644
--- a/pyload/datatype/File.py
+++ b/pyload/datatype/File.py
@@ -1,10 +1,9 @@
# -*- coding: utf-8 -*-
# @author: RaNaN, mkaay
+import time
import threading
-from time import sleep, time
-
from pyload.manager.Event import UpdateEvent
from pyload.utils import formatSize, lock
@@ -61,7 +60,7 @@ class PyFile(object):
self.plugin = None
# self.download = None
- self.waitUntil = 0 #: time() + time to wait
+ self.waitUntil = 0 #: time.time() + time to wait
# status attributes
self.active = False #: obsolete?
@@ -189,7 +188,7 @@ class PyFile(object):
self.abort = True
if self.plugin and self.plugin.req:
self.plugin.req.abortDownloads()
- sleep(0.1)
+ time.sleep(0.1)
self.abort = False
if self.hasPlugin() and self.plugin.req:
@@ -216,7 +215,7 @@ class PyFile(object):
def formatWait(self):
""" formats and return wait time in humanreadable format """
- seconds = self.waitUntil - time()
+ seconds = self.waitUntil - time.time()
if seconds < 0:
return "00:00:00"
diff --git a/pyload/manager/Captcha.py b/pyload/manager/Captcha.py
index 748f2e425..271e6122b 100644
--- a/pyload/manager/Captcha.py
+++ b/pyload/manager/Captcha.py
@@ -2,10 +2,9 @@
# @author: RaNaN, mkaay
import threading
+import time
import traceback
-from time import time
-
from pyload.utils import encode
@@ -112,7 +111,7 @@ class CaptchaTask(object):
def setWaiting(self, sec):
""" let the captcha wait secs for the solution """
- self.waitUntil = max(time() + sec, self.waitUntil)
+ self.waitUntil = max(time.time() + sec, self.waitUntil)
self.status = "waiting"
@@ -141,7 +140,7 @@ class CaptchaTask(object):
def timedOut(self):
- return time() > self.waitUntil
+ return time.time() > self.waitUntil
def invalid(self):
diff --git a/pyload/manager/Event.py b/pyload/manager/Event.py
index b3d22619f..919835984 100644
--- a/pyload/manager/Event.py
+++ b/pyload/manager/Event.py
@@ -1,7 +1,8 @@
# -*- coding: utf-8 -*-
# @author: mkaay
-from time import time
+import time
+
from pyload.utils import uniqify
@@ -18,7 +19,7 @@ class PullManager(object):
def clean(self):
for n, client in enumerate(self.clients):
- if client.lastActive + 30 < time():
+ if client.lastActive + 30 < time.time():
del self.clients[n]
@@ -27,7 +28,7 @@ class PullManager(object):
validUuid = False
for client in self.clients:
if client.uuid == uuid:
- client.lastActive = time()
+ client.lastActive = time.time()
validUuid = True
while client.newEvents():
events.append(client.popEvent().toList())
@@ -47,7 +48,7 @@ class Client(object):
def __init__(self, uuid):
self.uuid = uuid
- self.lastActive = time()
+ self.lastActive = time.time()
self.events = []
diff --git a/pyload/manager/Plugin.py b/pyload/manager/Plugin.py
index 19898069c..36213eb7a 100644
--- a/pyload/manager/Plugin.py
+++ b/pyload/manager/Plugin.py
@@ -6,10 +6,10 @@ import os
import re
import sys
import traceback
+import urllib
from itertools import chain
from sys import version_info
-from urllib import unquote
from SafeEval import const_eval as literal_eval
@@ -196,7 +196,7 @@ class PluginManager(object):
if type(url) not in (str, unicode, buffer):
continue
- url = unquote(url)
+ url = urllib.unquote(url)
if last and last[2]['re'].match(url):
res.append((url, last[0], last[1]))
diff --git a/pyload/manager/Scheduler.py b/pyload/manager/Scheduler.py
index d7098ae10..630e43022 100644
--- a/pyload/manager/Scheduler.py
+++ b/pyload/manager/Scheduler.py
@@ -2,9 +2,9 @@
# @author: mkaay
import threading
+import time
from heapq import heappop, heappush
-from time import time
class AlreadyCalled(Exception):
@@ -42,7 +42,7 @@ class Scheduler(object):
def addJob(self, t, call, args=[], kwargs={}, threaded=True):
d = Deferred()
- t += time()
+ t += time.time()
j = Job(t, call, args, kwargs, d, threaded)
self.queue.put((t, j))
return d
@@ -72,7 +72,7 @@ class Scheduler(object):
if not j:
break
else:
- if t <= time():
+ if t <= time.time():
j.start()
else:
self.queue.put((t, j))
diff --git a/pyload/manager/Thread.py b/pyload/manager/Thread.py
index abc7b2fef..0acfd4751 100644
--- a/pyload/manager/Thread.py
+++ b/pyload/manager/Thread.py
@@ -5,13 +5,13 @@ import os
import random
import re
import threading
+import time
import traceback
import pycurl
from random import choice
from subprocess import Popen
-from time import sleep, time
from pyload.Datatype import PyFile
from pyload.Thread import DecrypterThread, DownloadThread, InfoThread
@@ -67,7 +67,7 @@ class ThreadManager(object):
start a thread whichs fetches online status and other infos
data = [ .. () .. ]
"""
- self.timestamp = time() + 5 * 60
+ self.timestamp = time.time() + 5 * 60
InfoThread(self, data, pid)
@@ -75,7 +75,7 @@ class ThreadManager(object):
@lock
def createResultThread(self, data, add=False):
""" creates a thread to fetch online status, returns result id """
- self.timestamp = time() + 5 * 60
+ self.timestamp = time.time() + 5 * 60
rid = self.resultIDs
self.resultIDs += 1
@@ -88,7 +88,7 @@ class ThreadManager(object):
@lock
def getInfoResult(self, rid):
"""returns result and clears it"""
- self.timestamp = time() + 5 * 60
+ self.timestamp = time.time() + 5 * 60
if rid in self.infoResults:
data = self.infoResults[rid]
@@ -135,11 +135,11 @@ class ThreadManager(object):
if self.core.debug:
traceback.print_exc()
- sleep(0.5)
+ time.sleep(0.5)
self.assignJob()
# it may be failed non critical so we try it again
- if (self.infoCache or self.infoResults) and self.timestamp < time():
+ if (self.infoCache or self.infoResults) and self.timestamp < time.time():
self.infoCache.clear()
self.infoResults.clear()
self.core.log.debug("Cleared Result cache")
@@ -172,7 +172,7 @@ class ThreadManager(object):
self.core.log.info(_("Starting reconnect"))
while [x.active.plugin.waiting for x in self.threads if x.active].count(True) != 0:
- sleep(0.25)
+ time.sleep(0.25)
ip = self.getIP()
@@ -191,7 +191,7 @@ class ThreadManager(object):
return
reconn.wait()
- sleep(1)
+ time.sleep(1)
ip = self.getIP()
self.core.addonManager.afterReconnecting(ip)
@@ -214,7 +214,7 @@ class ThreadManager(object):
break
except Exception:
ip = ""
- sleep(1)
+ time.sleep(1)
return ip
diff --git a/pyload/network/Bucket.py b/pyload/network/Bucket.py
index b7f33f993..4f152f0d4 100644
--- a/pyload/network/Bucket.py
+++ b/pyload/network/Bucket.py
@@ -2,8 +2,7 @@
# @author: RaNaN
import threading
-
-from time import time
+import time
MIN_RATE = 10240 #: 10kb minimum rate
@@ -14,7 +13,7 @@ class Bucket(object):
def __init__(self):
self.rate = 0 #: bytes per second, maximum targeted throughput
self.tokens = 0
- self.timestamp = time()
+ self.timestamp = time.time()
self.lock = threading.Lock()
@@ -45,7 +44,7 @@ class Bucket(object):
def calc_tokens(self):
if self.tokens < self.rate:
- now = time()
+ now = time.time()
delta = self.rate * (now - self.timestamp)
self.tokens = min(self.rate, self.tokens + delta)
self.timestamp = now
diff --git a/pyload/network/CookieJar.py b/pyload/network/CookieJar.py
index a970a08e5..8c8d4c87b 100644
--- a/pyload/network/CookieJar.py
+++ b/pyload/network/CookieJar.py
@@ -2,9 +2,9 @@
# @author: RaNaN
import Cookie
+import time
from datetime import datetime, timedelta
-from time import time
# monkey patch for 32 bit systems
@@ -30,7 +30,7 @@ class CookieJar(Cookie.SimpleCookie):
# Value of expires should be integer if possible
# otherwise the cookie won't be used
if not exp:
- expires = time() + 3600 * 24 * 180
+ expires = time.time() + 3600 * 24 * 180
else:
try:
expires = int(exp)
diff --git a/pyload/network/HTTPChunk.py b/pyload/network/HTTPChunk.py
index a48c69cba..1ce72a918 100644
--- a/pyload/network/HTTPChunk.py
+++ b/pyload/network/HTTPChunk.py
@@ -3,13 +3,12 @@
import codecs
import os
+import re
+import time
import urllib
import pycurl
-from time import sleep
-from re import search
-
from pyload.network.HTTPRequest import HTTPRequest
from pyload.utils import fs_encode
@@ -213,7 +212,7 @@ class HTTPChunk(HTTPRequest):
if not self.range and self.header.endswith("\r\n\r\n"):
self.parseHeader()
elif not self.range and buf.startswith("150") and "data connection" in buf.lower(): #: ftp file size parsing
- size = search(r"(\d+) bytes", buf)
+ size = re.search(r"(\d+) bytes", buf)
if size:
self.p.size = int(size.group(1))
self.p.chunkSupport = True
@@ -235,7 +234,7 @@ class HTTPChunk(HTTPRequest):
self.fp.write(buf)
if self.p.bucket:
- sleep(self.p.bucket.consumed(size))
+ time.sleep(self.p.bucket.consumed(size))
else:
# Avoid small buffers, increasing sleep time slowly if buffer size gets smaller
# otherwise reduce sleep time percentual (values are based on tests)
@@ -248,7 +247,7 @@ class HTTPChunk(HTTPRequest):
self.lastSize = size
- sleep(self.sleep)
+ time.sleep(self.sleep)
if self.range and self.arrived > self.size:
return 0 #: close if we have enough data
diff --git a/pyload/network/HTTPDownload.py b/pyload/network/HTTPDownload.py
index 78e069f7e..959ffd111 100644
--- a/pyload/network/HTTPDownload.py
+++ b/pyload/network/HTTPDownload.py
@@ -5,10 +5,10 @@ from __future__ import with_statement
import os
import shutil
+import time
import pycurl
-from time import sleep, time
from logging import getLogger
from pyload.network.HTTPChunk import ChunkInfo, HTTPChunk
@@ -188,7 +188,7 @@ class HTTPDownload(object):
if ret != pycurl.E_CALL_MULTI_PERFORM:
break
- t = time()
+ t = time.time()
# reduce these calls
while lastFinishCheck + 0.5 < t:
@@ -275,7 +275,7 @@ class HTTPDownload(object):
if self.abort:
raise Abort
- # sleep(0.003) #: supress busy waiting - limits dl speed to (1 / x) * buffersize
+ # time.sleep(0.003) #: supress busy waiting - limits dl speed to (1 / x) * buffersize
self.m.select(1)
for chunk in self.chunks:
diff --git a/pyload/network/HTTPRequest.py b/pyload/network/HTTPRequest.py
index 74b83cf12..14c5b8cb6 100644
--- a/pyload/network/HTTPRequest.py
+++ b/pyload/network/HTTPRequest.py
@@ -3,10 +3,11 @@
from __future__ import with_statement
+import urllib
+
import pycurl
from codecs import getincrementaldecoder, lookup, BOM_UTF8
-from urllib import quote, urlencode
from httplib import responses
from logging import getLogger
from cStringIO import StringIO
@@ -17,12 +18,12 @@ from pyload.utils import encode
def myquote(url):
- return quote(encode(url), safe="%/:=&?~#+!$,;'@()*[]")
+ return urllib.quote(encode(url), safe="%/:=&?~#+!$,;'@()*[]")
def myurlencode(data):
data = dict(data)
- return urlencode(dict((encode(x), encode(y)) for x, y in data.iteritems()))
+ return urllib.urlencode(dict((encode(x), encode(y)) for x, y in data.iteritems()))
bad_headers = range(400, 404) + range(405, 418) + range(500, 506)
@@ -148,7 +149,7 @@ class HTTPRequest(object):
url = myquote(url)
if get:
- get = urlencode(get)
+ get = urllib.urlencode(get)
url = "%s?%s" % (url, get)
self.c.setopt(pycurl.URL, url)
diff --git a/pyload/network/JsEngine.py b/pyload/network/JsEngine.py
index c542b4dac..8b5e2d760 100644
--- a/pyload/network/JsEngine.py
+++ b/pyload/network/JsEngine.py
@@ -4,8 +4,7 @@
import os
import subprocess
import sys
-
-from urllib import quote
+import urllib
from pyload.utils import encode, decode, uniqify
@@ -185,7 +184,7 @@ class CommonEngine(AbstractEngine):
def eval(self, script):
- script = "print(eval(unescape('%s')))" % quote(script)
+ script = "print(eval(unescape('%s')))" % urllib.quote(script)
args = ["js", "-e", script]
return self._eval(args)
@@ -200,7 +199,7 @@ class NodeEngine(AbstractEngine):
def eval(self, script):
- script = "console.log(eval(unescape('%s')))" % quote(script)
+ script = "console.log(eval(unescape('%s')))" % urllib.quote(script)
args = ["node", "-e", script]
return self._eval(args)
@@ -225,7 +224,7 @@ class RhinoEngine(AbstractEngine):
def eval(self, script):
- script = "print(eval(unescape('%s')))" % quote(script)
+ script = "print(eval(unescape('%s')))" % urllib.quote(script)
args = ["java", "-cp", self.path, "org.mozilla.javascript.tools.shell.Main", "-e", script]
res = decode(self._eval(args))
try:
@@ -245,7 +244,7 @@ class JscEngine(AbstractEngine):
def eval(self, script):
- script = "print(eval(unescape('%s')))" % quote(script)
+ script = "print(eval(unescape('%s')))" % urllib.quote(script)
args = [self.path, "-e", script]
return self._eval(args)
diff --git a/pyload/network/XDCCRequest.py b/pyload/network/XDCCRequest.py
index b9e9958aa..0d8e90db9 100644
--- a/pyload/network/XDCCRequest.py
+++ b/pyload/network/XDCCRequest.py
@@ -4,9 +4,9 @@
import os
import socket
import struct
+import time
from select import select
-from time import time
from pyload.plugin.Plugin import Abort
@@ -48,7 +48,7 @@ class XDCCRequest(object):
def download(self, ip, port, filename, irc, progress=None):
ircbuffer = ""
- lastUpdate = time()
+ lastUpdate = time.time()
cumRecvLen = 0
dccsock = self.createSocket()
@@ -85,7 +85,7 @@ class XDCCRequest(object):
cumRecvLen += dataLen
- now = time()
+ now = time.time()
timespan = now - lastUpdate
if timespan > 1:
self.speed = cumRecvLen / timespan
diff --git a/pyload/remote/ClickNLoadBackend.py b/pyload/remote/ClickNLoadBackend.py
index 2d3e29dbc..f0c988d73 100644
--- a/pyload/remote/ClickNLoadBackend.py
+++ b/pyload/remote/ClickNLoadBackend.py
@@ -2,9 +2,10 @@
# @author: RaNaN
import re
+import urllib
+
from BaseHTTPServer import HTTPServer, BaseHTTPRequestHandler
from cgi import FieldStorage
-from urllib import unquote
from base64 import standard_b64decode
from binascii import unhexlify
@@ -130,7 +131,7 @@ class CNLHandler(BaseHTTPRequestHandler):
crypted = self.get_post("crypted")
jk = self.get_post("jk")
- crypted = standard_b64decode(unquote(crypted.replace(" ", "+")))
+ crypted = standard_b64decode(urllib.unquote(crypted.replace(" ", "+")))
jk = "%s f()" % jk
jk = js.eval(jk)
Key = unhexlify(jk)
diff --git a/pyload/remote/thriftbackend/Socket.py b/pyload/remote/thriftbackend/Socket.py
index 0ca9ed178..6459d8f79 100644
--- a/pyload/remote/thriftbackend/Socket.py
+++ b/pyload/remote/thriftbackend/Socket.py
@@ -3,8 +3,7 @@
import sys
import socket
import errno
-
-from time import sleep
+import time
from thrift.transport.TSocket import TSocket, TServerSocket, TTransportException
@@ -38,7 +37,7 @@ class SecureSocketConnection(object):
try:
return self.__dict__['connection'].send(buff)
except WantReadError:
- sleep(0.1)
+ time.sleep(0.1)
return self.send(buff)
@@ -46,7 +45,7 @@ class SecureSocketConnection(object):
try:
return self.__dict__['connection'].recv(buff)
except WantReadError:
- sleep(0.1)
+ time.sleep(0.1)
return self.recv(buff)
diff --git a/pyload/remote/thriftbackend/ThriftTest.py b/pyload/remote/thriftbackend/ThriftTest.py
index c95e060b8..d8adf476e 100644
--- a/pyload/remote/thriftbackend/ThriftTest.py
+++ b/pyload/remote/thriftbackend/ThriftTest.py
@@ -3,11 +3,7 @@
import os
import platform
import sys
-
-if "64" in platform.machine():
- sys.path.append(os.path.join(pypath, "lib64"))
-sys.path.append(os.path.join(pypath, "lib", "Python", "Lib"))
-
+import time
from pyload.remote.thriftbackend.thriftgen.pyload import Pyload
from pyload.remote.thriftbackend.thriftgen.pyload.ttypes import *
@@ -18,15 +14,13 @@ from thrift.transport import TTransport
from Protocol import Protocol
-from time import time
-
import xmlrpclib
def bench(f, *args, **kwargs):
- s = time()
+ s = time.time()
ret = [f(*args, **kwargs) for _i in xrange(0, 100)]
- e = time()
+ e = time.time()
try:
print "%s: %f s" % (f._Method__name, e-s)
except Exception:
diff --git a/pyload/remote/thriftbackend/thriftgen/pyload/Pyload-remote b/pyload/remote/thriftbackend/thriftgen/pyload/Pyload-remote
index ddc1dd451..beab520e2 100644
--- a/pyload/remote/thriftbackend/thriftgen/pyload/Pyload-remote
+++ b/pyload/remote/thriftbackend/thriftgen/pyload/Pyload-remote
@@ -8,7 +8,8 @@
import sys
import pprint
-from urlparse import urlparse
+import urlparse
+
from thrift.transport import TTransport
from thrift.transport import TSocket
from thrift.transport import THttpClient
@@ -111,7 +112,7 @@ if sys.argv[argi] == '-h':
argi += 2
if sys.argv[argi] == '-u':
- url = urlparse(sys.argv[argi+1])
+ url = urlparse.urlparse(sys.argv[argi+1])
parts = url[1].split(':')
host = parts[0]
if len(parts) > 1:
diff --git a/pyload/utils/__init__.py b/pyload/utils/__init__.py
index ef30a0996..99c470048 100644
--- a/pyload/utils/__init__.py
+++ b/pyload/utils/__init__.py
@@ -8,12 +8,12 @@ import os
import re
import sys
import time
+import urllib
# from gettext import gettext
import pylgettext as gettext
from htmlentitydefs import name2codepoint
from string import maketrans
-from urllib import unquote
# abstraction layer for json operations
try:
@@ -63,7 +63,7 @@ def remove_chars(string, repl):
def safe_filename(name):
""" remove bad chars """
- name = unquote(name).encode('ascii', 'replace') #: Non-ASCII chars usually breaks file saving. Replacing.
+ name = urllib.unquote(name).encode('ascii', 'replace') #: Non-ASCII chars usually breaks file saving. Replacing.
if os.name == 'nt':
return remove_chars(name, u'\00\01\02\03\04\05\06\07\10\11\12\13\14\15\16\17\20\21\22\23\24\25\26\27\30\31\32'
u'\33\34\35\36\37/?%*|"<>')
@@ -256,14 +256,14 @@ 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
+ import traceback
try:
gettext.setpaths([join(os.sep, "usr", "share", "pyload", "locale"), None])
translation = gettext.translation(name, os.path.join(pypath, "locale"),
languages=[locale, default], fallback=True)
except Exception:
- print_exc()
+ traceback.print_exc()
return None
else:
translation.install(True)
diff --git a/pyload/utils/packagetools.py b/pyload/utils/packagetools.py
index 8ed55d0f7..fed46123c 100644
--- a/pyload/utils/packagetools.py
+++ b/pyload/utils/packagetools.py
@@ -1,8 +1,7 @@
# -*- coding: utf-8 -*-
import re
-
-from urlparse import urlparse
+import urlparse
endings = ("jdeatme", "3gp", "7zip", "7z", "abr", "ac3", "aiff", "aifc", "aif", "ai",
@@ -138,7 +137,7 @@ def parseNames(files):
#@NOTE: fallback: package by hoster
if not name:
- name = urlparse(file).netloc
+ name = urlparse.urlparse(file).netloc
if name:
name = pat0.sub("", name)
diff --git a/pyload/webui/app/api.py b/pyload/webui/app/api.py
index 7f1b230da..591b97437 100644
--- a/pyload/webui/app/api.py
+++ b/pyload/webui/app/api.py
@@ -1,9 +1,9 @@
# -*- coding: utf-8 -*-
import traceback
+import urllib
from itertools import chain
-from urllib import unquote
from SafeEval import const_eval as literal_eval
from bottle import route, request, response, HTTPError
@@ -46,7 +46,7 @@ def call_api(func, args=""):
for x, y in chain(request.GET.iteritems(), request.POST.iteritems()):
if x == "session":
continue
- kwargs[x] = unquote(y)
+ kwargs[x] = urllib.unquote(y)
try:
return callApi(func, *args, **kwargs)
diff --git a/pyload/webui/app/cnl.py b/pyload/webui/app/cnl.py
index fb64cbc5c..c02e0d1ff 100644
--- a/pyload/webui/app/cnl.py
+++ b/pyload/webui/app/cnl.py
@@ -4,8 +4,8 @@ from __future__ import with_statement
import os
import re
+import urllib
-from urllib import unquote
from base64 import standard_b64decode
from binascii import unhexlify
@@ -80,7 +80,7 @@ def addcrypted2():
crypted = request.forms['crypted']
jk = request.forms['jk']
- crypted = standard_b64decode(unquote(crypted.replace(" ", "+")))
+ crypted = standard_b64decode(urllib.unquote(crypted.replace(" ", "+")))
if JS:
jk = "%s f()" % jk
jk = JS.eval(jk)
diff --git a/pyload/webui/app/pyloadweb.py b/pyload/webui/app/pyloadweb.py
index 8ce9f2f74..316717b26 100644
--- a/pyload/webui/app/pyloadweb.py
+++ b/pyload/webui/app/pyloadweb.py
@@ -4,11 +4,11 @@
import os
import sys
import time
+import urllib
from datetime import datetime
from operator import itemgetter, attrgetter
from sys import getfilesystemencoding
-from urllib import unquote
from bottle import route, static_file, request, response, redirect, error
@@ -228,7 +228,7 @@ def downloads():
@route('/downloads/get/<path:path>')
@login_required("DOWNLOAD")
def get_download(path):
- path = unquote(path).decode("utf8")
+ path = urllib.unquote(path).decode("utf8")
#@TODO some files can not be downloaded
root = PYLOAD.getConfigValue("general", "download_folder")
diff --git a/tests/APIExerciser.py b/tests/APIExerciser.py
index 25eb666d7..02bfef20d 100644
--- a/tests/APIExerciser.py
+++ b/tests/APIExerciser.py
@@ -7,10 +7,10 @@ import gc
import random
import string
import threading
+import time
import traceback
from math import floor
-from time import time
from pyload.remote.thriftbackend.ThriftClient import ThriftClient, Destination
@@ -48,7 +48,7 @@ class APIExerciser(threading.Thread):
self.setDaemon(True)
self.core = core
self.count = 0 #: number of methods
- self.time = time()
+ self.time = time.time()
self.api = ThriftClient(user=user, password=pw) if thrift else core.api
@@ -84,11 +84,11 @@ class APIExerciser(threading.Thread):
if not sumCalled % 1000: #: not thread safe
self.core.log.info("Exercisers tested %d api calls" % sumCalled)
- persec = sumCalled / (time() - self.time)
+ persec = sumCalled / (time.time() - self.time)
self.core.log.info("Approx. %.2f calls per second." % persec)
self.core.log.info("Approx. %.2f ms per call." % (1000 / persec))
self.core.log.info("Collected garbage: %d" % gc.collect())
- # sleep(random() / 500)
+ # time.sleep(random() / 500)
def testAPI(self):
diff --git a/tests/test_json.py b/tests/test_json.py
index a83ef0a24..82a2a3d07 100644
--- a/tests/test_json.py
+++ b/tests/test_json.py
@@ -1,10 +1,10 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
-from urllib import urlencode
-from urllib2 import urlopen, HTTPError
-from json import loads
+import urllib
+import urllib2
+from json import loads
from logging import log
url = "http://localhost:8001/api/%s"
@@ -15,25 +15,25 @@ class TestJson(object):
def call(self, name, post=None):
if not post: post = {}
post['session'] = self.key
- u = urlopen(url % name, data=urlencode(post))
+ u = urllib2.urlopen(url % name, data=urlencode(post))
return loads(u.read())
def setUp(self):
- u = urlopen(url % "login", data=urlencode({"username": "TestUser", "password": "pwhere"}))
+ u = urllib2.urlopen(url % "login", data=urlencode({"username": "TestUser", "password": "pwhere"}))
self.key = loads(u.read())
assert self.key is not False
def test_wronglogin(self):
- u = urlopen(url % "login", data=urlencode({"username": "crap", "password": "wrongpw"}))
+ u = urllib2.urlopen(url % "login", data=urlencode({"username": "crap", "password": "wrongpw"}))
assert loads(u.read()) is False
def test_access(self):
try:
- urlopen(url % "getServerVersion")
- except HTTPError, e:
+ urllib2.urlopen(url % "getServerVersion")
+ except urllib2.HTTPError, e:
assert e.code == 403
else:
assert False
@@ -49,7 +49,7 @@ class TestJson(object):
def test_unknown_method(self):
try:
self.call("notExisting")
- except HTTPError, e:
+ except urllib2.HTTPError, e:
assert e.code == 404
else:
assert False