summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthew Treinish <mtreinish@kortar.org>2023-02-06 16:04:08 -0500
committerMatthew Treinish <mtreinish@kortar.org>2023-02-06 16:04:08 -0500
commitb4bcd3c3d1964352d5f51def08629114057541a8 (patch)
tree0590c743258d769c12544907176c83540240a0b6
parent89ed130cf089a448b6d4492d5a4df9d6aecb9d23 (diff)
downloadtesttools-b4bcd3c3d1964352d5f51def08629114057541a8.tar.gz
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.
-rw-r--r--testtools/testresult/real.py7
1 files 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 = '*/*'