[3.7] bpo-22347: Update mimetypes.guess_type to allow proper parsing … · python/cpython@8873bff (original) (raw)
Navigation Menu
- GitHub Copilot Write better code with AI
- GitHub Models New Manage and compare prompts
- GitHub Advanced Security Find and fix vulnerabilities
- Actions Automate any workflow
- Codespaces Instant dev environments
- Issues Plan and track work
- Code Review Manage code changes
- Discussions Collaborate outside of code
- Code Search Find more, search less
- Explore
- Pricing
Provide feedback
Saved searches
Use saved searches to filter your results more quickly
Appearance settings
Commit 8873bff
authored and
committed
File tree
4 files changed
lines changed
4 files changed
lines changed
Lines changed: 2 additions & 1 deletion
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -114,7 +114,8 @@ def guess_type(self, url, strict=True): | ||
114 | 114 | but non-standard types. |
115 | 115 | """ |
116 | 116 | url = os.fspath(url) |
117 | -scheme, url = urllib.parse.splittype(url) | |
117 | +p = urllib.parse.urlparse(url) | |
118 | +scheme, url = p.scheme, p.path | |
118 | 119 | if scheme == 'data': |
119 | 120 | # syntax of data URLs: |
120 | 121 | # dataurl := "data:" [ mediatype ] [ ";base64" ] "," data |
Lines changed: 8 additions & 0 deletions
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -50,6 +50,14 @@ def test_non_standard_types(self): | ||
50 | 50 | eq(self.db.guess_type('foo.xul', strict=False), ('text/xul', None)) |
51 | 51 | eq(self.db.guess_extension('image/jpg', strict=False), '.jpg') |
52 | 52 | |
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 | + | |
53 | 61 | def test_guess_all_types(self): |
54 | 62 | eq = self.assertEqual |
55 | 63 | unless = self.assertTrue |
Lines changed: 1 addition & 1 deletion
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -746,7 +746,7 @@ def connect_ftp(self, user, passwd, host, port, dirs, | ||
746 | 746 | ["foo", "bar"], "", None), |
747 | 747 | ("ftp://localhost/baz.gif;type=a", |
748 | 748 | "localhost", ftplib.FTP_PORT, "", "", "A", |
749 | - [], "baz.gif", None), # XXX really this should guess image/gif | |
749 | + [], "baz.gif", "image/gif"), | |
750 | 750 | ]: |
751 | 751 | req = Request(url) |
752 | 752 | req.timeout = None |
Lines changed: 2 additions & 0 deletions
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
1 | +Update mimetypes.guess_type to allow proper parsing of URLs with only a host name. | |
2 | +Patch by Dong-hee Na. |