File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 55import magic
66import re
77
8+
89def get_mime_type (content ):
910 # try to fixup encoding
1011 if hasattr (magic , "open" ):
@@ -13,15 +14,17 @@ def get_mime_type(content):
1314 filetype = m .buffer (content )
1415 else :
1516 m = magic .Magic ()
16- m .cookie = magic .magic_open (magic .MAGIC_NONE | magic .MAGIC_MIME | magic .MAGIC_MIME_ENCODING )
17+ m .cookie = magic .magic_open (
18+ magic .MAGIC_NONE | magic .MAGIC_MIME | magic .MAGIC_MIME_ENCODING
19+ )
1720 magic .magic_load (m .cookie , None )
1821 filetype = m .from_buffer (content )
1922 # Work around silliness in libmagic on OpenSUSE 15.1
20- filetype = filetype .replace ('text/x-Algol68;' , 'text/plain;' )
21- if ';' in filetype and 'charset=' in filetype :
22- mimetype , charset = re .split ('; *charset=' , filetype )
23+ filetype = filetype .replace ("text/x-Algol68;" , "text/plain;" )
24+ filetype = filetype .replace ("application/vnd.hp-HPGL;" , "text/plain;" )
25+ if ";" in filetype and "charset=" in filetype :
26+ mimetype , charset = re .split ("; *charset=" , filetype )
2327 else :
24- mimetype = re .split (';' , filetype )[0 ]
25- charset = ' utf-8'
28+ mimetype = re .split (";" , filetype )[0 ]
29+ charset = " utf-8"
2630 return mimetype , charset
27-
You can’t perform that action at this time.
0 commit comments