1
2
3
4
5
6 import socket
7
8 from restkit.pool.base import BasePool
9 from restkit.util import sock
10
12
19
21 while self.nb_connections:
22 self.nb_connections -= 1
23 conn = self.do_get()
24 try:
25 _ = conn.fileno()
26 return conn
27 except socket.error:
28 """ connection probably closed """
29 continue
30 return None
31
32 - def put(self, conn):
39
41 while self.nb_connections:
42 conn = self.get()
43 sock.close(conn)
44
46 if fno in self.alive:
47 conn = self.alive.pop(fno)
48 sock.close(conn)
49
51 self.alive[conn.fileno()] = conn
52
54 raise NotImplementedError
55
57 raise NotImplementedError
58
60 raise NotImplementedError
61
63 raise NotImplementedError
64
65
67
68 HOST_CLASS = None
69
73
74 - def get(self, netloc):
75 if netloc not in self._hosts:
76 return
77 host = self._hosts[netloc]
78 return host.get()
79
80 - def put(self, netloc, conn):
81 if netloc in self._hosts:
82 host = self._hosts[netloc]
83 else:
84 host = self.HOST_CLASS(self.keepalive, self.timeout)
85 self._hosts[netloc] = host
86 host.put(conn)
87
89 if netloc not in self._hosts:
90 return
91 host = self._hosts[netloc]
92 host.clear()
93 del self._hosts[netloc]
94
96 for netloc, host in self._hosts.items():
97 host.clear()
98 del self._hosts[netloc]
99