-
-
Notifications
You must be signed in to change notification settings - Fork 36.3k
Parse header with email.parser #145113
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
Parse header with email.parser #145113
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @soldierkam
It seems you haven't yet signed a CLA. Please do so here.
Once you do that we will be able to review and accept this pull request.
Thanks!
|
Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍 |
|
Hey there @erwindouna, mind taking a look at this pull request as it has been labeled with an integration ( Code owner commandsCode owners of
|
8d883b0 to
bf0d293
Compare
|
|
||
| from __future__ import annotations | ||
|
|
||
| from email.parser import HeaderParser |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why this library?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was evaluating modules in the Python Standard Library for parsing headers. I identified two candidates: email and cgi. Since cgi is deprecated, email was the only viable option. I wanted to avoid introducing additional dependencies.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it not possible to use aiohttp library? https://github.com/aio-libs/aiohttp/blob/e5d1240babff6db6297e0d92f174446de19cf76d/aiohttp/client_reqrep.py#L892-L899
disposition_type, params_dct = multipart.parse_content_disposition(raw)
params = MappingProxyType(params_dct)
filename = multipart.content_disposition_filename(params)
return ContentDisposition(disposition_type, params, filename)It is a core dependency of Home Assistant so it wouldn't be considered "introducing additional dependencies"
Also (related but not dependant) it seems that "downloader" is still using "requests". Would it not make sense to migrate to aiohttp instead and gain all the benefits of async downloads?
async with session.get(url, stream=True, timeout=10) as req:
if req.status != HTTPStatus.OK:
...
return
...
filename = req.content_disposition.filename|
There hasn't been any activity on this pull request recently. This pull request has been automatically marked as stale because of that and will be closed if no further activity occurs within 7 days. |
Proposed change
Current implementation is using regular expression to extract filename from Content-Disposition. It truncates the filename if it contains space character.
Type of change
Additional information
Checklist
ruff format homeassistant tests)If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
Updated and included derived files by running:
python3 -m script.hassfest.requirements_all.txt.Updated by running
python3 -m script.gen_requirements_all.To help with the load of incoming pull requests: