コード例 #1
0
    def _receive(self, timeout, logger):
        """Read session buffer."""
        timeout = timeout if timeout else self._timeout
        self._handler.settimeout(timeout)

        try:
            data = self._handler.recv(self._buffer_size)
        except socket.timeout:
            raise SessionReadTimeout()

        if not data:
            raise SessionReadEmptyData()

        return data
コード例 #2
0
    def _receive(self, timeout, logger):
        """Read session buffer."""
        timeout = timeout if timeout else self._timeout
        self._handler.get_socket().settimeout(timeout)

        try:
            byte_data = self._handler.read_some()
        except socket.timeout:
            raise SessionReadTimeout()

        if not byte_data:
            raise SessionReadEmptyData()

        data = byte_data.decode()
        return data
コード例 #3
0
    def _receive(self, timeout, logger):
        """read session buffer

        :param timeout:
        :return: output
        """

        timeout = timeout if timeout else self._timeout
        self._handler.get_socket().settimeout(timeout)

        try:
            data = self._handler.read_some()
        except socket.timeout:
            raise SessionReadTimeout()

        if not data:
            raise SessionReadEmptyData()

        return data
コード例 #4
0
    def _receive(self, timeout, logger):
        """Read session buffer

        :param timeout: time between retries
        :return:
        """

        # Set the channel timeout
        timeout = timeout if timeout else self._timeout
        self._current_channel.settimeout(timeout)

        try:
            data = self._current_channel.recv(self._buffer_size)
        except socket.timeout:
            raise SessionReadTimeout()

        if not data:
            raise SessionReadEmptyData()

        return data
コード例 #5
0
 def test_clear_buffer_receive_call(self, normalize_buffer, loops_detected):
     timeout = Mock()
     self._receive.side_effect = SessionReadTimeout()
     self._instance._clear_buffer(timeout, self._logger)
     self._receive.assert_called_once_with(timeout, self._logger)
コード例 #6
0
 def test_receive_get_all_data(self, normalize_buffer, loops_detected):
     data1 = "test"
     data2 = "tesst"
     self._receive.side_effect = [data1, data2, SessionReadTimeout()]
     result = self._instance._receive_all(2, self._logger)
     self.assertTrue(result and result == data1 + data2)
コード例 #7
0
 def test_receive_all_receive_call(self, normalize_buffer, loops_detected):
     self._receive.side_effect = ["test", SessionReadTimeout()]
     self._instance._receive_all(2, self._logger)
     mock_calls = [call(0.1, self._logger), call(0.1, self._logger)]
     self._receive.assert_has_calls(mock_calls)
コード例 #8
0
 def test_receive_all_exit_by_timeout(self, normalize_buffer,
                                      loops_detected):
     self._receive.side_effect = SessionReadTimeout()
     exception = ExpectedSessionException
     with self.assertRaises(exception):
         self._instance._receive_all(0.1, self._logger)