diff options
-rwxr-xr-x | proxy.py | 13 |
1 files changed, 6 insertions, 7 deletions
@@ -31,15 +31,14 @@ FETCHER_JUMPSTART = 32 * kB ################# class Fetcher(asynchat.async_chat): - def __init__(self, reader, endpoint, url, headers, range): + def __init__(self, reader, proxy, url, headers, range): self.reader = reader - self.endpoint = endpoint + self.proxy = proxy self.url = url self.headers = headers self.range = range self.pos = self.range[0] - self.proxy = ENDPOINTS[endpoint] self.start_time = 0 self.stop_time = 0 self.http_status = "" @@ -110,8 +109,8 @@ class MultipleProxyReader(object): self.blocks = list() self.fetchers = list() - for i in range(len(ENDPOINTS)): - self.fetchers.append( Fetcher(self, i, self.url, self.header, self.next_range(INIT_BLOCKSIZE)) ) + for proxy in ENDPOINTS: + self.fetchers.append( Fetcher(self, proxy, self.url, self.header, self.next_range(INIT_BLOCKSIZE)) ) def handle_incoming_data(self, fetcher, data): if len(data) == 0: @@ -121,12 +120,12 @@ class MultipleProxyReader(object): if fetcher.range[1] - fetcher.pos < FETCHER_JUMPSTART \ and self.fetch_pos + 1 < self.content_length and not self.channel.is_closed \ - and len( filter( (lambda f: f.endpoint == fetcher.endpoint), self.fetchers) ) < 2: + and len( filter( (lambda f: f.proxy == fetcher.proxy), self.fetchers) ) < 2: #Start a new fetcher on this line if this fetchers is X-Bytes before finishing his jobs blocksize = min(TIME_SLICE * int(fetcher.speed()), MIN_BLOCKSIZE) fetch_range = self.next_range(blocksize) print "Start new Fetcher, bs=%s range=%s" % (blocksize,fetch_range) - self.fetchers.append( Fetcher(self, fetcher.endpoint, self.url, self.header, fetch_range) ) + self.fetchers.append( Fetcher(self, fetcher.proxy, self.url, self.header, fetch_range) ) while self.send_next_data(): pass |