def attach(self, host, port, handle_connect, handle_connect_error, connect_timeout): "Find an idle connection for (host, port), or create a new one." while True: try: tcp_conn = self._conns[(host, port)].pop() except (IndexError, KeyError): push_tcp.create_client(host, port, handle_connect, handle_connect_error, connect_timeout) break if tcp_conn.tcp_connected: tcp_conn.read_cb, tcp_conn.close_cb, tcp_conn.pause_cb = \ handle_connect(tcp_conn) break
def get(self, host, port, connection_handler, connect_timeout): "Find a connection for (host, port), or create a new one." try: conn = self._conns[(host, port)] except KeyError: conn = connection_handler() push_tcp.create_client( host, port, conn.handle_connect, conn.handle_connect_error, connect_timeout ) self._conns[(host, port)] = conn return conn