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


Python ssl.SSL_ERROR_WANT_READ属性代码示例

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


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

示例1: _doSSLHandshake

# 需要导入模块: import ssl [as 别名]
# 或者: from ssl import SSL_ERROR_WANT_READ [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_READ [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: read_from_fd

# 需要导入模块: import ssl [as 别名]
# 或者: from ssl import SSL_ERROR_WANT_READ [as 别名]
def read_from_fd(self, buf: Union[bytearray, memoryview]) -> Optional[int]:
        try:
            if self._ssl_accepting:
                # If the handshake hasn't finished yet, there can't be anything
                # to read (attempting to read may or may not raise an exception
                # depending on the SSL version)
                return None
            try:
                return self.socket.recv_into(buf, len(buf))
            except ssl.SSLError as e:
                # SSLError is a subclass of socket.error, so this except
                # block must come first.
                if e.args[0] == ssl.SSL_ERROR_WANT_READ:
                    return None
                else:
                    raise
            except socket.error as e:
                if e.args[0] in _ERRNO_WOULDBLOCK:
                    return None
                else:
                    raise
        finally:
            del buf 
开发者ID:opendevops-cn,项目名称:opendevops,代码行数:25,代码来源:iostream.py

示例4: read_from_fd

# 需要导入模块: import ssl [as 别名]
# 或者: from ssl import SSL_ERROR_WANT_READ [as 别名]
def read_from_fd(self, buf):
        try:
            if self._ssl_accepting:
                # If the handshake hasn't finished yet, there can't be anything
                # to read (attempting to read may or may not raise an exception
                # depending on the SSL version)
                return None
            try:
                return self.socket.recv_into(buf)
            except ssl.SSLError as e:
                # SSLError is a subclass of socket.error, so this except
                # block must come first.
                if e.args[0] == ssl.SSL_ERROR_WANT_READ:
                    return None
                else:
                    raise
            except socket.error as e:
                if e.args[0] in _ERRNO_WOULDBLOCK:
                    return None
                else:
                    raise
        finally:
            buf = None 
开发者ID:tp4a,项目名称:teleport,代码行数:25,代码来源:iostream.py

示例5: readIntoBufferNonblock

# 需要导入模块: import ssl [as 别名]
# 或者: from ssl import SSL_ERROR_WANT_READ [as 别名]
def readIntoBufferNonblock(sock, buff):
    read = 0
    while True:
        try:
            msg = sock.recv(4096)
            if len(msg):
                read += len(msg)
                buff.append(msg)
            else:
                raise SocketClosed('socket was closed remotely')
                # returning '' is basically the same as a EAGAIN
                return read
        except ssl.SSLError as e:
            if e.errno == ssl.SSL_ERROR_WANT_READ:
                return read
            raise e
        except socket.error as e:
            if e.errno in (errno.EWOULDBLOCK, errno.EAGAIN):
                return read
            raise e 
开发者ID:ufora,项目名称:ufora,代码行数:22,代码来源:common.py

示例6: readable

# 需要导入模块: import ssl [as 别名]
# 或者: from ssl import SSL_ERROR_WANT_READ [as 别名]
def readable(self, client):
        """
        Callback when the socket is readable. If we need to do the TLS handshake, it will
        start that, otherwise it will attempt to read data from the socket. If we need more
        data to decrypt the data, it will save and continue.

        See core.TCPClient.readable() for more information.
        """
        if not self.handshook:
            self.do_handshake()

        if not self.handshook:
            return

        try:
            super(TLSClient, self).readable(client)
        except ssl.SSLError as err:
            if err.args[0] != ssl.SSL_ERROR_WANT_READ:
                self.die()
        except socket.error as e:
            print(traceback.print_exc(e))
            log.error('socket error: %s' % e)
            self.die() 
开发者ID:pycepa,项目名称:pycepa,代码行数:25,代码来源:TLSClient.py

示例7: do_handshake

# 需要导入模块: import ssl [as 别名]
# 或者: from ssl import SSL_ERROR_WANT_READ [as 别名]
def do_handshake(self):
        """
        Does the TLS handshake on a fresh connection.
        
        Local events raised:
            * handshook - indicates that the TLS handshake has completed and the socket
                          is ready for use.
        """
        try:
            self.sock.do_handshake()
            self.handshook = True
            self.trigger_local('handshook')
        except ssl.SSLError as err:
            if err.args[0] != ssl.SSL_ERROR_WANT_READ:
                self.die()
        except socket.error:
            self.die() 
开发者ID:pycepa,项目名称:pycepa,代码行数:19,代码来源:TLSClient.py

示例8: _do_ssl_shutdown

# 需要导入模块: import ssl [as 别名]
# 或者: from ssl import SSL_ERROR_WANT_READ [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

示例9: _send_discovery_request

# 需要导入模块: import ssl [as 别名]
# 或者: from ssl import SSL_ERROR_WANT_READ [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

示例10: _receive_until

# 需要导入模块: import ssl [as 别名]
# 或者: from ssl import SSL_ERROR_WANT_READ [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

示例11: _hasCredentialsNecessaryForWebsocket

# 需要导入模块: import ssl [as 别名]
# 或者: from ssl import SSL_ERROR_WANT_READ [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

示例12: _continue_tls_handshake

# 需要导入模块: import ssl [as 别名]
# 或者: from ssl import SSL_ERROR_WANT_READ [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

示例13: wrap_socket

# 需要导入模块: import ssl [as 别名]
# 或者: from ssl import SSL_ERROR_WANT_READ [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

示例14: read_from_fd

# 需要导入模块: import ssl [as 别名]
# 或者: from ssl import SSL_ERROR_WANT_READ [as 别名]
def read_from_fd(self):
        if self._ssl_accepting:
            # If the handshake hasn't finished yet, there can't be anything
            # to read (attempting to read may or may not raise an exception
            # depending on the SSL version)
            return None
        try:
            # SSLSocket objects have both a read() and recv() method,
            # while regular sockets only have recv().
            # The recv() method blocks (at least in python 2.6) if it is
            # called when there is nothing to read, so we have to use
            # read() instead.
            chunk = self.socket.read(self.read_chunk_size)
        except ssl.SSLError as e:
            # SSLError is a subclass of socket.error, so this except
            # block must come first.
            if e.args[0] == ssl.SSL_ERROR_WANT_READ:
                return None
            else:
                raise
        except socket.error as e:
            if e.args[0] in _ERRNO_WOULDBLOCK:
                return None
            else:
                raise
        if not chunk:
            self.close()
            return None
        return chunk 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:31,代码来源:iostream.py

示例15: _do_ssl_handshake

# 需要导入模块: import ssl [as 别名]
# 或者: from ssl import SSL_ERROR_WANT_READ [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


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