def test_get_socket_timeout(self): self.assertEqual(pulsar.get_socket_timeout(None), None) self.assertEqual(pulsar.get_socket_timeout(-2.3), None) self.assertEqual(pulsar.get_socket_timeout('-1'), None) self.assertEqual(pulsar.get_socket_timeout(-1), None) self.assertEqual(pulsar.get_socket_timeout(0.0), 0) self.assertEqual(pulsar.get_socket_timeout(0),0) self.assertEqual(pulsar.get_socket_timeout(False),0) self.assertEqual(pulsar.get_socket_timeout(1.0),1) self.assertEqual(pulsar.get_socket_timeout(3.2),3.2) self.assertEqual(pulsar.get_socket_timeout(5),5)
def __init__(self, socket, address, timeout=None, read_timeout=None, **kwargs): '''Create a client or client-connection socket. :parameter socket: a client or client-connection socket :parameter address: The address of the remote client/server :parameter protocol_factory: A callable used for creating :attr:`ProtoSocket.protocol` instance. :parameter timeout: A timeout in seconds for the socket. Same rules as the ``socket.settimeout`` method in the standard library. A value of 0 indicates an asynchronous socket. :parameter read_timeout: A timeout in seconds for asynchronous operations. This value is only used when *timeout* is 0 in the constructor of a :class:`AsyncIOStream`. ''' self._socket_timeout = get_socket_timeout(timeout) self._set_socket(socket, read_timeout) self.remote_address = address self.protocol = self.protocol_factory() self.buffer = bytearray()