Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2a40559

Browse files
maxkingned-deily
authored andcommitted
[3.7] bpo-38449: Revert "bpo-22347: Update mimetypes.guess_type to allow oper parsing of URLs (GH-15685)" (GH-16724) (GH-16727)
Reverts GH-15687 which caused the issue. https://bugs.python.org/issue22347 https://bugs.python.org/issue38449
1 parent c16897c commit 2a40559

File tree

4 files changed

+4
-11
lines changed

4 files changed

+4
-11
lines changed

Lib/mimetypes.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,7 @@ def guess_type(self, url, strict=True):
114114
but non-standard types.
115115
"""
116116
url = os.fspath(url)
117-
p = urllib.parse.urlparse(url)
118-
scheme, url = p.scheme, p.path
117+
scheme, url = urllib.parse.splittype(url)
119118
if scheme == 'data':
120119
# syntax of data URLs:
121120
# dataurl := "data:" [ mediatype ] [ ";base64" ] "," data

Lib/test/test_mimetypes.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,6 @@ def test_non_standard_types(self):
5050
eq(self.db.guess_type('foo.xul', strict=False), ('text/xul', None))
5151
eq(self.db.guess_extension('image/jpg', strict=False), '.jpg')
5252

53-
def test_url(self):
54-
result = self.db.guess_type('http://host.html')
55-
msg = 'URL only has a host name, not a file'
56-
self.assertSequenceEqual(result, (None, None), msg)
57-
result = self.db.guess_type('http://example.com/host.html')
58-
msg = 'Should be text/html'
59-
self.assertSequenceEqual(result, ('text/html', None), msg)
60-
6153
def test_guess_all_types(self):
6254
eq = self.assertEqual
6355
unless = self.assertTrue

Lib/test/test_urllib2.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -746,7 +746,7 @@ def connect_ftp(self, user, passwd, host, port, dirs,
746746
["foo", "bar"], "", None),
747747
("ftp://localhost/baz.gif;type=a",
748748
"localhost", ftplib.FTP_PORT, "", "", "A",
749-
[], "baz.gif", "image/gif"),
749+
[], "baz.gif", None), # XXX really this should guess image/gif
750750
]:
751751
req = Request(url)
752752
req.timeout = None
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Revert GH-15522, which introduces a regression in
2+
:meth:`mimetypes.guess_type` due to improper handling of filenames as urls.

0 commit comments

Comments
 (0)