MCPcopy Index your code
hub / github.com/python/cpython / starttls

Method starttls

Lib/imaplib.py:911–931  ·  view source on GitHub ↗
(self, ssl_context=None)

Source from the content-addressed store, hash-verified

909
910
911 def starttls(self, ssl_context=None):
912 name = 'STARTTLS'
913 if not HAVE_SSL:
914 raise self.error('SSL support missing')
915 if self._tls_established:
916 raise self.abort('TLS session already established')
917 if name not in self.capabilities:
918 raise self.abort('TLS not supported by server')
919 # Generate a default SSL context if none was passed.
920 if ssl_context is None:
921 ssl_context = ssl._create_stdlib_context()
922 typ, dat = self._simple_command(name)
923 if typ == 'OK':
924 self.sock = ssl_context.wrap_socket(self.sock,
925 server_hostname=self.host)
926 self._file = self.sock.makefile('rb')
927 self._tls_established = True
928 self._get_capabilities()
929 else:
930 raise self.error("Couldn't establish TLS session")
931 return self._untagged_response(typ, dat, name)
932
933
934 def status(self, mailbox, names):

Callers

nothing calls this directly

Calls 7

_simple_commandMethod · 0.95
_get_capabilitiesMethod · 0.95
_untagged_responseMethod · 0.95
wrap_socketMethod · 0.80
errorMethod · 0.45
abortMethod · 0.45
makefileMethod · 0.45

Tested by

no test coverage detected