asynconnect.py 文件源码

python
阅读 24 收藏 0 点赞 0 评论 0

项目:aquests 作者: hansroh 项目源码 文件源码
def handshake (self):
        if not self._handshaking:
            err = self.socket.getsockopt(socket.SOL_SOCKET, socket.SO_ERROR)
            if err != 0:
                raise OSError(err, asyncore._strerror(err))

            ssl_context = create_urllib3_context(ssl_version=resolve_ssl_version(None), cert_reqs=resolve_cert_reqs(None))
            if self.ac_negotiate_http2:
                try: ssl_context.set_alpn_protocols (H2_PROTOCOLS)
                except AttributeError: ssl_context.set_npn_protocols (H2_PROTOCOLS)                             
            self.socket = ssl_context.wrap_socket (self.socket, do_handshake_on_connect = False, server_hostname = self.address [0])            
            self._handshaking = True

        try:
            self.socket.do_handshake ()
        except ssl.SSLError as why:
            if why.args [0] in (ssl.SSL_ERROR_WANT_READ, ssl.SSL_ERROR_WANT_WRITE):
                return False
            raise ssl.SSLError(why)

        try: self._proto = self.socket.selected_alpn_protocol()
        except (AttributeError, NotImplementedError): 
            try: self._proto = self.socket.selected_npn_protocol()
            except (AttributeError, NotImplementedError): pass

        self._handshaked = True
        return True
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号