'(typ, [data]) = starttls(keyfile=None, certfile=None, ca_certs=None, cert_verify_cb=None, ssl_version="ssl23", tls_level="tls_compat")
Start TLS negotiation as per RFC 2595.'

def starttls(self, keyfile=None, certfile=None, ca_certs=None, cert_verify_cb=None, ssl_version='ssl23', tls_level=TLS_COMPAT, **kw):

    name = 'STARTTLS'
    if (name not in self.capabilities):
        raise self.abort('TLS    not    supported    by    server')
    if self._tls_established:
        raise self.abort('TLS    session    already    established')
    self.read_size = 1
    self.TerminateReader = True
    try:
        (typ, dat) = self._simple_command(name)
    finally:
        self._release_state_change()
        self.rdth.join()
        self.TerminateReader = False
        self.read_size = READ_SIZE
    if (typ != 'OK'):
        self.rdth = threading.Thread(target=self._reader)
        self.rdth.setDaemon(True)
        self.rdth.start()
        raise self.error(("Couldn't    establish    TLS    session:    %s" % dat))
    self.keyfile = keyfile
    self.certfile = certfile
    self.ca_certs = ca_certs
    self.cert_verify_cb = cert_verify_cb
    self.ssl_version = ssl_version
    self.tls_level = tls_level
    try:
        self.ssl_wrap_socket()
    finally:
        self.rdth = threading.Thread(target=self._reader)
        self.rdth.setDaemon(True)
        self.rdth.start()
    (typ, dat) = self.capability()
    if (dat == [None]):
        raise self.error('no    CAPABILITY    response    from    server')
    self.capabilities = tuple(dat[(-1)].upper().split())
    self._tls_established = True
    (typ, dat) = self._untagged_response(typ, dat, name)
    return self._deliver_dat(typ, dat, kw)
