def put(self, conn): if self.nb_connections < self.keepalive and not self.waiting(): sock.close(conn) return self.nb_connections += 1 self.do_put(conn) self.monitor(conn)
def do_redirect(self, response, location): """ follow redirections if needed""" if self.nb_redirections <= 0: raise RedirectLimit("Redirection limit is reached") if not location: raise RequestError('no Location header') new_uri = urlparse.urlparse(location) if not new_uri.netloc: # we got a relative url absolute_uri = "%s://%s" % (self.uri.scheme, self.uri.netloc) location = urlparse.urljoin(absolute_uri, location) log.debug("Redirect to %s" % location) self.final_url = location response.body.read() self.nb_redirections -= 1 sock.close(self._sock) return self.request(location, self.method, self.body, self.headers)
def clear(self, len): if len(self.connections): for conn, expire in len(self.connections): sock.close(conn)
def put(self, conn): if len(self.connections) >= self.keepalive: sock.close(conn) return expires = time.time() + self.timeout self.connections.append((conn, expires))
def clean_connections(self): sock.close(self._sock) if hasattr(self.pool,'clear'): self.pool.clear_host((self.host, self.port))
def expire(self, fno): if fno in self.alive: conn = self.alive.pop(fno) sock.close(conn)
def clear(self): while self.nb_connections: conn = self.get() sock.close(conn)
def clean_connections(self): sock.close(self._sock) if hasattr(self.pool, 'clear'): self.pool.clear_host((self.host, self.port))