eric6/Utilities/MimeTypes.py

changeset 6942
2602857055c5
parent 6645
ad476851d7e0
child 7229
53054eb5b15a
equal deleted inserted replaced
6941:f99d60d6b59b 6942:2602857055c5
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2014 - 2019 Detlev Offenbach <detlev@die-offenbachs.de>
4 #
5
6 """
7 Module implementing mimetype dependent functions.
8 """
9
10 from __future__ import unicode_literals
11
12 import mimetypes
13
14 import Preferences
15
16
17 def isTextFile(filename):
18 """
19 Function to test, if the given file is a text (i.e. editable) file.
20
21 @param filename name of the file to be checked (string)
22 @return flag indicating an editable file (boolean)
23 """
24 type_ = mimetypes.guess_type(filename)[0]
25 if (type_ is None or
26 type_.split("/")[0] == "text" or
27 type_ in Preferences.getUI("TextMimeTypes")):
28 return True
29 else:
30 return False
31
32
33 def mimeType(filename):
34 """
35 Function to get the mime type of a file.
36
37 @param filename name of the file to be checked (string)
38 @return mime type of the file (string)
39 """
40 return mimetypes.guess_type(filename)[0]

eric ide

mercurial