Beispiel #1
0
    def _make_ssl_transport(self, rawsock, protocol, sslcontext, waiter=None,
                            *, server_side=False, server_hostname=None,
                            extra=None, server=None):
        """Create SSL transport."""
        from asyncio import sslproto

        if not sslproto._is_sslproto_available():
            # Python 3.4.3 and below
            if hasattr(self, "_make_legacy_ssl_transport"):
                # HACK: Add compatibility aliases to make
                #       `_SelectorSslTransport` somehow work, then reuse the
                #       SSL transport code from the official library
                self._add_reader = self.add_reader
                self._remove_reader = self.remove_reader
                self._add_writer = self.add_writer
                self._remove_writer = self.remove_writer
                return self._make_legacy_ssl_transport(
                             rawsock, protocol, sslcontext, waiter,
                             server_side=server_side, server_hostname=server_hostname,
                             extra=extra, server=server)
            raise NotImplementedError("Proactor event loop requires Python 3.5"
                                      " or newer (ssl.MemoryBIO) to support "
                                      "SSL")

        ssl_protocol = sslproto.SSLProtocol(self, protocol, sslcontext, waiter,
                                            server_side, server_hostname)
        transports.SocketTransport(self, rawsock, ssl_protocol, extra=extra, server=server)
        return ssl_protocol._app_transport
Beispiel #2
0
    def _make_ssl_transport(self,
                            rawsock,
                            protocol,
                            sslcontext,
                            waiter=None,
                            *,
                            server_side=False,
                            server_hostname=None,
                            extra=None,
                            server=None,
                            ssl_handshake_timeout=None):
        """Create SSL transport."""
        # sslproto._is_sslproto_available was removed from asyncio, starting from Python 3.7.
        if (hasattr(sslproto, "_is_sslproto_available")
                and not sslproto._is_sslproto_available()):
            raise NotImplementedError("Proactor event loop requires Python 3.5"
                                      " or newer (ssl.MemoryBIO) to support "
                                      "SSL")
        # Support for the ssl_handshake_timeout keyword argument was added in Python 3.7.
        extra_protocol_kwargs = {}
        if sys.version_info[:2] >= (3, 7):
            extra_protocol_kwargs[
                "ssl_handshake_timeout"] = ssl_handshake_timeout

        ssl_protocol = sslproto.SSLProtocol(self, protocol, sslcontext, waiter,
                                            server_side, server_hostname,
                                            **extra_protocol_kwargs)
        transports.SocketTransport(self,
                                   rawsock,
                                   ssl_protocol,
                                   extra=extra,
                                   server=server)
        return ssl_protocol._app_transport
Beispiel #3
0
    def _make_ssl_transport(self, rawsock, protocol, sslcontext, waiter=None,
                            *, server_side=False, server_hostname=None,
                            extra=None, server=None):
        """Create SSL transport."""
        if not sslproto._is_sslproto_available():
            # Python 3.4.3 and below
            if hasattr(self, "_make_legacy_ssl_transport"):
                # HACK: Add compatibility aliases to make
                #       `_SelectorSslTransport` somehow work, then reuse the
                #       SSL transport code from the official library
                self._add_reader = self.add_reader
                self._remove_reader = self.remove_reader
                self._add_writer = self.add_writer
                self._remove_writer = self.remove_writer
                return self._make_legacy_ssl_transport(
                             rawsock, protocol, sslcontext, waiter,
                             server_side=server_side, server_hostname=server_hostname,
                             extra=extra, server=server)
            raise NotImplementedError("Proactor event loop requires Python 3.5"
                                      " or newer (ssl.MemoryBIO) to support "
                                      "SSL")

        ssl_protocol = sslproto.SSLProtocol(self, protocol, sslcontext, waiter,
                                            server_side, server_hostname)
        transports.SocketTransport(self, rawsock, ssl_protocol, extra=extra, server=server)
        return ssl_protocol._app_transport