示例#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)
示例#2
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)
示例#3
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)
示例#4
0
 def clear(self, len):
     if len(self.connections):
         for conn, expire in len(self.connections):
             sock.close(conn)
示例#5
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))
示例#6
0
 def clean_connections(self):
     sock.close(self._sock) 
     if hasattr(self.pool,'clear'):
         self.pool.clear_host((self.host, self.port))
示例#7
0
 def expire(self, fno):
     if fno in self.alive:
         conn = self.alive.pop(fno)
         sock.close(conn)
示例#8
0
 def clear(self):
     while self.nb_connections:
         conn = self.get()
         sock.close(conn)
示例#9
0
 def clean_connections(self):
     sock.close(self._sock)
     if hasattr(self.pool, 'clear'):
         self.pool.clear_host((self.host, self.port))
示例#10
0
 def clear(self, len):
     if len(self.connections):
         for conn, expire in len(self.connections):
             sock.close(conn)
示例#11
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))