
This issue trackerhas been migrated toGitHub, and is currentlyread-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.
Created on2018-10-08 06:07 byYoSTEALTH, last changed2022-04-11 14:59 byadmin. This issue is nowclosed.
| Pull Requests | |||
|---|---|---|---|
| URL | Status | Linked | Edit |
| PR 9777 | merged | python-dev,2018-10-09 18:22 | |
| Messages (7) | |||
|---|---|---|---|
| msg327323 -(view) | Author: (YoSTEALTH)* | Date: 2018-10-08 06:07 | |
How about adding basic "mime_type" method to "pathlib.Path" ?Code would do something like: import mimetypes def mime_type(name): """Mime-type of the file.""" find = name.rfind('.') ext = '' if find == -1 else name[find:] return mimetypes.types_map.get(ext, 'application/octet-stream')Users would use it like so: import pathlib file = pathlib.Path('hello_world.py') print(file.mime_type) # 'text/x-python' | |||
| msg327377 -(view) | Author: Raymond Hettinger (rhettinger)*![]() | Date: 2018-10-09 01:03 | |
-0 There is some value in having a separation of responsibilities and in not adding another dependency. On the other hand, I can see how this would sometimes be convenient.Assigning to Antoine to make the decision. | |||
| msg327382 -(view) | Author: Karthikeyan Singaravelan (xtreak)*![]() | Date: 2018-10-09 06:10 | |
Thanks for the report. There was a similar request to add pathlib.rmtree (issue33498) and adding more methods as Raymond mentioned might be convenient but there is a maintenance cost (msg316517) since there is a consensus that pathlib should do everything os.path does. It's up to Antoine to decide on this. | |||
| msg327383 -(view) | Author: Antoine Pitrou (pitrou)*![]() | Date: 2018-10-09 08:08 | |
I would rather have the mimetypes module improved to accept Path-like objects, so that the following works:>>> p = Path('LICENSE.txt')>>> mimetypes.guess_type(p)('text/plain', None)It should be quite simple to implement as well. | |||
| msg327478 -(view) | Author: Antoine Pitrou (pitrou)*![]() | Date: 2018-10-10 14:46 | |
New changeset7e18deef652a9d413d5dbd19d61073ba7eb5460e by Antoine Pitrou (Mayank Asthana) in branch 'master':bpo-34926: Make mimetypes.guess_type accept os.PathLike objects (GH-9777)https://github.com/python/cpython/commit/7e18deef652a9d413d5dbd19d61073ba7eb5460e | |||
| msg327565 -(view) | Author: Karthikeyan Singaravelan (xtreak)*![]() | Date: 2018-10-12 06:49 | |
As part of triaging, I am closing this since this was merged with doc changes and there was no back port done since it's an enhancement. Antoine, feel free to reopen this if there are any changes left.Thanks everybody for the feedback and review. | |||
| msg327566 -(view) | Author: Antoine Pitrou (pitrou)*![]() | Date: 2018-10-12 07:00 | |
No, I simply forgot to close it. Thank you! | |||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022-04-11 14:59:06 | admin | set | github: 79107 |
| 2022-01-18 09:28:49 | iritkatriel | link | issue30268 superseder |
| 2018-12-27 23:11:44 | cheryl.sabella | link | issue21524 superseder |
| 2018-10-12 07:00:45 | pitrou | set | messages: +msg327566 |
| 2018-10-12 06:49:13 | xtreak | set | status: open -> closed resolution: fixed messages: +msg327565 stage: patch review -> resolved |
| 2018-10-10 14:46:55 | pitrou | set | messages: +msg327478 |
| 2018-10-09 18:22:33 | python-dev | set | keywords: +patch stage: patch review pull_requests: +pull_request9163 |
| 2018-10-09 08:09:02 | pitrou | set | title: Adding "mime_type" method to pathlib.Path -> Allow querying a Path's mime-type |
| 2018-10-09 08:08:41 | pitrou | set | keywords: +easy messages: +msg327383 components: + Library (Lib) |
| 2018-10-09 06:10:59 | xtreak | set | nosy: +xtreak messages: +msg327382 |
| 2018-10-09 01:03:03 | rhettinger | set | assignee:pitrou messages: +msg327377 nosy: +rhettinger,pitrou |
| 2018-10-08 22:33:56 | YoSTEALTH | set | components: - Extension Modules |
| 2018-10-08 06:46:34 | xtreak | set | title: Adding "mine_type" method to pathlib.Path -> Adding "mime_type" method to pathlib.Path |
| 2018-10-08 06:07:23 | YoSTEALTH | create | |