14 |
14 |
15 def isTextFile(filename): |
15 def isTextFile(filename): |
16 """ |
16 """ |
17 Function to test, if the given file is a text (i.e. editable) file. |
17 Function to test, if the given file is a text (i.e. editable) file. |
18 |
18 |
19 @param filename name of the file to be checked (string) |
19 @param filename name of the file to be checked |
20 @return flag indicating an editable file (boolean) |
20 @type str |
|
21 @return flag indicating an editable file |
|
22 @rtype bool |
21 """ |
23 """ |
22 type_ = mimetypes.guess_type(filename)[0] |
24 type_ = mimetypes.guess_type(filename)[0] |
23 if (type_ is None or |
25 return ( |
|
26 type_ is None or |
24 type_.split("/")[0] == "text" or |
27 type_.split("/")[0] == "text" or |
25 type_ in Preferences.getUI("TextMimeTypes")): |
28 type_ in Preferences.getUI("TextMimeTypes") |
26 return True |
29 ) |
27 else: |
|
28 return False |
|
29 |
30 |
30 |
31 |
31 def mimeType(filename): |
32 def mimeType(filename): |
32 """ |
33 """ |
33 Function to get the mime type of a file. |
34 Function to get the mime type of a file. |
34 |
35 |
35 @param filename name of the file to be checked (string) |
36 @param filename name of the file to be checked |
36 @return mime type of the file (string) |
37 @type str |
|
38 @return mime type of the file |
|
39 @rtype str |
37 """ |
40 """ |
38 return mimetypes.guess_type(filename)[0] |
41 return mimetypes.guess_type(filename)[0] |