summaryrefslogtreecommitdiffstats
path: root/pyload/network
diff options
context:
space:
mode:
Diffstat (limited to 'pyload/network')
-rw-r--r--pyload/network/Browser.py6
-rw-r--r--pyload/network/HTTPChunk.py5
-rw-r--r--pyload/network/HTTPDownload.py43
-rw-r--r--pyload/network/HTTPRequest.py2
4 files changed, 29 insertions, 27 deletions
diff --git a/pyload/network/Browser.py b/pyload/network/Browser.py
index d8617fabc..a499336c3 100644
--- a/pyload/network/Browser.py
+++ b/pyload/network/Browser.py
@@ -124,7 +124,8 @@ class Browser(object):
def removeAuth(self):
- if "auth" in self.options: del self.options['auth']
+ if "auth" in self.options:
+ del self.options['auth']
self.renewHTTPRequest()
@@ -134,7 +135,8 @@ class Browser(object):
def deleteOption(self, name):
- if name in self.options: del self.options[name]
+ if name in self.options:
+ del self.options[name]
def clearHeaders(self):
diff --git a/pyload/network/HTTPChunk.py b/pyload/network/HTTPChunk.py
index 784b64349..86c88fe8e 100644
--- a/pyload/network/HTTPChunk.py
+++ b/pyload/network/HTTPChunk.py
@@ -51,7 +51,7 @@ class ChunkInfo(object):
chunk_size = self.size / chunks
current = 0
- for i in range(chunks):
+ for i in xrange(chunks):
end = self.size - 1 if (i == chunks - 1) else current + chunk_size
self.addChunk("%s.chunk%s" % (self.name, i), (current, end))
current += chunk_size + 1
@@ -310,7 +310,8 @@ class HTTPChunk(HTTPRequest):
""" closes everything, unusable after this """
if self.fp: self.fp.close()
self.c.close()
- if hasattr(self, "p"): del self.p
+ if hasattr(self, "p"):
+ del self.p
def charEnc(enc):
diff --git a/pyload/network/HTTPDownload.py b/pyload/network/HTTPDownload.py
index 13666195a..8bf822a15 100644
--- a/pyload/network/HTTPDownload.py
+++ b/pyload/network/HTTPDownload.py
@@ -1,6 +1,8 @@
# -*- coding: utf-8 -*-
# @author: RaNaN
+from __future__ import with_statement
+
from os import remove, fsync
from os.path import dirname
from time import sleep, time
@@ -81,27 +83,24 @@ class HTTPDownload(object):
init = fs_encode(self.info.getChunkName(0)) #: initial chunk name
if self.info.getCount() > 1:
- fo = open(init, "rb+") #: first chunkfile
- for i in range(1, self.info.getCount()):
- #input file
- fo.seek(
- self.info.getChunkRange(i - 1)[1] + 1) #: seek to beginning of chunk, to get rid of overlapping chunks
- fname = fs_encode("%s.chunk%d" % (self.filename, i))
- fi = open(fname, "rb")
- buf = 32 * 1024
- while True: #: copy in chunks, consumes less memory
- data = fi.read(buf)
- if not data:
- break
- fo.write(data)
- fi.close()
- if fo.tell() < self.info.getChunkRange(i)[1]:
- fo.close()
- remove(init)
- self.info.remove() #: there are probably invalid chunks
- raise Exception("Downloaded content was smaller than expected. Try to reduce download connections.")
- remove(fname) #: remove chunk
- fo.close()
+ with open(init, "rb+") as fo: #: first chunkfile
+ for i in xrange(1, self.info.getCount()):
+ #input file
+ fo.seek(
+ self.info.getChunkRange(i - 1)[1] + 1) #: seek to beginning of chunk, to get rid of overlapping chunks
+ fname = fs_encode("%s.chunk%d" % (self.filename, i))
+ with open(fname, "rb") as fi:
+ buf = 32 * 1024
+ while True: #: copy in chunks, consumes less memory
+ data = fi.read(buf)
+ if not data:
+ break
+ fo.write(data)
+ if fo.tell() < self.info.getChunkRange(i)[1]:
+ remove(init)
+ self.info.remove() #: there are probably invalid chunks
+ raise Exception("Downloaded content was smaller than expected. Try to reduce download connections.")
+ remove(fname) #: remove chunk
if self.nameDisposition and self.disposition:
self.filename = fs_join(dirname(self.filename), self.nameDisposition)
@@ -174,7 +173,7 @@ class HTTPDownload(object):
init.setRange(self.info.getChunkRange(0))
- for i in range(1, chunks):
+ for i in xrange(1, chunks):
c = HTTPChunk(i, self, self.info.getChunkRange(i), resume)
handle = c.getHandle()
diff --git a/pyload/network/HTTPRequest.py b/pyload/network/HTTPRequest.py
index 62c0ef72b..d87a3ee7e 100644
--- a/pyload/network/HTTPRequest.py
+++ b/pyload/network/HTTPRequest.py
@@ -24,7 +24,7 @@ def myurlencode(data):
data = dict(data)
return urlencode(dict((encode(x), encode(y)) for x, y in data.iteritems()))
-bad_headers = range(400, 404) + range(405, 418) + range(500, 506)
+bad_headers = xrange(400, 404) + xrange(405, 418) + xrange(500, 506)
class BadHeader(Exception):