Read a single mime.types-format file
430603
function read(file) {
    var data = fs.readFileSync(file, 'ascii');
    // Strip comments
    data = data.replace(/#.*/g, '');
    var lines = data.split('\n');
    for (var i = 0, len = lines.length; i < len; i++) {
        var line = lines[i].trim();
        if (!line) {
            continue;
        }

        var words = line.split(/\s/),
            type = words.shift(),
            suffixes = words;

        for (var j = 0, jen = suffixes.length; j < jen; j++) {
            var suff = suffixes[j].trim();
            if (!suff) {
                continue;
            }

            addType(type, '.' + suff);
        }
    }
}
876245
private static void loadMIMETypesFile(String path) {
        try {
            File f = new File(path);

            logger.debug("Attempting to load MIME types file \"" + path + "\"");
            if (!(f.exists() && f.isFile()))
                logger.debug("Regular file \"" + path + "\" does not exist.");

            else {
                LineNumberReader r = new LineNumberReader(new FileReader(f));
                String line;

                while ((line = r.readLine()) != null) {
                    line = line.trim();

                    if ((line.length() == 0) || (line.startsWith("#")))
                        continue;

                    String[] fields = line.split(" ");

                    // Skip lines without at least two tokens.

                    if (fields.length < 2) continue;

                    // Special case: Scan the extensions, and make sure we
                    // have at least one valid extension. Some .mime.types
                    // files have entries like this:
                    //
                    // mime/type  desc="xxx" exts="jnlp"
                    //
                    // We don't handle those.

                    List<String> extensions = new ArrayList<String>();

                    for (int i = 1; i < fields.length; i++) {
                        if (fields[i].indexOf('=') != -1) continue;
                        if (fields[i].indexOf('"') != -1) continue;

                        // Treat as valid. Remove any leading "."

                        if (fields[i].startsWith(".")) {
                            if (fields[i].length() == 1) continue;

                            fields[i] = fields[i].substring(1);
                        }

                        extensions.add(fields[i]);
                    }

                    if (extensions.size() == 0) continue;

                    // If the MIME type doesn't have a "/", skip it

                    String mimeType = fields[0];
                    String extension;

                    if (mimeType.indexOf('/') == -1) continue;

                    // The first field is the preferred extension. Keep any
                    // existing mapping for the MIME type.

                    if (mimeTypeToExtensionMap.get(mimeType) == null) {
                        extension = extensions.get(0);
                        logger.debug("File \"" + path + "\": " + mimeType
                                + " -> \"" + extension + "\"");

                        mimeTypeToExtensionMap.put(mimeType, extension);
                    }
                }

                r.close();
            }
        } catch (IOException ex) {
            logger.debug("Error reading \"" + path + "\"", ex);
        }
    }
163961
def extract_mime(self, mime, def_mime='unk'):
        
        self['mime'] = def_mime
        if mime:
            self['mime'] = self.MIME_RE.split(mime, 1)[0]
            self['_content_type'] = mime
1150978
def parse_mimetype(cls, value):
        '''
        '''
        match = re.match(r'([a-zA-Z0-9-]+/[a-zA-Z0-9-]+)', value)

        if match:
            return match.group(1)
569136
function getFileTypeReg(type) {
    var map = [],
        ext = ""; // fis.config.get('project.fileType.' + type);
    if (type === 'text') {
        map = TEXT_FILE_EXTS;
    } else if (type === 'image') {
        map = IMAGE_FILE_EXTS;
    } else {
        xgulp.log.error('invalid file type [%s]', type);
    }
    if (ext && ext.length) {
        if (typeof ext === 'string') {
            ext = ext.split(/\s*,\s*/);
        }
        map = map.concat(ext);
    }
    map = map.join('|');
    return new RegExp('\\.(?:' + map + ')$', 'i');
}
1301891
def read(filename):
    
    fname = os.path.join(here, filename)
    with codecs.open(fname, encoding='utf-8') as f:
        return f.read()
1288123
def read(parts):
    
    cur_dir = os.path.abspath(os.path.dirname(__file__))
    with codecs.open(os.path.join(cur_dir, *parts), "rb", "utf-8") as f:
        return f.read()
321124
def readme(fname):
    """"""
    md = open(os.path.join(os.path.dirname(__file__), fname)).read()
    output = md
    try:
        import pypandoc
        output = pypandoc.convert(md, 'rst', format='md')
    except ImportError:
        pass
    return output
125149
public static String findMimeType( File imgFile ) {

		String result;
		String name = imgFile.getName().toLowerCase();
		if( name.endsWith( ".jpg" ) || name.endsWith( ".jpeg" ))
			result = MIME_JPG;
		else if( name.endsWith( ".gif" ))
			result = MIME_GIF;
		else if( name.endsWith( ".png" ))
			result = MIME_PNG;
		else if( name.endsWith( ".svg" ))
			result = MIME_SVG;
		else
			result = MIME_BINARY;

		return result;
	}
910291
function getTypeFromFileExtension(url) {
	url = url.toLowerCase().split('?')[0];
	var _ext = url.substring(url.lastIndexOf('.') + 1);
	var _av = /mp4|m4v|ogg|ogv|m3u8|webm|webmv|wmv|mpeg|mov/gi.test(_ext) ? 'video/' : 'audio/';

	switch (_ext) {
		case 'mp4':
		case 'm4v':
		case 'm4a':
			return _av + 'mp4';
		case 'webm':
		case 'webma':
		case 'webmv':
			return _av + 'webm';
		case 'ogg':
		case 'oga':
		case 'ogv':
			return _av + 'ogg';
		case 'm3u8':
			return 'application/x-mpegurl';
		case 'ts':
			return _av + 'mp2t';
		default:
			return _av + _ext;
	}
}
789624
def read_single_xso(src, type_):
    

    result = None

    def cb(instance):
        nonlocal result
        result = instance

    read_xso(src, {type_: cb})

    return result
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)
1373969
def parse(cls, mimetype):
        
        plist = mimetype.split(';')

        main_type, _, sub_type = plist.pop(0).lower().strip().partition('/')
        params = {}

        for p in plist:
            kv = p.split('=')
            if len(kv) != 2:
                continue
            v = kv[1].strip()
            if v:
                params[kv[0].strip()] = v

        return MimeType(main_type, sub_type, params)
