Example #1
0
 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)
Example #2
0
 def put(self, conn):
     if self.nb_connections > self.keepalive and self.waiting():
         sock.close(conn)
         return
     self.nb_connections += 1
     self.do_put(conn)
     self.alive[conn.fileno()] = (conn, self.timeout + time.time())
Example #3
0
 def murder_connections(self):
     for fno, connection in self.alive.items():
         conn, expires = connection
         if expires < time.time():
             sock.close(conn)
             self.nb_connections -= 1
             del self.alive[fno]
Example #4
0
 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 release_connection(self, address, socket):
     if self.should_close:
         sock.close(self._sock) 
     else:
         self.pool.put(address, self._sock)
     self._sock = None
 def clean_connections(self):
     sock.close(self._sock)
     self._sock = None
     if hasattr(self.pool,'clear'):
         self.pool.clear_host((self.host, self.port))
Example #7
0
 def expire(self, fno):
     if fno in self.alive:
         conn = self.alive.pop(fno)
         sock.close(conn)
Example #8
0
 def clear(self):
     while self.nb_connections:
         conn = self.get()
         sock.close(conn)
 def close(self):
     sock.close(self.sock)
Example #10
0
 def shutdown(self):
     while self.connections:
         conn, expires = self.connections.pop()
         sock.close(conn)
Example #11
0
 def clear(self, len):
     if len(self.connections):
         for conn, expire in len(self.connections):
             sock.close(conn)
Example #12
0
 def put(self, conn):
     if len(self.connections) >= self.keepalive:
         sock.close(conn)
         return
     expires = time.time() + self.timeout
     self.connections.append((conn, expires))
Example #13
0
 def clear(self):
     while self.nb_connections:
         self.nb_connections -= 1
         conn = self.do_get()
         sock.close(conn)
Example #14
0
 def shutdown(self):
     while self.connections:
         conn, expires = self.connections.pop()
         sock.close(conn)
Example #15
0
 def close(self):
     sock.close(self.sock)
Example #16
0
 def clear(self):
     while self.connections:
         conn, expires = self.connections.popleft()
         sock.close(conn)