Move remaining utility functions from _utils.py to _models.py #3387
Move remaining utility functions from _utils.py to _models.py #3387lovelydinosaur merged 2 commits intoencode:masterfrom
Conversation
bd63ac9 to
faa69b5
Compare
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.
faa69b5 to
81bb8d1
Compare
|
@tomchristie I first overlooked that I should also move some of the related tests. I did this now 🙂 |
There was a problem hiding this comment.
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?
lovelydinosaur
left a comment
There was a problem hiding this comment.
Thanks.
| return links | ||
|
|
||
|
|
||
| def _obfuscate_sensitive_headers( |
There was a problem hiding this comment.
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??)
There was a problem hiding this comment.
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'}"
Summary
Related issue: #3381
This PR moves the following remaining utility functions from
_utils.pyto_models.pythat are only used in_models.py(exceptto_bytes_or_str):is_known_encodingparse_header_linksparse_content_type_charsetobfuscate_sensitive_headersRelated tests are also moved accordingly, i.e. from
tests/test_utils.pytotests/models/test_headers.py.Additionally, this PR fixes the script
scripts/lintby usingruff checkdue to the following error:Checklist