5from ..exceptions
import ProxySchemeUnsupported
6from ..packages
import six
13 The SSLTransport wraps an existing socket and establishes an SSL connection.
15 Contrary to Python's implementation of SSLSocket, it allows you to chain
16 multiple TLS connections together. It's particularly useful if you need to
17 implement TLS within TLS.
19 The class supports most of the socket API operations.
25 Raises a ProxySchemeUnsupported if the provided ssl_context can't be used
28 The only requirement is that the ssl_context provides the 'wrap_bio'
32 if not hasattr(ssl_context,
"wrap_bio"):
35 "TLS in TLS requires SSLContext.wrap_bio() which isn't "
36 "supported on Python 2"
40 "TLS in TLS requires SSLContext.wrap_bio() which isn't "
41 "available on non-native SSLContext"
45 self, socket, ssl_context, server_hostname=None, suppress_ragged_eofs=True
48 Create an SSLTransport around socket using the provided ssl_context.
72 def read(self, len=1024, buffer=None):
75 def recv(self, len=1024, flags=0):
77 raise ValueError(
"non-zero flags not allowed in calls to recv")
82 raise ValueError(
"non-zero flags not allowed in calls to recv_into")
83 if buffer
and (nbytes
is None):
87 return self.
read(nbytes, buffer)
91 raise ValueError(
"non-zero flags not allowed in calls to sendall")
94 amount =
len(byte_view)
96 v = self.
send(byte_view[count:])
99 def send(self, data, flags=0):
101 raise ValueError(
"non-zero flags not allowed in calls to send")
106 self, mode="r", buffering=None, encoding=None, errors=None, newline=None
109 Python's httpclient uses makefile and buffered io when reading HTTP
110 messages and we need to support it.
112 This is unfortunately a copy and paste of socket.py makefile with small
113 changes to point to the socket directly.
115 if not set(mode) <= {
"r",
"w",
"b"}:
116 raise ValueError(
"invalid mode %r (only r, w, b allowed)" % (mode,))
118 writing =
"w" in mode
119 reading =
"r" in mode
or not writing
120 assert reading
or writing
129 if buffering
is None:
135 raise ValueError(
"unbuffered streams must be binary")
137 if reading
and writing:
160 return self.
sslobj.version()
196 """Performs an I/O loop between incoming/outgoing and the socket."""
recv(self, len=1024, flags=0)
_ssl_io_loop(self, func, *args)
_wrap_ssl_read(self, len, buffer=None)
recv_into(self, buffer, nbytes=None, flags=0)
_validate_ssl_context_for_tls_in_tls(ssl_context)
getpeercert(self, binary_form=False)
selected_alpn_protocol(self)
__init__(self, socket, ssl_context, server_hostname=None, suppress_ragged_eofs=True)
sendall(self, data, flags=0)
makefile(self, mode="r", buffering=None, encoding=None, errors=None, newline=None)
read(self, len=1024, buffer=None)
send(self, data, flags=0)
selected_npn_protocol(self)