本文整理汇总了Python中ssl.SSLWantWriteError方法的典型用法代码示例。如果您正苦于以下问题:Python ssl.SSLWantWriteError方法的具体用法?Python ssl.SSLWantWriteError怎么用?Python ssl.SSLWantWriteError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ssl
的用法示例。
在下文中一共展示了ssl.SSLWantWriteError方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __write
# 需要导入模块: import ssl [as 别名]
# 或者: from ssl import SSLWantWriteError [as 别名]
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
示例2: do_ssl_handshake
# 需要导入模块: import ssl [as 别名]
# 或者: from ssl import SSLWantWriteError [as 别名]
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)
示例3: process
# 需要导入模块: import ssl [as 别名]
# 或者: from ssl import SSLWantWriteError [as 别名]
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:]
示例4: do_handshake
# 需要导入模块: import ssl [as 别名]
# 或者: from ssl import SSLWantWriteError [as 别名]
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
示例5: send
# 需要导入模块: import ssl [as 别名]
# 或者: from ssl import SSLWantWriteError [as 别名]
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
示例6: _read_ready
# 需要导入模块: import ssl [as 别名]
# 或者: from ssl import SSLWantWriteError [as 别名]
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()
示例7: _write_ready
# 需要导入模块: import ssl [as 别名]
# 或者: from ssl import SSLWantWriteError [as 别名]
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)
示例8: test_on_handshake_writer_retry
# 需要导入模块: import ssl [as 别名]
# 或者: from ssl import SSLWantWriteError [as 别名]
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)
示例9: test_read_ready_recv_write
# 需要导入模块: import ssl [as 别名]
# 或者: from ssl import SSLWantWriteError [as 别名]
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)
示例10: test_write_ready_send_retry
# 需要导入模块: import ssl [as 别名]
# 或者: from ssl import SSLWantWriteError [as 别名]
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)
示例11: evt_read
# 需要导入模块: import ssl [as 别名]
# 或者: from ssl import SSLWantWriteError [as 别名]
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)
示例12: evt_write
# 需要导入模块: import ssl [as 别名]
# 或者: from ssl import SSLWantWriteError [as 别名]
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)
示例13: __do_ssl_handshake
# 需要导入模块: import ssl [as 别名]
# 或者: from ssl import SSLWantWriteError [as 别名]
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)
示例14: evt_read
# 需要导入模块: import ssl [as 别名]
# 或者: from ssl import SSLWantWriteError [as 别名]
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)
示例15: update
# 需要导入模块: import ssl [as 别名]
# 或者: from ssl import SSLWantWriteError [as 别名]
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)