当前位置: 首页>>代码示例>>Python>>正文


Python ssl.SSL_ERROR_WANT_WRITE属性代码示例

本文整理汇总了Python中ssl.SSL_ERROR_WANT_WRITE属性的典型用法代码示例。如果您正苦于以下问题:Python ssl.SSL_ERROR_WANT_WRITE属性的具体用法?Python ssl.SSL_ERROR_WANT_WRITE怎么用?Python ssl.SSL_ERROR_WANT_WRITE使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在ssl的用法示例。


在下文中一共展示了ssl.SSL_ERROR_WANT_WRITE属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _doSSLHandshake

# 需要导入模块: import ssl [as 别名]
# 或者: from ssl import SSL_ERROR_WANT_WRITE [as 别名]
def _doSSLHandshake(self) :
        count = 0
        while count < 10 :
            try :
                self._socket.do_handshake()
                break
            except ssl.SSLError as sslErr :
                count += 1
                if sslErr.args[0] == ssl.SSL_ERROR_WANT_READ :
                    select([self._socket], [], [], 1)
                elif sslErr.args[0] == ssl.SSL_ERROR_WANT_WRITE :
                    select([], [self._socket], [], 1)
                else :
                    raise XAsyncTCPClientException('SSL : Bad handshake : %s' % sslErr)
            except Exception as ex :
                raise XAsyncTCPClientException('SSL : Handshake error : %s' % ex)

    # ------------------------------------------------------------------------ 
开发者ID:jczic,项目名称:MicroWebSrv2,代码行数:20,代码来源:XAsyncSockets.py

示例2: _do_ssl_shutdown

# 需要导入模块: import ssl [as 别名]
# 或者: from ssl import SSL_ERROR_WANT_WRITE [as 别名]
def _do_ssl_shutdown(self):
            self._ssl_closing = True
            try:
                self.socket = self.socket.unwrap()
            except ssl.SSLError as err:
                if err.args[0] in (ssl.SSL_ERROR_WANT_READ,
                                   ssl.SSL_ERROR_WANT_WRITE):
                    return
            except socket.error as err:
                # Any "socket error" corresponds to a SSL_ERROR_SYSCALL return
                # from OpenSSL's SSL_shutdown(), corresponding to a
                # closed socket condition. See also:
                # http://www.mail-archive.com/openssl-users@openssl.org/msg60710.html
                pass
            self._ssl_closing = False
            if getattr(self, '_ccc', False) is False:
                super(SSLConnection, self).close()
            else:
                pass 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:21,代码来源:test_ftplib.py

示例3: write_to_fd

# 需要导入模块: import ssl [as 别名]
# 或者: from ssl import SSL_ERROR_WANT_WRITE [as 别名]
def write_to_fd(self, data: memoryview) -> int:
        try:
            return self.socket.send(data)  # type: ignore
        except ssl.SSLError as e:
            if e.args[0] == ssl.SSL_ERROR_WANT_WRITE:
                # In Python 3.5+, SSLSocket.send raises a WANT_WRITE error if
                # the socket is not writeable; we need to transform this into
                # an EWOULDBLOCK socket.error or a zero return value,
                # either of which will be recognized by the caller of this
                # method. Prior to Python 3.5, an unwriteable socket would
                # simply return 0 bytes written.
                return 0
            raise
        finally:
            # Avoid keeping to data, which can be a memoryview.
            # See https://github.com/tornadoweb/tornado/pull/2008
            del data 
开发者ID:opendevops-cn,项目名称:opendevops,代码行数:19,代码来源:iostream.py

示例4: write_to_fd

