Utilities/MimeTypes.py

Thu, 29 Jun 2017 18:51:03 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Thu, 29 Jun 2017 18:51:03 +0200
branch
maintenance
changeset 5776
49ba4a9f0421
parent 5389
9b1c800daff3
child 6048
82ad8ec9548c
permissions
-rw-r--r--

Fixed an issue in the single application client.
(grafted from 3a8bedba97ab2185b912f3e0614c8b3bb9074b3f)

# -*- coding: utf-8 -*-

# Copyright (c) 2014 - 2017 Detlev Offenbach <detlev@die-offenbachs.de>
#

"""
Module implementing mimetype dependent functions.
"""

from __future__ import unicode_literals

import mimetypes

import Preferences


def isTextFile(filename):
    """
    Function to test, if the given file is a text (i.e. editable) file.
    
    @param filename name of the file to be checked (string)
    @return flag indicating an editable file (boolean)
    """
    type_ = mimetypes.guess_type(filename)[0]
    if (type_ is None or
        type_.split("/")[0] == "text" or
            type_ in Preferences.getUI("TextMimeTypes")):
        return True
    else:
        return False


def mimeType(filename):
    """
    Function to get the mime type of a file.
    
    @param filename name of the file to be checked (string)
    @return mime type of the file (string)
    """
    return mimetypes.guess_type(filename)[0]

eric ide

mercurial