# HG changeset patch # Parent bb67b810aac130a56a1ae2d0e51d8030a8f59fae diff -r bb67b810aac1 Doc/library/mimetypes.rst --- a/Doc/library/mimetypes.rst Mon Feb 23 07:56:13 2015 -0800 +++ b/Doc/library/mimetypes.rst Tue Feb 24 05:52:14 2015 +0000 @@ -30,7 +30,7 @@ .. index:: pair: MIME; headers - Guess the type of a file based on its filename or URL, given by *url*. The + Guess the type of a file based on its URL, given by *url*. The return value is a tuple ``(type, encoding)`` where *type* is ``None`` if the type can't be guessed (missing or unknown suffix) or a string of the form ``'type/subtype'``, usable for a MIME :mailheader:`content-type` header. diff -r bb67b810aac1 Lib/mimetypes.py --- a/Lib/mimetypes.py Mon Feb 23 07:56:13 2015 -0800 +++ b/Lib/mimetypes.py Tue Feb 24 05:52:14 2015 +0000 @@ -111,8 +111,10 @@ Optional `strict' argument when False adds a bunch of commonly found, but non-standard types. """ - scheme, url = urllib.parse.splittype(url) - if scheme == 'data': + split = urllib.parse.urlsplit(url) + # Rebuild URL without scheme://netloc part + url = urllib.parse.urlunsplit(('', '') + split[2:]) + if split.scheme == 'data': # syntax of data URLs: # dataurl := "data:" [ mediatype ] [ ";base64" ] "," data # mediatype := [ type "/" subtype ] *( ";" parameter ) diff -r bb67b810aac1 Lib/test/test_mimetypes.py --- a/Lib/test/test_mimetypes.py Mon Feb 23 07:56:13 2015 -0800 +++ b/Lib/test/test_mimetypes.py Tue Feb 24 05:52:14 2015 +0000 @@ -49,6 +49,11 @@ eq(self.db.guess_type('foo.xul', strict=False), ('text/xul', None)) eq(self.db.guess_extension('image/jpg', strict=False), '.jpg') + def test_url(self): + result = self.db.guess_type('http://host.html') + msg = 'URL only has a host name, not a file' + self.assertSequenceEqual(result, (None, None), msg) + def test_guess_all_types(self): eq = self.assertEqual unless = self.assertTrue