def startSSL(self, ssl_options={}):
        """
        Enable SSL on the channel and perform a handshake at the next
        opportunity.

        SSL is only enabled on a channel once all currently pending data
        has been written. If a problem occurs at this stage,
        :meth:`~pants.stream.Stream.on_ssl_error` is called. Once SSL
        has been enabled, the SSL handshake begins - this typically
        takes some time and may fail, in which case
        :meth:`~pants.stream.Stream.on_ssl_handshake_error` will be
        called. When the handshake is successfully completed,
        :meth:`~pants.stream.Stream.on_ssl_handshake` is called and the
        channel is secure.

        Typically, this method is called before
        :meth:`~pants.stream.Stream.connect`. In this case,
        :meth:`~pants.stream.Stream.on_ssl_handshake` will be called
        before :meth:`~pants.stream.Stream.on_connect`. If
        :meth:`~pants.stream.Stream.startSSL` is called after
        :meth:`~pants.stream.Stream.connect`, the reverse is true.

        It is possible, although unusual, to start SSL on a channel that
        is already connected and active. In this case, as noted above,
        SSL will only be enabled and the handshake performed after all
        currently pending data has been written.

        The SSL options argument will be passed through to
        :func:`ssl.wrap_socket` as keyword arguments - see the
        :mod:`ssl` documentation for further information. You will
        typically want to provide the ``keyfile``, ``certfile`` and
        ``ca_certs`` options. The ``do_handshake_on_connect`` option
        **must** be ``False``, or a :exc:`ValueError` will be raised.

        Attempting to enable SSL on a closed channel or a channel that
        already has SSL enabled on it will raise a :exc:`RuntimeError`.

        Returns the channel.

        ============ ===================================================
        Arguments    Description
        ============ ===================================================
        ssl_options  *Optional.* Keyword arguments to pass to
                     :func:`ssl.wrap_socket`.
        ============ ===================================================
        """
        if self.ssl_enabled or self._ssl_enabling:
            raise RuntimeError("startSSL() called on SSL-enabled %r" % self)

        if self._closed or self._closing:
            raise RuntimeError("startSSL() called on closed %r" % self)

        if ssl_options.setdefault("do_handshake_on_connect", False) is not False:
            raise ValueError("SSL option 'do_handshake_on_connect' must be False.")

        self._ssl_enabling = True
        self._send_buffer.append((Stream.SEND_SSL_HANDSHAKE, ssl_options))

        if self.connected:
            self._process_send_buffer()

        return self
dataset/ETHPy150Open ecdavis/pants/pants/stream.py/Stream.startSSL/original