Issue 28025: Use IntEnum and IntFlags in ssl module (original) (raw)

Created on 2016-09-08 17:35 by christian.heimes, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
ssl_enum.patch christian.heimes,2016-09-08 17:35 review
convert-ssl-constants-to-enums.patch christian.heimes,2016-09-08 18:13 review
Messages (10)
msg275076 - (view) Author: Christian Heimes (christian.heimes) * (Python committer) Date: 2016-09-08 17:35
The patch removes ssl._import_symbols and adds more enums to the ssl module. Please review the patch. I'll update documentation in the next step. With IntFlags it is much easier to understand flags like SSLContext.options >>> import ssl >>> ctx = ssl.create_default_context() >>> ssl.Options(ctx.options) <Options.OP_ALL|OP_NO_SSLv3 OP_NO_SSLv2 OP_NO_COMPRESSION: 2197947391>
msg275096 - (view) Author: Christian Heimes (christian.heimes) * (Python committer) Date: 2016-09-08 18:13
Thanks Ethan! I have updated the patch with documentation and your fix. Do you have an easy recipe to wrap properties like SSLContext.options to return an enum? It's not easy because super() does not support attribute proxy assignment. super().verify_mode = value raises an AttributeError.
msg275113 - (view) Author: Ethan Furman (ethan.furman) * (Python committer) Date: 2016-09-08 18:56
Can you give me a code sample? Also, wouldn't <Options.ALL|NO_SSLv3 NO_SSLv2 NO_COMPRESSION: 2197947391> be more readable? And keep the "OP_" names as aliases.
msg275119 - (view) Author: Christian Heimes (christian.heimes) * (Python committer) Date: 2016-09-08 19:15
I tried: class SSLContext(_SSLContext): ... @property def options(self): return Options(super().options) @options.setter def options(self, value) super().options = value # ^^^^^ # This fails with an AttributeError # it would be cool to have something like this: options = MagicEnumWrapper(Options) About the shorter names, I'm worried that it might confuse people. The long names have been module constants for a long time.
msg275131 - (view) Author: Ethan Furman (ethan.furman) * (Python committer) Date: 2016-09-08 19:57
Huh. Well, for property this works: @property def options(self): return Options(_SSLContext.options.__get__(self)) @options.setter def options(self, value): _SSLContext.options.__set__(self, Options.OP_ALL) Sure is ugly, though. I think there's a PEP about making super() work with descriptors... Ah, PEP447 (not sure it's the same issue, though.)
msg275137 - (view) Author: Ethan Furman (ethan.furman) * (Python committer) Date: 2016-09-08 20:23
A little more research shows this is a problem with inheriting descriptors.
msg275138 - (view) Author: Ethan Furman (ethan.furman) * (Python committer) Date: 2016-09-08 20:28
See .
msg275146 - (view) Author: Ethan Furman (ethan.furman) * (Python committer) Date: 2016-09-08 20:43
Evidently the correct form is: super(SSLContext, SSLContext).options.__set__(self, value) Not sure that's any better. :(
msg275155 - (view) Author: Christian Heimes (christian.heimes) * (Python committer) Date: 2016-09-08 21:06
Too bad, but the ugly variant will suffice. >>> import ssl >>> ctx = ssl.create_default_context() >>> ctx.options <Options.OP_ALL|OP_NO_SSLv3 OP_NO_SSLv2 OP_NO_COMPRESSION: 2197947391> >>> ctx.verify_flags <VerifyFlags.VERIFY_X509_TRUSTED_FIRST: 32768> >>> ctx.verify_mode <VerifyMode.CERT_REQUIRED: 2> Latest patch: https://github.com/tiran/cpython/commits/feature/ssl_enum
msg275472 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2016-09-09 22:20
New changeset c32e9f9b00f7 by Christian Heimes in branch 'default': Issue #28025: Convert all ssl module constants to IntEnum and IntFlags. https://hg.python.org/cpython/rev/c32e9f9b00f7
History
Date User Action Args
2022-04-11 14:58:36 admin set github: 72212
2017-03-07 18:49:32 serhiy.storchaka set status: pending -> closedresolution: fixedstage: commit review -> resolved
2016-09-09 22:20:29 christian.heimes set status: open -> pendingstage: patch review -> commit review
2016-09-09 22:20:00 python-dev set nosy: + python-devmessages: +
2016-09-08 21🔞27 vstinner set nosy: - vstinner
2016-09-08 21:06:59 christian.heimes set messages: +
2016-09-08 20:43:21 ethan.furman set messages: +
2016-09-08 20:28:13 ethan.furman set messages: +
2016-09-08 20:23:53 ethan.furman set messages: +
2016-09-08 19:57:14 ethan.furman set messages: +
2016-09-08 19:15:24 christian.heimes set messages: +
2016-09-08 18:56:29 ethan.furman set messages: +
2016-09-08 18:13:51 christian.heimes set files: + convert-ssl-constants-to-enums.patchmessages: +
2016-09-08 17:38:45 ethan.furman set nosy: + ethan.furman
2016-09-08 17:35:49 christian.heimes create