Skip to content

Commit

Permalink
Merge pull request #221 from StareInTheAir/feature/ssl-context-wrap-s…
Browse files Browse the repository at this point in the history
…ocket-client

Replace deprecated ssl.wrap_socket with SSLContext.wrap_socket
  • Loading branch information
jaraco authored Mar 28, 2024
2 parents 6228067 + 52aac1b commit 03f998a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
5 changes: 4 additions & 1 deletion irc/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,16 @@ class Factory:
.. code-block:: python
context = ssl.create_default_context()
wrapper = functools.partial(context.wrap_socket, server_hostname=server_address)
Factory(wrapper=ssl.wrap_socket)(server_address)
To create an SSL connection with parameters to wrap_socket:
.. code-block:: python
wrapper = functools.partial(ssl.wrap_socket, ssl_cert=get_cert())
context = ssl.create_default_context()
wrapper = functools.partial(context.wrap_socket, server_hostname=server_address, ssl_cert=get_cert())
Factory(wrapper=wrapper)(server_address)
To create an IPv6 connection:
Expand Down
1 change: 1 addition & 0 deletions newsfragments/216.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Replace deprecated ssl.wrap_socket with SSLContext.wrap_socket and update examples in connection.py docs.
5 changes: 4 additions & 1 deletion scripts/ssl-cat.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import ssl
import argparse
import itertools
import functools

import irc.client

Expand Down Expand Up @@ -60,7 +61,9 @@ def main():
args = get_args()
target = args.target

ssl_factory = irc.connection.Factory(wrapper=ssl.wrap_socket)
context = ssl.create_default_context()
wrapper = functools.partial(context.wrap_socket, server_hostname=args.server)
ssl_factory = irc.connection.Factory(wrapper=wrapper)
reactor = irc.client.Reactor()
try:
c = reactor.server().connect(
Expand Down

0 comments on commit 03f998a

Please sign in to comment.