diff options
author | Walter Purcaro <vuolter@users.noreply.github.com> | 2015-05-12 02:17:30 +0200 |
---|---|---|
committer | Walter Purcaro <vuolter@users.noreply.github.com> | 2015-05-12 03:22:32 +0200 |
commit | 000426c9d890ba2a71625a7454f9c573f10b9bae (patch) | |
tree | 8fa66da5061b850778f72f84038d9bb8bfa31f2f /pyload/network | |
parent | 'from os' -> 'import os' and so on... (diff) | |
download | pyload-000426c9d890ba2a71625a7454f9c573f10b9bae.tar.xz |
'from time' -> 'import time' and so on...
Diffstat (limited to 'pyload/network')
-rw-r--r-- | pyload/network/Bucket.py | 7 | ||||
-rw-r--r-- | pyload/network/CookieJar.py | 4 | ||||
-rw-r--r-- | pyload/network/HTTPChunk.py | 11 | ||||
-rw-r--r-- | pyload/network/HTTPDownload.py | 6 | ||||
-rw-r--r-- | pyload/network/HTTPRequest.py | 9 | ||||
-rw-r--r-- | pyload/network/JsEngine.py | 11 | ||||
-rw-r--r-- | pyload/network/XDCCRequest.py | 6 |
7 files changed, 26 insertions, 28 deletions
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 |