Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace deprecated cgi module usage with email #340

Merged
merged 2 commits into from
Mar 14, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 5 additions & 2 deletions testtools/testresult/real.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
'TimestampingStreamResult',
]

import cgi
import datetime
import email
import math
from operator import methodcaller
import sys
Expand Down Expand Up @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new parameters now is a mappingproxy, so your solution is not equivalent to the old one.

When you scroll down a bit you can see that parameters will be manipulated, which does not work for a mappingproxy.

Unfortunately, the test coverage does not seem to be high for this package, so this was not uncovered.

You can workaround that issue when you wrap msg['content-type'].params in a dict().

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mtreinish Do you think you can push the requested changes? I see the deprecation warning daily and I'd really like to get rid of it :-D Thank you!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the delay I missed this comment at first. I've added the dict wrapping in: 54ea8f2

# Ensure any wildcards are valid.
if full_type == '*':
full_type = '*/*'
Expand Down