This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: SSLContext.set_servername_callback should be able to set argument
Type: enhancement Stage: resolved
Components: Library (Lib) Versions: Python 3.5
process
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: Nosy List: christian.heimes, grooverdan, pitrou
Priority: normal Keywords:

Created on 2013-02-11 10:07 by grooverdan, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (4)
msg181889 - (view) Author: Daniel Black (grooverdan) * Date: 2013-02-11 10:07
I think my original implementation of the SNI callback to see a original sslcontext was wrong. It would be much more useful for the SSLContext.set_servername_callback to take a callable and an object as an argument.

This would allow constructs like the following where self can be used within the callback. Example:

        def cb_sni(ssl_sock, server_name, self):
            self.sniname = server_name

        self.context.set_servername_callback(cb_sni, self)

The original functionality can still occur with:

        self.context.set_servername_callback(cb_sni, self.context)

Agree?
msg181898 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2013-02-11 15:19
> This would allow constructs like the following where self can be used
> within the callback. Example:
> 
>         def cb_sni(ssl_sock, server_name, self):
>             self.sniname = server_name
> 
>         self.context.set_servername_callback(cb_sni, self)
> 
> The original functionality can still occur with:
> 
>         self.context.set_servername_callback(cb_sni, self.context)

But you could simply use a closure:

        def cb_sni(ssl_sock, server_name):
            self.sniname = server_name

        self.context.set_servername_callback(cb_sni)
msg181923 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2013-02-11 19:16
(functools.partial is another solution to the problem)
msg404688 - (view) Author: Christian Heimes (christian.heimes) * (Python committer) Date: 2021-10-21 22:22
As Antoine said, you can use a partial function, closure, or an instance method as a callable.

Besides nobody else has requested an additional argument in the past eight years. I see this as a strong indication that an argument is not required.
History
Date User Action Args
2022-04-11 14:57:41adminsetgithub: 61383
2021-10-21 22:22:29christian.heimessetstatus: open -> closed
resolution: rejected
messages: + msg404688

stage: resolved
2021-10-21 22:05:30iritkatrielsetnosy: + christian.heimes
2013-02-11 19:16:11pitrousetmessages: + msg181923
2013-02-11 15:19:25pitrousetmessages: + msg181898
title: SSLContext.set_servername_callback should be able to set argument -> SSLContext.set_servername_callback should be able to set argument
2013-02-11 10:07:39grooverdancreate