119523
static function guessMimeType($file, $def = 'application/octet-stream')
	{
		// extract file extension (after . symbol)
		$ext = substr(strrchr(strtolower($file), '.'), 1);
	
		switch ( $ext )
		{
			case 'gif':
			case 'jpeg':
			case 'png':
				return "image/$ext";
			case 'jpg':
				return 'image/jpeg';
			case 'mp4':
			case 'mpeg':
			case 'avi':
				return "video/$ext";
			case 'mp3':
				return 'audio/mpeg3';
			case 'wav':
				return 'audio/wav';
			case 'pdf':
				return 'application/pdf';
			case 'htm':
			case 'html':
				return 'text/html';
			case 'txt':
				return 'text/plain';
			case 'eml':
				return 'message/rfc822';
			case 'doc':
				return 'application/msword';
			case 'docx':
				return 'application/vnd.openxmlformats-officedocument.wordprocessingml.document';
			case 'xls':
				return 'application/vnd.ms-excel';
			case 'xlsx':
				return 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet';
			case 'ppt':
			case 'pps':
				return 'application/vnd.ms-powerpoint';
			case 'pptx':
			case 'ppsx':
				return 'application/vnd.openxmlformats-officedocument.presentationml.presentation';
			case 'odt':
				return 'application/vnd.oasis.opendocument.text';
			case 'ods':
				return 'application/vnd.oasis.opendocument.spreadsheet';
			case 'odp':
				return 'application/vnd.oasis.opendocument.presentation';
			case 'zip':
				return 'application/zip';
			default :
				return $def;
		}
	}
1059947
def reads(s, filename=None, loader=None, implicit_tuple=True, allow_errors=False):
  """"""
  return ast.reads(s,
      filename=filename or '<input>',
      loader=loader or default_loader,
      implicit_tuple=implicit_tuple,
      allow_errors=allow_errors)
240862
def read_message_type(file):
    """"""
    message_byte = file.read(1)
    if message_byte == b'':
        return ConnectionClosed
    message_number = message_byte[0]
    return _message_types.get(message_number, UnknownMessage)
535036
def sanitize_mimetype(mimetype, filename=None):
    """"""
    # Allow some few mime type like plain text, images and audio.
    if mimetype in MIMETYPE_WHITELIST:
        return mimetype
    # Rewrite HTML, JavaScript, CSS etc to text/plain.
    if mimetype in MIMETYPE_PLAINTEXT or \
            (filename and filename.lower() in MIMETYPE_TEXTFILES):
        return 'text/plain'
    # Default
    return 'application/octet-stream'