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

Created on 2013-02-11 10:07 by grooverdan, last changed 2013-02-11 19:16 by pitrou.

Messages (3)
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)
History
Date User Action Args
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