Skip to content

Commit

Permalink
Merge pull request #16 from jamesmallen/feature/ssl-context-in-trio
Browse files Browse the repository at this point in the history
WIP: Pass ssl_context variable to trio
  • Loading branch information
theelous3 authored Sep 13, 2018
2 parents 418e504 + 42260c8 commit b6b6251
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions multio/_event_loop_wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,21 @@ async def trio_open_connection(host, port, *, ssl=False, **kwargs):
Args:
host (str): Network location, either by domain or IP.
port (int): The requested port.
ssl (bool): Whether or not SSL is required.
ssl (bool or SSLContext): If False or None, SSL is not required. If
True, the context returned by trio.ssl.create_default_context will
be used. Otherwise, this may be an SSLContext object.
kwargs: A catch all to soak up curio's additional kwargs and
ignore them.
'''
import trio
if not ssl:
sock = await trio.open_tcp_stream(host, port)
else:
sock = await trio.open_ssl_over_tcp_stream(host, port)
if isinstance(ssl, bool):
ssl_context = None
else:
ssl_context = ssl
sock = await trio.open_ssl_over_tcp_stream(host, port, ssl_context=ssl_context)
await sock.do_handshake()

sock.close = sock.aclose
Expand Down

0 comments on commit b6b6251

Please sign in to comment.