diff options
Diffstat (limited to 'pyload/network')
-rw-r--r-- | pyload/network/Browser.py | 6 | ||||
-rw-r--r-- | pyload/network/Bucket.py | 2 | ||||
-rw-r--r-- | pyload/network/HTTPChunk.py | 24 | ||||
-rw-r--r-- | pyload/network/HTTPDownload.py | 40 | ||||
-rw-r--r-- | pyload/network/RequestFactory.py | 26 |
5 files changed, 49 insertions, 49 deletions
diff --git a/pyload/network/Browser.py b/pyload/network/Browser.py index 61bf523ab..fab7454f3 100644 --- a/pyload/network/Browser.py +++ b/pyload/network/Browser.py @@ -13,10 +13,10 @@ class Browser(object): def __init__(self, bucket=None, options={}): self.log = getLogger("log") - self.options = options #holds pycurl options + self.options = options #: holds pycurl options self.bucket = bucket - self.cj = None # needs to be setted later + self.cj = None #: needs to be setted later self._size = 0 self.renewHTTPRequest() @@ -119,7 +119,7 @@ class Browser(object): :param pwd: string, user:password """ self.options["auth"] = pwd - self.renewHTTPRequest() #we need a new request + self.renewHTTPRequest() #: we need a new request def removeAuth(self): diff --git a/pyload/network/Bucket.py b/pyload/network/Bucket.py index 408a1e240..5f8260384 100644 --- a/pyload/network/Bucket.py +++ b/pyload/network/Bucket.py @@ -10,7 +10,7 @@ MIN_RATE = 10240 #: 10kb minimum rate class Bucket(object): def __init__(self): - self.rate = 0 # bytes per second, maximum targeted throughput + self.rate = 0 #: bytes per second, maximum targeted throughput self.tokens = 0 self.timestamp = time() self.lock = Lock() diff --git a/pyload/network/HTTPChunk.py b/pyload/network/HTTPChunk.py index c11ad9e3c..82e1ca76e 100644 --- a/pyload/network/HTTPChunk.py +++ b/pyload/network/HTTPChunk.py @@ -86,7 +86,7 @@ class ChunkInfo(object): ci.loaded = True ci.setSize(size) while True: - if not fh.readline(): #skip line + if not fh.readline(): #: skip line break name = fh.readline()[1:-1] range = fh.readline()[1:-1] @@ -122,8 +122,8 @@ class HTTPChunk(HTTPRequest): def __init__(self, id, parent, range=None, resume=False): self.id = id - self.p = parent # HTTPDownload instance - self.range = range # tuple (start, end) + self.p = parent #: HTTPDownload instance + self.range = range #: tuple (start, end) self.resume = resume self.log = parent.log @@ -134,14 +134,14 @@ class HTTPChunk(HTTPRequest): self.c = pycurl.Curl() self.header = "" - self.headerParsed = False #indicates if the header has been processed + self.headerParsed = False #: indicates if the header has been processed - self.fp = None #file handle + self.fp = None #: file handle self.initHandle() self.setInterface(self.p.options) - self.BOMChecked = False # check and remove byte order mark + self.BOMChecked = False #: check and remove byte order mark self.rep = None @@ -175,10 +175,10 @@ class HTTPChunk(HTTPRequest): self.arrived = stat(fs_name).st_size if self.range: - #do nothing if chunk already finished + # do nothing if chunk already finished if self.arrived + self.range[0] >= self.range[1]: return None - if self.id == len(self.p.info.chunks) - 1: #as last chunk dont set end range, so we get everything + if self.id == len(self.p.info.chunks) - 1: #: as last chunk dont set end range, so we get everything range = "%i-" % (self.arrived + self.range[0]) else: range = "%i-%i" % (self.arrived + self.range[0], min(self.range[1] + 1, self.p.size - 1)) @@ -191,7 +191,7 @@ class HTTPChunk(HTTPRequest): else: if self.range: - if self.id == len(self.p.info.chunks) - 1: # see above + if self.id == len(self.p.info.chunks) - 1: #: see above range = "%i-" % self.range[0] else: range = "%i-%i" % (self.range[0], min(self.range[1] + 1, self.p.size - 1)) @@ -249,7 +249,7 @@ class HTTPChunk(HTTPRequest): sleep(self.sleep) if self.range and self.arrived > self.size: - return 0 #close if we have enough data + return 0 #: close if we have enough data def parseHeader(self): @@ -300,8 +300,8 @@ class HTTPChunk(HTTPRequest): 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 + 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): diff --git a/pyload/network/HTTPDownload.py b/pyload/network/HTTPDownload.py index 0580a6b90..32c165f82 100644 --- a/pyload/network/HTTPDownload.py +++ b/pyload/network/HTTPDownload.py @@ -34,7 +34,7 @@ class HTTPDownload(object): self.abort = False self.size = 0 - self.nameDisposition = None #will be parsed from content disposition + self.nameDisposition = None #: will be parsed from content disposition self.chunks = [] @@ -42,7 +42,7 @@ class HTTPDownload(object): try: self.info = ChunkInfo.load(filename) - self.info.resume = True #resume is only possible with valid info file + self.info.resume = True #: resume is only possible with valid info file self.size = self.info.size self.infoSaved = True except IOError: @@ -77,18 +77,18 @@ class HTTPDownload(object): def _copyChunks(self): - init = fs_encode(self.info.getChunkName(0)) #initial chunk name + init = fs_encode(self.info.getChunkName(0)) #: initial chunk name if self.info.getCount() > 1: - fo = open(init, "rb+") #first chunkfile + 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 + 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 + while True: #: copy in chunks, consumes less memory data = fi.read(buf) if not data: break @@ -97,16 +97,16 @@ class HTTPDownload(object): if fo.tell() < self.info.getChunkRange(i)[1]: fo.close() remove(init) - self.info.remove() #there are probably invalid chunks + 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 + remove(fname) #: remove chunk fo.close() if self.nameDisposition and self.disposition: self.filename = fs_join(dirname(self.filename), self.nameDisposition) move(init, fs_encode(self.filename)) - self.info.remove() #remove info file + self.info.remove() #: remove info file def download(self, chunks=1, resume=False): @@ -141,12 +141,12 @@ class HTTPDownload(object): def _download(self, chunks, resume): if not resume: self.info.clear() - self.info.addChunk("%s.chunk0" % self.filename, (0, 0)) #create an initial entry + self.info.addChunk("%s.chunk0" % self.filename, (0, 0)) #: create an initial entry self.info.save() self.chunks = [] - init = HTTPChunk(0, self, None, resume) #initial chunk that will load complete file (if needed) + init = HTTPChunk(0, self, None, resume) #: initial chunk that will load complete file (if needed) self.chunks.append(init) self.m.add_handle(init.getHandle()) @@ -156,12 +156,12 @@ class HTTPDownload(object): chunksDone = set() # list of curl handles that are finished chunksCreated = False done = False - if self.info.getCount() is 0: # This is a resume, if we were chunked originally assume still can + if self.info.getCount() is 0: #: This is a resume, if we were chunked originally assume still can self.chunkSupport = False while 1: #need to create chunks - if not chunksCreated and self.chunkSupport and self.size: #will be setted later by first chunk + if not chunksCreated and self.chunkSupport and self.size: #: will be setted later by first chunk if not resume: self.info.setSize(self.size) @@ -197,12 +197,12 @@ class HTTPDownload(object): while lastFinishCheck + 0.5 < t: # list of failed curl handles failed = [] - ex = None # save only last exception, we can only raise one anyway + ex = None #: save only last exception, we can only raise one anyway num_q, ok_list, err_list = self.m.info_read() for c in ok_list: chunk = self.findChunk(c) - try: # check if the header implies success, else add it to failed list + try: #: check if the header implies success, else add it to failed list chunk.verifyHeader() except BadHeader, e: self.log.debug("Chunk %d failed: %s" % (chunk.id + 1, str(e))) @@ -221,7 +221,7 @@ class HTTPDownload(object): self.log.debug("Chunk %d failed: %s" % (chunk.id + 1, str(ex))) continue - try: # check if the header implies success, else add it to failed list + try: #: check if the header implies success, else add it to failed list chunk.verifyHeader() except BadHeader, e: self.log.debug("Chunk %d failed: %s" % (chunk.id + 1, str(e))) @@ -229,7 +229,7 @@ class HTTPDownload(object): ex = e else: chunksDone.add(curl) - if not num_q: # no more infos to get + if not num_q: #: no more infos to get # check if init is not finished so we reset download connections # note that other chunks are closed and downloaded with init too @@ -261,7 +261,7 @@ class HTTPDownload(object): break if done: - break #all chunks loaded + break #: all chunks loaded # calc speed once per second, averaging over 3 seconds if lastTimeCheck + 1 < t: @@ -278,11 +278,11 @@ class HTTPDownload(object): if self.abort: raise Abort - # sleep(0.003) #supress busy waiting - limits dl speed to (1 / x) * buffersize + # sleep(0.003) #: supress busy waiting - limits dl speed to (1 / x) * buffersize self.m.select(1) for chunk in self.chunks: - chunk.flushFile() #make sure downloads are written to disk + chunk.flushFile() #: make sure downloads are written to disk self._copyChunks() diff --git a/pyload/network/RequestFactory.py b/pyload/network/RequestFactory.py index 5f8e7e206..a80882088 100644 --- a/pyload/network/RequestFactory.py +++ b/pyload/network/RequestFactory.py @@ -21,7 +21,7 @@ class RequestFactory(object): def iface(self): - return self.core.config["download"]["interface"] + return self.core.config.get("download", "interface") def getRequest(self, pluginName, account=None, type="HTTP"): @@ -45,7 +45,7 @@ class RequestFactory(object): def getHTTPRequest(self, **kwargs): """ returns a http request, dont forget to close it ! """ options = self.getOptions() - options.update(kwargs) # submit kwargs as additional options + options.update(kwargs) #: submit kwargs as additional options return HTTPRequest(CookieJar(None), options) @@ -82,26 +82,26 @@ class RequestFactory(object): def getProxies(self): """ returns a proxy list for the request classes """ - if not self.core.config["proxy"]["proxy"]: + if not self.core.config.get("proxy", "proxy"): return {} else: type = "http" - setting = self.core.config["proxy"]["type"].lower() + setting = self.core.config.get("proxy", "type").lower() if setting == "socks4": type = "socks4" elif setting == "socks5": type = "socks5" username = None - if self.core.config["proxy"]["username"] and self.core.config["proxy"]["username"].lower() != "none": - username = self.core.config["proxy"]["username"] + if self.core.config.get("proxy", "username") and self.core.config.get("proxy", "username").lower() != "none": + username = self.core.config.get("proxy", "username") pw = None - if self.core.config["proxy"]["password"] and self.core.config["proxy"]["password"].lower() != "none": - pw = self.core.config["proxy"]["password"] + if self.core.config.get("proxy", "password") and self.core.config.get("proxy", "password").lower() != "none": + pw = self.core.config.get("proxy", "password") return { "type": type, - "address": self.core.config["proxy"]["address"], - "port": self.core.config["proxy"]["port"], + "address": self.core.config.get("proxy", "address"), + "port": self.core.config.get("proxy", "port"), "username": username, "password": pw, } @@ -111,15 +111,15 @@ class RequestFactory(object): """returns options needed for pycurl""" return {"interface": self.iface(), "proxies": self.getProxies(), - "ipv6": self.core.config["download"]["ipv6"]} + "ipv6": self.core.config.get("download", "ipv6")} def updateBucket(self): """ set values in the bucket according to settings""" - if not self.core.config["download"]["limit_speed"]: + if not self.core.config.get("download", "limit_speed"): self.bucket.setRate(-1) else: - self.bucket.setRate(self.core.config["download"]["max_speed"] * 1024) + self.bucket.setRate(self.core.config.get("download", "max_speed") * 1024) # needs pyreq in global namespace def getURL(*args, **kwargs): |