# 需要导入模块: import ssl [as 别名]
# 或者: from ssl import SSL_ERROR_WANT_WRITE [as 别名]
def write_to_fd(self, data):
        try:
            return self.socket.send(data)
        except ssl.SSLError as e:
            if e.args[0] == ssl.SSL_ERROR_WANT_WRITE:
                # In Python 3.5+, SSLSocket.send raises a WANT_WRITE error if
                # the socket is not writeable; we need to transform this into
                # an EWOULDBLOCK socket.error or a zero return value,
                # either of which will be recognized by the caller of this
                # method. Prior to Python 3.5, an unwriteable socket would
                # simply return 0 bytes written.
                return 0
            raise
        finally:
            # Avoid keeping to data, which can be a memoryview.
            # See https://github.com/tornadoweb/tornado/pull/2008
            del data 
开发者ID:tp4a,项目名称:teleport,代码行数:19,代码来源:iostream.py

示例5: _do_ssl_shutdown

# 需要导入模块: import ssl [as 别名]
# 或者: from ssl import SSL_ERROR_WANT_WRITE [as 别名]
def _do_ssl_shutdown(self):
            self._ssl_closing = True
            try:
                self.socket = self.socket.unwrap()
            except ssl.SSLError as err:
                if err.args[0] in (ssl.SSL_ERROR_WANT_READ,
                                   ssl.SSL_ERROR_WANT_WRITE):
                    return
            except OSError as err:
                # Any "socket error" corresponds to a SSL_ERROR_SYSCALL return
                # from OpenSSL's SSL_shutdown(), corresponding to a
                # closed socket condition. See also:
                # http://www.mail-archive.com/openssl-users@openssl.org/msg60710.html
                pass
            self._ssl_closing = False
            if getattr(self, '_ccc', False) is False:
                super(SSLConnection, self).close()
            else:
                pass 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:21,代码来源:test_ftplib.py

示例6: _send_discovery_request

# 需要导入模块: import ssl [as 别名]
# 或者: from ssl import SSL_ERROR_WANT_WRITE [as 别名]
def _send_discovery_request(self, ssl_sock, thing_name):
        request = self.REQUEST_TYPE_PREFIX + \
                  self.PAYLOAD_PREFIX + \
                  thing_name + \
                  self.PAYLOAD_SUFFIX + \
                  self.HOST_PREFIX + \
                  self._host + ":" + str(self._port) + \
                  self.HOST_SUFFIX
        self._logger.debug("Sending discover request: " + request)

        start_time = time.time()
        desired_length_to_write = len(request)
        actual_length_written = 0
        while True:
            try:
                length_written = ssl_sock.write(request.encode("utf-8"))
                actual_length_written += length_written
            except socket.error as err:
                if err.errno == ssl.SSL_ERROR_WANT_READ or err.errno == ssl.SSL_ERROR_WANT_WRITE:
                    pass
            if actual_length_written == desired_length_to_write:
                return self.LOW_LEVEL_RC_COMPLETE
            if start_time + self._timeout_sec < time.time():
                return self.LOW_LEVEL_RC_TIMEOUT 
开发者ID:aws,项目名称:aws-iot-device-sdk-python,代码行数:26,代码来源:providers.py

示例7: _receive_until

# 需要导入模块: import ssl [as 别名]
# 或者: from ssl import SSL_ERROR_WANT_WRITE [as 别名]
def _receive_until(self, ssl_sock, criteria_function, extra_data=None):
        start_time = time.time()
        response = bytearray()
        number_bytes_read = 0
        while True:  # Python does not have do-while
            try:
                response.append(self._convert_to_int_py3(ssl_sock.read(1)))
                number_bytes_read += 1
            except socket.error as err:
                if err.errno == ssl.SSL_ERROR_WANT_READ or err.errno == ssl.SSL_ERROR_WANT_WRITE:
                    pass

            if criteria_function((number_bytes_read, response, extra_data)):
                return self.LOW_LEVEL_RC_COMPLETE, response
            if start_time + self._timeout_sec < time.time():
                return self.LOW_LEVEL_RC_TIMEOUT, response 
开发者ID:aws,项目名称:aws-iot-device-sdk-python,代码行数:18,代码来源:providers.py

