Navigation Menu

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

Allow querying a Path's mime-type #79107

Closed
YoSTEALTH mannequin opened this issue Oct 8, 2018 · 7 comments
Closed

Allow querying a Path's mime-type #79107

YoSTEALTH mannequin opened this issue Oct 8, 2018 · 7 comments
Assignees
Labels
3.8 only security fixes easy stdlib Python modules in the Lib dir type-feature A feature request or enhancement

Comments

@YoSTEALTH
Copy link
Mannequin

YoSTEALTH mannequin commented Oct 8, 2018

BPO 34926
Nosy @rhettinger, @pitrou, @YoSTEALTH, @tirkarthi
PRs
  • bpo-34926: Make mimetypes.guess_type accept os.PathLike objects #9777
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = 'https://github.com/pitrou'
    closed_at = <Date 2018-10-12.06:49:13.957>
    created_at = <Date 2018-10-08.06:07:23.973>
    labels = ['easy', '3.8', 'type-feature', 'library']
    title = "Allow querying a Path's mime-type"
    updated_at = <Date 2018-10-12.07:00:45.579>
    user = 'https://github.com/YoSTEALTH'

    bugs.python.org fields:

    activity = <Date 2018-10-12.07:00:45.579>
    actor = 'pitrou'
    assignee = 'pitrou'
    closed = True
    closed_date = <Date 2018-10-12.06:49:13.957>
    closer = 'xtreak'
    components = ['Library (Lib)']
    creation = <Date 2018-10-08.06:07:23.973>
    creator = 'YoSTEALTH'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 34926
    keywords = ['patch', 'easy']
    message_count = 7.0
    messages = ['327323', '327377', '327382', '327383', '327478', '327565', '327566']
    nosy_count = 4.0
    nosy_names = ['rhettinger', 'pitrou', 'YoSTEALTH', 'xtreak']
    pr_nums = ['9777']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue34926'
    versions = ['Python 3.8']

    @YoSTEALTH
    Copy link
    Mannequin Author

    YoSTEALTH mannequin commented Oct 8, 2018

    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'

    @YoSTEALTH YoSTEALTH mannequin added extension-modules C modules in the Modules dir 3.8 only security fixes type-feature A feature request or enhancement labels Oct 8, 2018
    @tirkarthi tirkarthi changed the title Adding "mine_type" method to pathlib.Path Adding "mime_type" method to pathlib.Path Oct 8, 2018
    @YoSTEALTH YoSTEALTH mannequin removed the extension-modules C modules in the Modules dir label Oct 8, 2018
    @rhettinger
    Copy link
    Contributor

    -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.

    @tirkarthi
    Copy link
    Member

    Thanks for the report. There was a similar request to add pathlib.rmtree (bpo-33498) 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.

    @pitrou
    Copy link
    Member

    pitrou commented Oct 9, 2018

    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.

    @pitrou pitrou added easy stdlib Python modules in the Lib dir labels Oct 9, 2018
    @pitrou pitrou changed the title Adding "mime_type" method to pathlib.Path Allow querying a Path's mime-type Oct 9, 2018
    @pitrou
    Copy link
    Member

    pitrou commented Oct 10, 2018

    New changeset 7e18dee by Antoine Pitrou (Mayank Asthana) in branch 'master':
    bpo-34926: Make mimetypes.guess_type accept os.PathLike objects (GH-9777)
    7e18dee

    @tirkarthi
    Copy link
    Member

    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.

    @pitrou
    Copy link
    Member

    pitrou commented Oct 12, 2018

    No, I simply forgot to close it. Thank you!

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.8 only security fixes easy stdlib Python modules in the Lib dir type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants