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

Move remaining utility functions from _utils.py to _models.py #3387

Merged
merged 2 commits into from
Nov 1, 2024

Conversation

RafaelWO
Copy link
Contributor

@RafaelWO RafaelWO commented Nov 1, 2024

Summary

Related issue: #3381

This PR moves the following remaining utility functions from _utils.py to _models.py that are only used in _models.py (except to_bytes_or_str):

  • is_known_encoding
  • parse_header_links
  • parse_content_type_charset
  • obfuscate_sensitive_headers

Related tests are also moved accordingly, i.e. from tests/test_utils.py to tests/models/test_headers.py.


Additionally, this PR fixes the script scripts/lint by using ruff check due to the following error:

error: `ruff <path>` has been removed. Use `ruff check <path>` instead.

Checklist

  • I understand that this PR may be closed in case there was no previous discussion. (This doesn't apply to typos!)
  • I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.
  • I've updated the documentation accordingly.

@RafaelWO RafaelWO force-pushed the change/move-utils-to-models branch from bd63ac9 to faa69b5 Compare November 1, 2024 15:45
@RafaelWO RafaelWO marked this pull request as draft November 1, 2024 16:25
The following functions are moved because they are only used in _models.py
* is_known_encoding
* parse_header_links
* parse_content_type_charset
* obfuscate_sensitive_headers

Related tests are also moved accordingly.
`ruff <path>` has been removed. Use `ruff check <path>` instead.
@RafaelWO RafaelWO force-pushed the change/move-utils-to-models branch from faa69b5 to 81bb8d1 Compare November 1, 2024 16:31
@RafaelWO RafaelWO marked this pull request as ready for review November 1, 2024 16:33
@RafaelWO
Copy link
Contributor Author

RafaelWO commented Nov 1, 2024

@tomchristie I first overlooked that I should also move some of the related tests. I did this now 🙂

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm note sure if test_encoded, test_bad_utf_like_encoding, and test_guess_by_bom are related to the moved function is_known_encoding and therefore should be moved into tests related to models?

@RafaelWO RafaelWO requested a review from tomchristie November 1, 2024 16:38
Copy link
Member

@tomchristie tomchristie left a comment

Choose a reason for hiding this comment

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

Thanks. ☺️ Prompted one review thought, tho let's get this in.

return links


def _obfuscate_sensitive_headers(
Copy link
Member

Choose a reason for hiding this comment

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

Is now a good time to review this? Eg does flask provide similar behaviour onto its headers data structures? Does Django?

(Possibly too off topic??)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It seems that flask does not obfuscate header values for repr (see werkzeug)

>>> from werkzeug.datastructures import Headers
>>>
>>> head = Headers({"authorization": "s3kr3t"})
>>> head
Headers([('authorization', 's3kr3t')])
>>> repr(head)
"Headers([('authorization', 's3kr3t')])"

Same for Django (see HttpHeaders or ResponseHeaders)

>>> from django.http.response import ResponseHeaders
>>> head = ResponseHeaders({"Authorization": "s3kr3t"})
>>> repr(head)
"{'Authorization': 's3kr3t'}"

@tomchristie tomchristie merged commit 41597ad into encode:master Nov 1, 2024
5 checks passed
@RafaelWO RafaelWO deleted the change/move-utils-to-models branch November 1, 2024 20:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants