當前位置: 首頁>>代碼示例>>Python>>正文


Python ssl.SSLWantWriteError方法代碼示例

本文整理匯總了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 
開發者ID:fdslight,項目名稱:fdslight,代碼行數:25,代碼來源:httpclient.py

示例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) 
開發者ID:fdslight,項目名稱:fdslight,代碼行數:22,代碼來源:tunnelc.py

示例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:] 
開發者ID:untwisted,項目名稱:untwisted,代碼行數:21,代碼來源:dump_ssl.py

示例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 
開發者ID:untwisted,項目名稱:untwisted,代碼行數:22,代碼來源:client_ssl.py

示例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 
開發者ID:tintinweb,項目名稱:striptls,代碼行數:16,代碼來源:striptls.py

示例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() 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:33,代碼來源:selector_events.py

示例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) 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:34,代碼來源:selector_events.py

示例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) 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:7,代碼來源:test_selector_events.py

示例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) 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:14,代碼來源:test_selector_events.py

示例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) 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:13,代碼來源:test_selector_events.py

示例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) 
開發者ID:fdslight,項目名稱:fdslight,代碼行數:30,代碼來源:ssl_handler.py

示例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) 
開發者ID:fdslight,項目名稱:fdslight,代碼行數:29,代碼來源:ssl_handler.py

示例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) 
開發者ID:fdslight,項目名稱:fdslight,代碼行數:13,代碼來源:ssl_handler.py

示例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) 
開發者ID:fdslight,項目名稱:fdslight,代碼行數:29,代碼來源:tunnelc.py

示例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) 
開發者ID:untwisted,項目名稱:untwisted,代碼行數:14,代碼來源:stdout_ssl.py


注:本文中的ssl.SSLWantWriteError方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。