summaryrefslogtreecommitdiffstats
path: root/module/network
diff options
context:
space:
mode:
Diffstat (limited to 'module/network')
-rw-r--r--module/network/Bucket.py4
-rw-r--r--module/network/HTTPChunk.py2
-rw-r--r--module/network/HTTPDownload.py2
-rw-r--r--module/network/HTTPRequest.py8
-rw-r--r--module/network/RequestFactory.py4
-rw-r--r--module/network/XDCCRequest.py52
6 files changed, 35 insertions, 37 deletions
diff --git a/module/network/Bucket.py b/module/network/Bucket.py
index 69da277ae..add3861d6 100644
--- a/module/network/Bucket.py
+++ b/module/network/Bucket.py
@@ -13,7 +13,7 @@
You should have received a copy of the GNU General Public License
along with this program; if not, see <http://www.gnu.org/licenses/>.
-
+
@author: RaNaN
"""
@@ -47,7 +47,7 @@ class Bucket:
time = -self.tokens/float(self.rate)
else:
time = 0
-
+
self.lock.release()
return time
diff --git a/module/network/HTTPChunk.py b/module/network/HTTPChunk.py
index b637aef32..91a1b06e8 100644
--- a/module/network/HTTPChunk.py
+++ b/module/network/HTTPChunk.py
@@ -13,7 +13,7 @@
You should have received a copy of the GNU General Public License
along with this program; if not, see <http://www.gnu.org/licenses/>.
-
+
@author: RaNaN
"""
from os import remove, stat, fsync
diff --git a/module/network/HTTPDownload.py b/module/network/HTTPDownload.py
index fe8075539..ab2de1e94 100644
--- a/module/network/HTTPDownload.py
+++ b/module/network/HTTPDownload.py
@@ -13,7 +13,7 @@
You should have received a copy of the GNU General Public License
along with this program; if not, see <http://www.gnu.org/licenses/>.
-
+
@author: RaNaN
"""
diff --git a/module/network/HTTPRequest.py b/module/network/HTTPRequest.py
index 4747d937f..6b4df665d 100644
--- a/module/network/HTTPRequest.py
+++ b/module/network/HTTPRequest.py
@@ -13,7 +13,7 @@
You should have received a copy of the GNU General Public License
along with this program; if not, see <http://www.gnu.org/licenses/>.
-
+
@author: RaNaN
"""
@@ -29,7 +29,7 @@ from module.plugins.Plugin import Abort
def myquote(url):
return quote(url.encode('utf_8') if isinstance(url, unicode) else url, safe="%/:=&?~#+!$,;'@()*[]")
-
+
def myurlencode(data):
data = dict(data)
return urlencode(dict((x.encode('utf_8') if isinstance(x, unicode) else x, \
@@ -255,7 +255,7 @@ class HTTPRequest():
#self.log.debug("Decoded %s" % encoding )
if lookup(encoding).name == 'utf-8' and rep.startswith(BOM_UTF8):
encoding = 'utf-8-sig'
-
+
decoder = getincrementaldecoder(encoding)("replace")
rep = decoder.decode(rep, True)
@@ -303,4 +303,4 @@ if __name__ == "__main__":
url = "http://pyload.org"
c = HTTPRequest()
print c.load(url)
-
+
diff --git a/module/network/RequestFactory.py b/module/network/RequestFactory.py
index 5b1528281..27b2e5606 100644
--- a/module/network/RequestFactory.py
+++ b/module/network/RequestFactory.py
@@ -13,7 +13,7 @@
You should have received a copy of the GNU General Public License
along with this program; if not, see <http://www.gnu.org/licenses/>.
-
+
@author: mkaay, RaNaN
"""
@@ -67,7 +67,7 @@ class RequestFactory():
rep = h.load(*args, **kwargs)
finally:
h.close()
-
+
return rep
def getCookieJar(self, pluginName, account=None):
diff --git a/module/network/XDCCRequest.py b/module/network/XDCCRequest.py
index f03798c17..d59be40c1 100644
--- a/module/network/XDCCRequest.py
+++ b/module/network/XDCCRequest.py
@@ -13,7 +13,7 @@
You should have received a copy of the GNU General Public License
along with this program; if not, see <http://www.gnu.org/licenses/>.
-
+
@author: jeix
"""
@@ -33,17 +33,16 @@ from module.plugins.Plugin import Abort
class XDCCRequest():
def __init__(self, timeout=30, proxies={}):
-
+
self.proxies = proxies
self.timeout = timeout
-
+
self.filesize = 0
self.recv = 0
self.speed = 0
-
+
self.abort = False
-
def createSocket(self):
# proxytype = None
# proxy = None
@@ -60,33 +59,33 @@ class XDCCRequest():
# else:
# sock = socket.socket()
# return sock
-
+
return socket.socket()
-
+
def download(self, ip, port, filename, irc, progressNotify=None):
ircbuffer = ""
lastUpdate = time()
cumRecvLen = 0
-
+
dccsock = self.createSocket()
-
+
dccsock.settimeout(self.timeout)
dccsock.connect((ip, port))
-
+
if exists(filename):
i = 0
nameParts = filename.rpartition(".")
while True:
newfilename = "%s-%d%s%s" % (nameParts[0], i, nameParts[1], nameParts[2])
i += 1
-
+
if not exists(newfilename):
filename = newfilename
break
-
+
fh = open(filename, "wb")
-
+
# recv loop for dcc socket
while True:
if self.abort:
@@ -94,44 +93,43 @@ class XDCCRequest():
fh.close()
remove(filename)
raise Abort()
-
+
self._keepAlive(irc, ircbuffer)
-
+
data = dccsock.recv(4096)
dataLen = len(data)
self.recv += dataLen
-
+
cumRecvLen += dataLen
-
+
now = time()
timespan = now - lastUpdate
if timespan > 1:
self.speed = cumRecvLen / timespan
cumRecvLen = 0
lastUpdate = now
-
+
if progressNotify:
progressNotify(self.percent)
-
-
+
if not data:
break
-
+
fh.write(data)
-
+
# acknowledge data by sending number of recceived bytes
dccsock.send(struct.pack('!I', self.recv))
-
+
dccsock.close()
fh.close()
-
+
return filename
-
+
def _keepAlive(self, sock, readbuffer):
fdset = select([sock], [], [], 0)
if sock not in fdset[0]:
return
-
+
readbuffer += sock.recv(1024)
temp = readbuffer.split("\n")
readbuffer = temp.pop()
@@ -144,7 +142,7 @@ class XDCCRequest():
def abortDownloads(self):
self.abort = True
-
+
@property
def size(self):
return self.filesize