示例8: _hasCredentialsNecessaryForWebsocket

# 需要导入模块: import ssl [as 别名]
# 或者: from ssl import SSL_ERROR_WANT_WRITE [as 别名]
def _hasCredentialsNecessaryForWebsocket(self, allKeys):
        awsAccessKeyIdCandidate = allKeys.get("aws_access_key_id")
        awsSecretAccessKeyCandidate = allKeys.get("aws_secret_access_key")
        # None value is NOT considered as valid entries
        validEntries = awsAccessKeyIdCandidate is not None and awsAccessKeyIdCandidate is not None
        if validEntries:
            # Empty value is NOT considered as valid entries
            validEntries &= (len(awsAccessKeyIdCandidate) != 0 and len(awsSecretAccessKeyCandidate) != 0)
        return validEntries


# This is an internal class that buffers the incoming bytes into an
# internal buffer until it gets the full desired length of bytes.
# At that time, this bufferedReader will be reset.
# *Error handling:
# For retry errors (ssl.SSL_ERROR_WANT_READ, ssl.SSL_ERROR_WANT_WRITE, EAGAIN),
# leave them to the paho _packet_read for further handling (ignored and try
# again when data is available.
# For other errors, leave them to the paho _packet_read for error reporting. 
开发者ID:aws,项目名称:aws-iot-device-sdk-python,代码行数:21,代码来源:cores.py

示例9: send

# 需要导入模块: import ssl [as 别名]
# 或者: from ssl import SSL_ERROR_WANT_WRITE [as 别名]
def send(self, data):
        """
        If data is ``None`` then ``self.write_buf`` is used.
        """
        if (data is not None) and not self.send_finished:
            raise SendNotFinished(("previous send on %r is not finished, " +
                              "wait for on_ready_to_send") % self)

        data = data or self.write_buf

        self.send_finished = False
        if self.ssl_config is None:
            self.last_send_size = self.sock.send(data)
        else:
            try:
                self.last_send_size = self.sock.write(data)
                self.write_buf = None
            except ssl.SSLError as exc:
                if exc.args[0] != ssl.SSL_ERROR_WANT_WRITE:
                    raise
                self.write_buf = data

    ######################################################### 
开发者ID:blackye,项目名称:luscan-devel,代码行数:25,代码来源:link.py

示例10: _continue_tls_handshake

# 需要导入模块: import ssl [as 别名]
# 或者: from ssl import SSL_ERROR_WANT_WRITE [as 别名]
def _continue_tls_handshake(self):
        """Continue a TLS handshake."""
        try:
            logger.debug(" do_handshake()")
            self._socket.do_handshake()
        except ssl.SSLError as err:
            if err.args[0] == ssl.SSL_ERROR_WANT_READ:
                self._tls_state = "want_read"
                logger.debug("   want_read")
                self._state_cond.notify()
                return
            elif err.args[0] == ssl.SSL_ERROR_WANT_WRITE:
                self._tls_state = "want_write"
                logger.debug("   want_write")
                self._write_queue.appendleft(TLSHandshake)
                return
            else:
                raise
        self._tls_state = "connected"
        self._set_state("connected")
        self.event(TLSConnectedEvent(self._socket.cipher(),
                                                self._socket.getpeercert())) 
开发者ID:kuri65536,项目名称:python-for-android,代码行数:24,代码来源:transport.py

示例11: wrap_socket

# 需要导入模块: import ssl [as 别名]
# 或者: from ssl import SSL_ERROR_WANT_WRITE [as 别名]
def wrap_socket(cls, socket):
        sock = ssl.wrap_socket(socket, ssl_version=ssl.PROTOCOL_TLSv1)
        while True:
            try:
                logger.info('Performing TLS handshade...')
                sock.do_handshake()
                break
            except ssl.SSLError as err:
                errs = (
                    ssl.SSL_ERROR_WANT_READ,
                    ssl.SSL_ERROR_WANT_WRITE)
                if err.args[0] not in (errs):
                    raise
                else:
                    logger.info('Continuing TLS handshake...')
        logger.info('Socket wrapped')
        return sock 
