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

Remove urllib.parse._splittype from mimetypes.guess_type #80120

Closed
corona10 opened this issue Feb 8, 2019 · 2 comments
Closed

Remove urllib.parse._splittype from mimetypes.guess_type #80120

corona10 opened this issue Feb 8, 2019 · 2 comments
Labels
3.7 (EOL) end of life 3.8 only security fixes 3.9 only security fixes stdlib Python modules in the Lib dir type-feature A feature request or enhancement

Comments

@corona10
Copy link
Member

corona10 commented Feb 8, 2019

BPO 35939
Nosy @orsenthil, @vadmium, @corona10
Superseder
  • bpo-22347: mimetypes.guess_type("//example.com") misinterprets host name as file name
  • 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 = None
    closed_at = <Date 2019-09-05.01:43:49.292>
    created_at = <Date 2019-02-08.08:14:43.855>
    labels = ['3.7', '3.8', 'type-feature', 'library', '3.9']
    title = 'Remove urllib.parse._splittype from mimetypes.guess_type'
    updated_at = <Date 2019-09-05.12:19:43.440>
    user = 'https://github.com/corona10'

    bugs.python.org fields:

    activity = <Date 2019-09-05.12:19:43.440>
    actor = 'corona10'
    assignee = 'none'
    closed = True
    closed_date = <Date 2019-09-05.01:43:49.292>
    closer = 'corona10'
    components = ['Library (Lib)']
    creation = <Date 2019-02-08.08:14:43.855>
    creator = 'corona10'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 35939
    keywords = []
    message_count = 2.0
    messages = ['335061', '351169']
    nosy_count = 3.0
    nosy_names = ['orsenthil', 'martin.panter', 'corona10']
    pr_nums = []
    priority = 'normal'
    resolution = 'duplicate'
    stage = 'resolved'
    status = 'closed'
    superseder = '22347'
    type = 'enhancement'
    url = 'https://bugs.python.org/issue35939'
    versions = ['Python 3.7', 'Python 3.8', 'Python 3.9']

    @corona10
    Copy link
    Member Author

    corona10 commented Feb 8, 2019

    Since urllib.parse.splittype is deprecated on 3.8.
    In the future urllib.parse._splittype also should be removed.

    I found that mimetypes.guess_type uses urllib.parse._splittype and
    it can be replaced and it also looks like solve the issue mentioned on https://github.com/python/cpython/blame/e42b705188271da108de42b55d9344642170aa2b/Lib/test/test_urllib2.py#L749

    And I checked that all unit tests are passed when

    --- a/Lib/mimetypes.py
    +++ b/Lib/mimetypes.py
    @@ -114,7 +114,8 @@ class MimeTypes:
             but non-standard types.
             """
             url = os.fspath(url)
    -        scheme, url = urllib.parse._splittype(url)
    +        p = urllib.parse.urlparse(url)
    +        scheme, url = p.scheme, p.path
             if scheme == 'data':
                 # syntax of data URLs:
                 # dataurl   := "data:" [ mediatype ] [ ";base64" ] "," data
    diff --git a/Lib/test/test_urllib2.py b/Lib/test/test_urllib2.py
    index 876fcd4199..0677390c2b 100644
    --- a/Lib/test/test_urllib2.py
    +++ b/Lib/test/test_urllib2.py
    @@ -746,7 +746,7 @@ class HandlerTests(unittest.TestCase):
                  ["foo", "bar"], "", None),
                 ("ftp://localhost/baz.gif;type=a",
                  "localhost", ftplib.FTP_PORT, "", "", "A",
    -             [], "baz.gif", None),  # XXX really this should guess image/gif
    +             [], "baz.gif", "image/gif"),
                 ]:
                 req = Request(url)
                 req.timeout = None

    I'd like to work on this issue if this proposal is accepted!
    Always thanks

    @corona10 corona10 added 3.8 only security fixes stdlib Python modules in the Lib dir type-feature A feature request or enhancement 3.7 (EOL) end of life labels Feb 8, 2019
    @corona10
    Copy link
    Member Author

    corona10 commented Sep 5, 2019

    This issue is fixed by
    #15522

    @corona10 corona10 added the 3.9 only security fixes label Sep 5, 2019
    @corona10 corona10 closed this as completed Sep 5, 2019
    @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.7 (EOL) end of life 3.8 only security fixes 3.9 only security fixes stdlib Python modules in the Lib dir type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant