Guesses the mime type of a file. If mime type cannot be detected, plain
        text is assumed.

        :param path: path of the file
        :return: the corresponding mime type.
435978
def get_mimetype(path):
        
        filename = os.path.split(path)[1]
        mimetype = mimetypes.guess_type(filename)[0]
        if mimetype is None:
            mimetype = 'text/x-plain'
        _logger().debug('mimetype detected: %s', mimetype)
        return mimetype
798230
def mimetype(path)
      extension = File.basename(path).split('.')[-1]
      Rack::Mime.mime_type(".#{extension}")
    end
1264883
def _detect_content_type(self, filename):
        '''
        '''
        name, ext = os.path.splitext(filename)
        if not ext:
            raise MessageError('File requires an extension.')
        ext = ext.lower()
        if ext.lstrip('.') in self._banned_extensions:
            err = 'Extension "{0}" is not allowed.'
            raise MessageError(err.format(ext))
        if not mimetypes.inited:
            mimetypes.init()
        return mimetypes.types_map.get(ext, self._default_content_type)
629170
private String getMIMEType(String path) {
        String extension = getFileExtension(path);

        if (extension == null) {
            return FILE_TRANSFER_BINARY_MIME;
        }

        if ("zip".equals(extension) || "ear".equals(extension) || "war".equals(extension) || "jar".equals(extension) || "eba".equals(extension)) {
            return FILE_TRANSFER_ZIP_MIME;

        } else if ("pax".equals(extension)) {
            return FILE_TRANSFER_PAX_MIME;

        } else if ("gz".equals(extension) || "gzip".equals(extension)) {

            return FILE_TRANSFER_GZIP_MIME;

        } else if ("tar".equals(extension)) {
            return FILE_TRANSFER_TAR_MIME;

        } else if ("txt".equals(extension) || "log".equals(extension) || "trace".equals(extension) || "properties".equals(extension)) {
            return FILE_TRANSFER_TEXT_MIME;

        } else if ("xml".equals(extension) || "xslt".equals(extension) || "xsl".equals(extension)) {
            return FILE_TRANSFER_XML_MIME;

        } else if ("html".equals(extension) || "htm".equals(extension)) {
            return FILE_TRANSFER_HTML_MIME;

        } else {
            return FILE_TRANSFER_BINARY_MIME;
        }
    }
187459
def _get_content_type(self, file):
        
        if file.mimetype:
            return file.mimetype

        # get file extension
        _, extension = os.path.splitext(file.name)
        extension = extension.strip('.')

        # Make an educated guess about what the Content-Type should be.
        return media_types[extension] if extension in media_types else 'binary/octet-stream'
856580
public static function guessMimeType($path, $content)
    {
        $mimeType = MimeType::getMimeTypeByContent($content);

        if (!(null === $mimeType || \in_array($mimeType, ['application/x-empty', 'text/plain', 'text/x-asm'], true))) {
            return $mimeType;
        }

        return MimeType::getMimeType($path) ?? 'text/plain';
    }
244912
def mime_type
      guesses = MIME::Types.type_for(self.name) rescue []
      guesses.first ? guesses.first.simplified : DEFAULT_MIME_TYPE
    end
1123460
def read(self, path, encoding=None):
        
        b = common.read(path)

        if encoding is None:
            encoding = self.file_encoding

        return self.unicode(b, encoding)
88098
def check_file_encoding(self, input_file_path):
        
        self.log([u"Checking encoding of file '%s'", input_file_path])
        self.result = ValidatorResult()
        if self._are_safety_checks_disabled(u"check_file_encoding"):
            return self.result
        if not gf.file_can_be_read(input_file_path):
            self._failed(u"File '%s' cannot be read." % (input_file_path))
            return self.result
        with io.open(input_file_path, "rb") as file_object:
            bstring = file_object.read()
            self._check_utf8_encoding(bstring)
        return self.result
106803
def identify_link_type(filename):
    '''
    '''
    mime_type = mimetypes.guess_type(filename)[0]

    if not mime_type:
        return

    if mime_type == 'text/css':
        return LinkType.css
    elif mime_type == 'application/javascript':
        return LinkType.javascript
    elif mime_type == 'text/html' or mime_type.endswith('xml'):
        return LinkType.html
    elif mime_type.startswith('video') or \
            mime_type.startswith('image') or \
            mime_type.startswith('audio') or \
            mime_type.endswith('shockwave-flash'):
        return LinkType.media
166510
def get_mimetype(self, path):
        '''
        
        '''
        for fnc in self._mimetype_functions:
            mime = fnc(path)
            if mime:
                return mime
        return mimetype.by_default(path)
371404
function mimeType( path ) {
	var extension = path.replace( /.*[./\\]/ , '' ).toLowerCase() ;

	if ( ! mimeType.extension[ extension ] ) {
		// default MIME type, when nothing is found
		return 'application/octet-stream' ;
	}

	return mimeType.extension[ extension ] ;
}
10873
def get_description_type(path=PKG_DESCRIBE):
    
    _, ext = os.path.splitext(path)
    return {
        ".rst": "text/x-rst",
        ".txt": "text/plain",
        ".md": "text/markdown",
    }[ext]
775837
def filesys_decode(path):
    

    if isinstance(path, six.text_type):
        return path

    fs_enc = sys.getfilesystemencoding() or 'utf-8'
    candidates = fs_enc, 'utf-8'

    for enc in candidates:
        try:
            return path.decode(enc)
        except UnicodeDecodeError:
            continue
23672
def get_content_type(local_file_path)
      png = Regexp.new("\x89PNG".force_encoding("binary"))
      jpg = Regexp.new("\xff\xd8\xff\xe0\x00\x10JFIF".force_encoding("binary"))
      jpg2 = Regexp.new("\xff\xd8\xff\xe1(.*){2}Exif".force_encoding("binary"))
      case IO.read(local_file_path, 10)
      when /^GIF8/
        'image/gif'
      when /^#{png}/
        'image/png'
      when /^#{jpg}/
        'image/jpeg'
      when /^#{jpg2}/
        'image/jpeg'
      else
        if local_file_path.end_with? '.txt'
          'text/plain'
        else
          'application/octet-stream'
        end
        # mime_type = `file #{local_file_path} --mime-type`.gsub("\n", '') # Works on linux and mac
        # raise UnprocessableEntity, "unknown file type" if !mime_type
        # mime_type.split(':')[1].split('/')[1].gsub('x-', '').gsub(/jpeg/, 'jpg').gsub(/text/, 'txt').gsub(/x-/, '')
      end
    end
1353966
def mimetype_from_path(path):
    
    extension = file_extension(path)
    if extension is not None:
        extension = extension.lower()
        if extension in gc.MIMETYPE_MAP:
            return gc.MIMETYPE_MAP[extension]
    return None
785912
def mime_type(self, path):
        """"""
        name, ext = os.path.splitext(path)
        return MIME_TYPES[ext]