mirror of
https://github.com/python/cpython.git
synced 2025-08-23 10:16:01 +00:00
bpo-20392: Fix inconsistency with uppercase file extensions in mimetypes.guess_type (GH-30229)
(cherry picked from commit 5dd7ec52b8
)
Co-authored-by: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com>
This commit is contained in:
parent
64a68c39cb
commit
32ae9ab55f
3 changed files with 12 additions and 6 deletions
|
@ -135,25 +135,23 @@ class MimeTypes:
|
|||
type = 'text/plain'
|
||||
return type, None # never compressed, so encoding is None
|
||||
base, ext = posixpath.splitext(url)
|
||||
while ext in self.suffix_map:
|
||||
base, ext = posixpath.splitext(base + self.suffix_map[ext])
|
||||
while (ext_lower := ext.lower()) in self.suffix_map:
|
||||
base, ext = posixpath.splitext(base + self.suffix_map[ext_lower])
|
||||
# encodings_map is case sensitive
|
||||
if ext in self.encodings_map:
|
||||
encoding = self.encodings_map[ext]
|
||||
base, ext = posixpath.splitext(base)
|
||||
else:
|
||||
encoding = None
|
||||
ext = ext.lower()
|
||||
types_map = self.types_map[True]
|
||||
if ext in types_map:
|
||||
return types_map[ext], encoding
|
||||
elif ext.lower() in types_map:
|
||||
return types_map[ext.lower()], encoding
|
||||
elif strict:
|
||||
return None, encoding
|
||||
types_map = self.types_map[False]
|
||||
if ext in types_map:
|
||||
return types_map[ext], encoding
|
||||
elif ext.lower() in types_map:
|
||||
return types_map[ext.lower()], encoding
|
||||
else:
|
||||
return None, encoding
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue