From b4bcd3c3d1964352d5f51def08629114057541a8 Mon Sep 17 00:00:00 2001 From: Matthew Treinish Date: Mon, 6 Feb 2023 16:04:08 -0500 Subject: Replace deprecated `cgi` module usage with `email` In Python 3.11 the standard library `cgi` module was deprecated with a planned removal set for Python 3.13. In preparation for that removal, this commit removes the usage of this deprecated module and replaces it with the still supported standard library `email` module which is what the documentation points to as an alternative for how `cgi` was previously used. This should still be compatible with all the supported Python versions but will be more future proof and not emit any deprecation warnings with Python 3.11 anymore. --- testtools/testresult/real.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/testtools/testresult/real.py b/testtools/testresult/real.py index 8c7f372..be9122a 100644 --- a/testtools/testresult/real.py +++ b/testtools/testresult/real.py @@ -22,8 +22,8 @@ __all__ = [ 'TimestampingStreamResult', ] -import cgi import datetime +import email import math from operator import methodcaller import sys @@ -759,7 +759,10 @@ def _make_content_type(mime_type=None): if mime_type is None: mime_type = 'application/octet-stream' - full_type, parameters = cgi.parse_header(mime_type) + msg = email.message.EmailMessage() + msg['content-type'] = mime_type + + full_type, parameters = msg.get_content_type(), msg['content-type'].params # Ensure any wildcards are valid. if full_type == '*': full_type = '*/*' -- cgit v1.2.1