diff options
author | RaNaN <Mast3rRaNaN@hotmail.de> | 2011-12-04 13:39:42 +0100 |
---|---|---|
committer | RaNaN <Mast3rRaNaN@hotmail.de> | 2011-12-04 13:39:42 +0100 |
commit | d2e3afceb738af20aeb8e41f9aad12150cf1e8a7 (patch) | |
tree | 91a1ce5bc7fb51be6c3d188aed11552662d6f4bf /module/network/HTTPChunk.py | |
parent | closed #440 (diff) | |
download | pyload-d2e3afceb738af20aeb8e41f9aad12150cf1e8a7.tar.xz |
Better download connection handling: Detect server error earlier, fallback to single connection if possible
Diffstat (limited to 'module/network/HTTPChunk.py')
-rw-r--r-- | module/network/HTTPChunk.py | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/module/network/HTTPChunk.py b/module/network/HTTPChunk.py index 69eedb19c..582067aa8 100644 --- a/module/network/HTTPChunk.py +++ b/module/network/HTTPChunk.py @@ -16,7 +16,7 @@ @author: RaNaN """ -from os import remove, stat +from os import remove, stat, fsync from os.path import exists from time import sleep from re import search @@ -146,6 +146,9 @@ class HTTPChunk(HTTPRequest): self.sleep = 0.000 self.lastSize = 0 + def __repr__(self): + return "<HTTPChunk id=%d, size=%d, arrived=%d>" % (self.id, self.size, self.arrived) + @property def cj(self): return self.p.cj @@ -157,7 +160,7 @@ class HTTPChunk(HTTPRequest): self.c.setopt(pycurl.WRITEFUNCTION, self.writeBody) self.c.setopt(pycurl.HEADERFUNCTION, self.writeHeader) - # request one byte more, since some servers in russia seems to have a defect arihmetic unit + # request all bytes, since some servers in russia seems to have a defect arihmetic unit if self.resume: self.fp = open(self.p.info.getChunkName(self.id), "ab") @@ -259,10 +262,25 @@ class HTTPChunk(HTTPRequest): self.headerParsed = True + def stop(self): + """The download will not proceed after next call of writeBody""" + self.range = [0,0] + self.size = 0 + + def resetRange(self): + """ Reset the range, so the download will load all data available """ + self.range = None + def setRange(self, range): self.range = range self.size = range[1] - range[0] + def flushFile(self): + """ flush and close file """ + self.fp.flush() + fsync(self.fp.fileno()) #make sure everything was written to disk + self.fp.close() #needs to be closed, or merging chunks will fail + def close(self): """ closes everything, unusable after this """ if self.fp: self.fp.close() |