开发者ID:dlecocq,项目名称:nsq-py,代码行数:19,代码来源:tls.py

示例12: test_flush_would_block_ssl_write_buffer

# 需要导入模块: import ssl [as 别名]
# 或者: from ssl import SSL_ERROR_WANT_WRITE [as 别名]
def test_flush_would_block_ssl_write_buffer(self):
        '''ssl.SSL_ERROR_WANT_WRITE usesthe same buffer on next send'''
        pending = deque([b'1', b'2', b'3'])
        with mock.patch.object(self.connection, '_pending', pending):
            with mock.patch.object(self.connection, '_socket') as mock_socket:
                mock_socket.send.side_effect = ssl.SSLError(
                    ssl.SSL_ERROR_WANT_WRITE)
                self.assertFalse(self.connection._out_buffer)
                self.connection.flush()
                self.assertEqual(self.connection._out_buffer, b'123')

        # With some more pending items, make sure we still only get '123' sent
        pending = deque([b'4', b'5', b'6'])
        with mock.patch.object(self.connection, '_pending', pending):
            with mock.patch.object(self.connection, '_socket') as mock_socket:
                mock_socket.send.return_value = 3
                # The first flush should see the existing buffer
                self.connection.flush()
                mock_socket.send.assert_called_with(b'123')
                # The second flush should see the pending requests
                self.connection.flush()
                mock_socket.send.assert_called_with(b'456') 
开发者ID:dlecocq,项目名称:nsq-py,代码行数:24,代码来源:test_connection.py

示例13: write_to_fd

# 需要导入模块: import ssl [as 别名]
# 或者: from ssl import SSL_ERROR_WANT_WRITE [as 别名]
def write_to_fd(self, data):
        try:
            return self.socket.send(data)
        except ssl.SSLError as e:
            if e.args[0] == ssl.SSL_ERROR_WANT_WRITE:
                # In Python 3.5+, SSLSocket.send raises a WANT_WRITE error if
                # the socket is not writeable; we need to transform this into
                # an EWOULDBLOCK socket.error or a zero return value,
                # either of which will be recognized by the caller of this
                # method. Prior to Python 3.5, an unwriteable socket would
                # simply return 0 bytes written.
                return 0
            raise 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:15,代码来源:iostream.py

示例14: _do_ssl_handshake

# 需要导入模块: import ssl [as 别名]
# 或者: from ssl import SSL_ERROR_WANT_WRITE [as 别名]
def _do_ssl_handshake(self):
            try:
                self.socket.do_handshake()
            except ssl.SSLError as err:
                if err.args[0] in (ssl.SSL_ERROR_WANT_READ,
                                   ssl.SSL_ERROR_WANT_WRITE):
                    return
                elif err.args[0] == ssl.SSL_ERROR_EOF:
                    return self.handle_close()
                raise
            except socket.error as err:
                if err.args[0] == errno.ECONNABORTED:
                    return self.handle_close()
            else:
                self._ssl_accepting = False 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:17,代码来源:test_ftplib.py

示例15: send

# 需要导入模块: import ssl [as 别名]
# 或者: from ssl import SSL_ERROR_WANT_WRITE [as 别名]
def send(self, data):
            try:
                return super(SSLConnection, self).send(data)
            except ssl.SSLError as err:
                if err.args[0] in (ssl.SSL_ERROR_EOF, ssl.SSL_ERROR_ZERO_RETURN,
                                   ssl.SSL_ERROR_WANT_READ,
                                   ssl.SSL_ERROR_WANT_WRITE):
                    return 0
                raise 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:11,代码来源:test_ftplib.py


注:本文中的ssl.SSL_ERROR_WANT_WRITE属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。