當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。