File tree Expand file tree Collapse file tree 1 file changed +10
-7
lines changed Expand file tree Collapse file tree 1 file changed +10
-7
lines changed Original file line number Diff line number Diff line change 5
5
import magic
6
6
import re
7
7
8
+
8
9
def get_mime_type (content ):
9
10
# try to fixup encoding
10
11
if hasattr (magic , "open" ):
@@ -13,15 +14,17 @@ def get_mime_type(content):
13
14
filetype = m .buffer (content )
14
15
else :
15
16
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
+ )
17
20
magic .magic_load (m .cookie , None )
18
21
filetype = m .from_buffer (content )
19
22
# 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 )
23
27
else :
24
- mimetype = re .split (';' , filetype )[0 ]
25
- charset = ' utf-8'
28
+ mimetype = re .split (";" , filetype )[0 ]
29
+ charset = " utf-8"
26
30
return mimetype , charset
27
-
You can’t perform that action at this time.
0 commit comments