Python ssl.SSLWantWriteError() Examples
The following are 30
code examples of ssl.SSLWantWriteError().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
ssl
, or try the search function
.
Example #1
Source File: tunnelc.py From fdslight with GNU General Public License v2.0 | 6 votes |
def do_ssl_handshake(self): try: self.socket.do_handshake() self.__ssl_handshake_ok = True # 如果开启SNI那么匹配证书 if self.__enable_https_sni: cert = self.socket.getpeercert() ssl.match_hostname(cert, self.__https_sni_host) logging.print_general("TLS_handshake_ok", self.__server_address) self.add_evt_read(self.fileno) self.send_handshake() except ssl.SSLWantReadError: self.add_evt_read(self.fileno) except ssl.SSLWantWriteError: self.add_evt_write(self.fileno) except: logging.print_error() self.delete_handler(self.fileno)
Example #2
Source File: dump_ssl.py From untwisted with MIT License | 6 votes |
def process(self, spin): # When ssl.SSLEOFError happens it shouldnt spawn CLOSE # because there may exist data to be read. # If it spawns CLOSE the socket is closed and no data # can be read from. try: size = spin.send(self.data) except ssl.SSLWantReadError: spin.drive(SSL_SEND_ERR, spin, excpt) except ssl.SSLWantWriteError: spin.drive(SSL_SEND_ERR, spin, excpt) except ssl.SSLEOFError as excpt: pass except ssl.SSLError as excpt: spin.drive(CLOSE, excpt) except socket.error as excpt: self.process_error(spin, excpt) else: self.data = self.data[size:]
Example #3
Source File: client_ssl.py From untwisted with MIT License | 6 votes |
def do_handshake(self, spin): """ """ try: spin.do_handshake() except ssl.CertificateError as excpt: spin.drive(SSL_CERTIFICATE_ERR, excpt) except ssl.SSLWantReadError: pass except ssl.SSLWantWriteError: pass except socket.error as excpt: # When it happens then it should spawn SSL_CONNECT_ERR. spin.drive(SSL_CONNECT_ERR, excpt) except ssl.SSLError as excpt: spin.drive(SSL_CONNECT_ERR, excpt) else: spin.drive(SSL_CONNECT) raise Erase
Example #4
Source File: httpclient.py From fdslight with GNU General Public License v2.0 | 6 votes |
def __write(self): size = self.__writer.size() data = self.__writer._getvalue() try: sent_size = self.__socket.send(data) except BlockingIOError: self.__write_ok = False self.__writer.write(data) except ssl.SSLWantWriteError: return except (ConnectionError, ssl.SSLEOFError): raise HttpErr("the connection has been closed") if size == sent_size: self.__write_ok = True return bdata = data[sent_size:] self.__writer.write(bdata) self.__write_ok = False
Example #5
Source File: test_selector_events.py From annotated-py-projects with MIT License | 5 votes |
def test_on_handshake_writer_retry(self): self.loop.set_debug(False) self.sslsock.do_handshake.side_effect = ssl.SSLWantWriteError transport = self.ssl_transport() self.loop.assert_writer(1, transport._on_handshake, None)
Example #6
Source File: striptls.py From pub with GNU General Public License v2.0 | 5 votes |
def send(self, data, retransmit_delay=0.1): if self.socket_ssl: last_exception = None for _ in xrange(3): try: self.socket_ssl.write(data) last_exception = None break except ssl.SSLWantWriteError,swwe: logger.warning("TCPSockBuff: ssl.sock not yet ready, retransmit (%d) in %f seconds: %s"%(_,retransmit_delay,repr(swwe))) last_exception = swwe time.sleep(retransmit_delay) if last_exception: raise last_exception
Example #7
Source File: stdout_ssl.py From untwisted with MIT License | 5 votes |
def update(self, spin): try: while True: self.process_data(spin) except ssl.SSLWantReadError as excpt: spin.drive(SSL_RECV_ERR, spin, excpt) except ssl.SSLWantWriteError as excpt: spin.drive(SSL_RECV_ERR, spin, excpt) except ssl.SSLError as excpt: spin.drive(CLOSE, spin, excpt) except socket.error as excpt: self.process_error(spin, excpt)
Example #8
Source File: selector_events.py From annotated-py-projects with MIT License | 5 votes |
def _read_ready(self): if self._write_wants_read: self._write_wants_read = False self._write_ready() if self._buffer: self._loop.add_writer(self._sock_fd, self._write_ready) try: data = self._sock.recv(self.max_size) except (BlockingIOError, InterruptedError, ssl.SSLWantReadError): pass except ssl.SSLWantWriteError: self._read_wants_write = True self._loop.remove_reader(self._sock_fd) self._loop.add_writer(self._sock_fd, self._write_ready) except Exception as exc: self._fatal_error(exc, 'Fatal read error on SSL transport') else: if data: self._protocol.data_received(data) else: try: if self._loop.get_debug(): logger.debug("%r received EOF", self) keep_open = self._protocol.eof_received() if keep_open: logger.warning('returning true from eof_received() ' 'has no effect when using ssl') finally: self.close()
Example #9
Source File: selector_events.py From annotated-py-projects with MIT License | 5 votes |
def _write_ready(self): if self._read_wants_write: self._read_wants_write = False self._read_ready() if not (self._paused or self._closing): self._loop.add_reader(self._sock_fd, self._read_ready) if self._buffer: try: n = self._sock.send(self._buffer) except (BlockingIOError, InterruptedError, ssl.SSLWantWriteError): n = 0 except ssl.SSLWantReadError: n = 0 self._loop.remove_writer(self._sock_fd) self._write_wants_read = True except Exception as exc: self._loop.remove_writer(self._sock_fd) self._buffer.clear() self._fatal_error(exc, 'Fatal write error on SSL transport') return if n: del self._buffer[:n] self._maybe_resume_protocol() # May append to buffer. if not self._buffer: self._loop.remove_writer(self._sock_fd) if self._closing: self._call_connection_lost(None)
Example #10
Source File: ssl_socket.py From fluxclient with GNU Affero General Public License v3.0 | 5 votes |
def do_handshake(self): try: super(SSLSocket, self).do_handshake() except ssl.SSLWantReadError: return 1 except ssl.SSLWantWriteError: return 2 return self._do_flux_handshake()
Example #11
Source File: test_selector_events.py From annotated-py-projects with MIT License | 5 votes |
def test_read_ready_recv_write(self): self.loop.remove_reader = mock.Mock() self.loop.add_writer = mock.Mock() self.sslsock.recv.side_effect = ssl.SSLWantWriteError transport = self._make_one() transport._read_ready() self.assertFalse(self.protocol.data_received.called) self.assertTrue(transport._read_wants_write) self.loop.remove_reader.assert_called_with(transport._sock_fd) self.loop.add_writer.assert_called_with( transport._sock_fd, transport._write_ready)
Example #12
Source File: selector_events.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
def _read_ready(self): if self._conn_lost: return if self._write_wants_read: self._write_wants_read = False self._write_ready() if self._buffer: self._loop._add_writer(self._sock_fd, self._write_ready) try: data = self._sock.recv(self.max_size) except (BlockingIOError, InterruptedError, ssl.SSLWantReadError): pass except ssl.SSLWantWriteError: self._read_wants_write = True self._loop._remove_reader(self._sock_fd) self._loop._add_writer(self._sock_fd, self._write_ready) except Exception as exc: self._fatal_error(exc, 'Fatal read error on SSL transport') else: if data: self._protocol.data_received(data) else: try: if self._loop.get_debug(): logger.debug("%r received EOF", self) keep_open = self._protocol.eof_received() if keep_open: logger.warning('returning true from eof_received() ' 'has no effect when using ssl') finally: self.close()
Example #13
Source File: selector_events.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
def _write_ready(self): if self._conn_lost: return if self._read_wants_write: self._read_wants_write = False self._read_ready() if not (self._paused or self._closing): self._loop._add_reader(self._sock_fd, self._read_ready) if self._buffer: try: n = self._sock.send(self._buffer) except (BlockingIOError, InterruptedError, ssl.SSLWantWriteError): n = 0 except ssl.SSLWantReadError: n = 0 self._loop._remove_writer(self._sock_fd) self._write_wants_read = True except Exception as exc: self._loop._remove_writer(self._sock_fd) self._buffer.clear() self._fatal_error(exc, 'Fatal write error on SSL transport') return if n: del self._buffer[:n] self._maybe_resume_protocol() # May append to buffer. if not self._buffer: self._loop._remove_writer(self._sock_fd) if self._closing: self._call_connection_lost(None)
Example #14
Source File: test_selector_events.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
def test_on_handshake_writer_retry(self): self.loop.set_debug(False) self.sslsock.do_handshake.side_effect = ssl.SSLWantWriteError transport = self.ssl_transport() self.loop.assert_writer(1, transport._on_handshake, None)
Example #15
Source File: test_selector_events.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
def test_read_ready_recv_write(self): self.loop._remove_reader = mock.Mock() self.loop._add_writer = mock.Mock() self.sslsock.recv.side_effect = ssl.SSLWantWriteError transport = self._make_one() transport._read_ready() self.assertFalse(self.protocol.data_received.called) self.assertTrue(transport._read_wants_write) self.loop._remove_reader.assert_called_with(transport._sock_fd) self.loop._add_writer.assert_called_with( transport._sock_fd, transport._write_ready)
Example #16
Source File: test_selector_events.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
def test_write_ready_send_retry(self): transport = self._make_one() transport._buffer = list_to_buffer([b'data']) self.sslsock.send.side_effect = ssl.SSLWantWriteError transport._write_ready() self.assertEqual(list_to_buffer([b'data']), transport._buffer) self.sslsock.send.side_effect = BlockingIOError() transport._write_ready() self.assertEqual(list_to_buffer([b'data']), transport._buffer)
Example #17
Source File: striptls.py From striptls with Creative Commons Zero v1.0 Universal | 5 votes |
def send(self, data, retransmit_delay=0.1): if self.socket_ssl: last_exception = None for _ in xrange(3): try: self.socket_ssl.write(data) last_exception = None break except ssl.SSLWantWriteError,swwe: logger.warning("TCPSockBuff: ssl.sock not yet ready, retransmit (%d) in %f seconds: %s"%(_,retransmit_delay,repr(swwe))) last_exception = swwe time.sleep(retransmit_delay) if last_exception: raise last_exception
Example #18
Source File: tunnelc.py From fdslight with GNU General Public License v2.0 | 5 votes |
def evt_read(self): if not self.is_conn_ok(): super().evt_read() return if not self.__over_https: super().evt_read() return if not self.__ssl_handshake_ok: self.do_ssl_handshake() if not self.__ssl_handshake_ok: return try: super().evt_read() except ssl.SSLWantWriteError: self.add_evt_write(self.fileno) except ssl.SSLWantReadError: if self.reader.size() > 0: self.tcp_readable() except ssl.SSLZeroReturnError: if self.reader.size() > 0: self.tcp_readable() if self.handler_exists(self.fileno): self.delete_handler(self.fileno) except ssl.SSLError: self.delete_handler(self.fileno)
Example #19
Source File: ssl_handler.py From fdslight with GNU General Public License v2.0 | 5 votes |
def __do_ssl_handshake(self): try: self.socket.do_handshake() self.__ssl_handshake_ok = True self.ssl_handshake_ok() except ssl.SSLWantReadError: self.add_evt_read(self.fileno) except ssl.SSLWantWriteError: self.add_evt_write(self.fileno) except: self.delete_handler(self.fileno)
Example #20
Source File: ssl_handler.py From fdslight with GNU General Public License v2.0 | 5 votes |
def evt_write(self): if self.__server_side: if not self.__ssl_on: super().evt_write() return '''''' else: if not self.is_conn_ok(): super().evt_write() return '''''' if not self.__ssl_handshake_ok: self.remove_evt_write(self.fileno) self.__do_ssl_handshake() if not self.__ssl_handshake_ok: return try: super().evt_write() except ssl.SSLWantReadError: pass except ssl.SSLWantWriteError: self.add_evt_write(self.fileno) except ssl.SSLEOFError: self.delete_handler(self.fileno) except ssl.SSLError: self.delete_handler(self.fileno)
Example #21
Source File: ssl_handler.py From fdslight with GNU General Public License v2.0 | 5 votes |
def evt_read(self): if self.__server_side: if not self.__ssl_on: super().evt_read() return '''''' else: if not self.is_conn_ok(): super().evt_read() return '''''' if not self.__ssl_handshake_ok: self.__do_ssl_handshake() if not self.__ssl_handshake_ok: return try: super().evt_read() except ssl.SSLWantWriteError: self.add_evt_write(self.fileno) except ssl.SSLWantReadError: if self.reader.size() > 0: self.tcp_readable() except ssl.SSLZeroReturnError: if self.reader.size() > 0: self.tcp_readable() if self.handler_exists(self.fileno): self.delete_handler(self.fileno)
Example #22
Source File: test_selector_events.py From ironpython3 with Apache License 2.0 | 5 votes |
def test_write_ready_send_retry(self): transport = self._make_one() transport._buffer = list_to_buffer([b'data']) self.sslsock.send.side_effect = ssl.SSLWantWriteError transport._write_ready() self.assertEqual(list_to_buffer([b'data']), transport._buffer) self.sslsock.send.side_effect = BlockingIOError() transport._write_ready() self.assertEqual(list_to_buffer([b'data']), transport._buffer)
Example #23
Source File: test_selector_events.py From ironpython3 with Apache License 2.0 | 5 votes |
def test_read_ready_recv_write(self): self.loop.remove_reader = mock.Mock() self.loop.add_writer = mock.Mock() self.sslsock.recv.side_effect = ssl.SSLWantWriteError transport = self._make_one() transport._read_ready() self.assertFalse(self.protocol.data_received.called) self.assertTrue(transport._read_wants_write) self.loop.remove_reader.assert_called_with(transport._sock_fd) self.loop.add_writer.assert_called_with( transport._sock_fd, transport._write_ready)
Example #24
Source File: test_selector_events.py From ironpython3 with Apache License 2.0 | 5 votes |
def test_on_handshake_writer_retry(self): self.loop.set_debug(False) self.sslsock.do_handshake.side_effect = ssl.SSLWantWriteError transport = self.ssl_transport() self.loop.assert_writer(1, transport._on_handshake, None)
Example #25
Source File: selector_events.py From ironpython3 with Apache License 2.0 | 5 votes |
def _write_ready(self): if self._read_wants_write: self._read_wants_write = False self._read_ready() if not (self._paused or self._closing): self._loop.add_reader(self._sock_fd, self._read_ready) if self._buffer: try: n = self._sock.send(self._buffer) except (BlockingIOError, InterruptedError, ssl.SSLWantWriteError): n = 0 except ssl.SSLWantReadError: n = 0 self._loop.remove_writer(self._sock_fd) self._write_wants_read = True except Exception as exc: self._loop.remove_writer(self._sock_fd) self._buffer.clear() self._fatal_error(exc, 'Fatal write error on SSL transport') return if n: del self._buffer[:n] self._maybe_resume_protocol() # May append to buffer. if not self._buffer: self._loop.remove_writer(self._sock_fd) if self._closing: self._call_connection_lost(None)
Example #26
Source File: selector_events.py From ironpython3 with Apache License 2.0 | 5 votes |
def _read_ready(self): if self._write_wants_read: self._write_wants_read = False self._write_ready() if self._buffer: self._loop.add_writer(self._sock_fd, self._write_ready) try: data = self._sock.recv(self.max_size) except (BlockingIOError, InterruptedError, ssl.SSLWantReadError): pass except ssl.SSLWantWriteError: self._read_wants_write = True self._loop.remove_reader(self._sock_fd) self._loop.add_writer(self._sock_fd, self._write_ready) except Exception as exc: self._fatal_error(exc, 'Fatal read error on SSL transport') else: if data: self._protocol.data_received(data) else: try: if self._loop.get_debug(): logger.debug("%r received EOF", self) keep_open = self._protocol.eof_received() if keep_open: logger.warning('returning true from eof_received() ' 'has no effect when using ssl') finally: self.close()
Example #27
Source File: test_selector_events.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def test_write_ready_send_retry(self): transport = self._make_one() transport._buffer = list_to_buffer([b'data']) self.sslsock.send.side_effect = ssl.SSLWantWriteError transport._write_ready() self.assertEqual(list_to_buffer([b'data']), transport._buffer) self.sslsock.send.side_effect = BlockingIOError() transport._write_ready() self.assertEqual(list_to_buffer([b'data']), transport._buffer)
Example #28
Source File: test_selector_events.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def test_read_ready_recv_write(self): self.loop.remove_reader = mock.Mock() self.loop.add_writer = mock.Mock() self.sslsock.recv.side_effect = ssl.SSLWantWriteError transport = self._make_one() transport._read_ready() self.assertFalse(self.protocol.data_received.called) self.assertTrue(transport._read_wants_write) self.loop.remove_reader.assert_called_with(transport._sock_fd) self.loop.add_writer.assert_called_with( transport._sock_fd, transport._write_ready)
Example #29
Source File: test_selector_events.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def test_on_handshake_writer_retry(self): self.loop.set_debug(False) self.sslsock.do_handshake.side_effect = ssl.SSLWantWriteError transport = self.ssl_transport() self.loop.assert_writer(1, transport._on_handshake, None)
Example #30
Source File: selector_events.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def _write_ready(self): if self._read_wants_write: self._read_wants_write = False self._read_ready() if not (self._paused or self._closing): self._loop.add_reader(self._sock_fd, self._read_ready) if self._buffer: try: n = self._sock.send(self._buffer) except (BlockingIOError, InterruptedError, ssl.SSLWantWriteError): n = 0 except ssl.SSLWantReadError: n = 0 self._loop.remove_writer(self._sock_fd) self._write_wants_read = True except Exception as exc: self._loop.remove_writer(self._sock_fd) self._buffer.clear() self._fatal_error(exc, 'Fatal write error on SSL transport') return if n: del self._buffer[:n] self._maybe_resume_protocol() # May append to buffer. if not self._buffer: self._loop.remove_writer(self._sock_fd) if self._closing: self._call_connection_lost(None)