Parse the magic.mime file
355569
private static void parse(final Reader r) throws IOException {
		final BufferedReader br = new BufferedReader(r);
		String line;
		final ArrayList<String> sequence = new ArrayList<String>();

		line = br.readLine();
		while (true) {
			if (line == null) {
				break;
			}
			line = line.trim();
			if (line.length() == 0 || line.charAt(0) == '#') {
				line = br.readLine();
				continue;
			}
			sequence.add(line);

			// read the following lines until a line does not begin with '>' or
			// EOF
			while (true) {
				line = br.readLine();
				if (line == null) {
					addEntry(sequence);
					sequence.clear();
					break;
				}
				line = line.trim();
				if (line.length() == 0 || line.charAt(0) == '#') {
					continue;
				}
				if (line.charAt(0) != '>') {
					addEntry(sequence);
					sequence.clear();
					break;
				}
				sequence.add(line);
			}
		}
		if (!sequence.isEmpty()) {
			addEntry(sequence);
		}
	}
238415
def guess_mime (filename):
    
    mime, encoding = guess_mime_file(filename)
    if mime is None:
        mime, encoding = guess_mime_mimedb(filename)
    assert mime is not None or encoding is None
    return mime, encoding
867185
def _ParseYamlFromFile(filedesc):
  """"""
  content = filedesc.read()
  return yaml.Parse(content) or collections.OrderedDict()
265497
private static function _mime_magic(
		string $fname, string $path_to_file=null
	) {
		# with builtin
		if (
			function_exists('mime_content_type') &&
			($mime = @mime_content_type($fname)) &&
			$mime != 'application/octet-stream'
		)
			return $mime;

		# with `file`, skip coverage because `file` is usually
		# not available on CI
		// @codeCoverageIgnoreStart
		if ($path_to_file && is_executable($path_to_file)) {
			$bin = $path_to_file;
		} elseif (!($bin = self::exec("bash -c 'type -p file'")[0])) {
			return 'application/octet-stream';
		}

		if (
			($mimes = self::exec('%s -bip %s', [$bin, $fname])) &&
			preg_match('!^[a-z0-9\-]+/!i', $mimes[0])
		)
			return $mimes[0];

		# giving up
		return 'application/octet-stream';
		// @codeCoverageIgnoreEnd
	}
473521
def retrieve_mime(self):
        
        mime = self.retrieve_config('mime', 'audio')
        mimedict = {"number": mime}
        # the input that parse_for_download expects
        return aux.parse_for_download(mimedict)
157254
def _file_type(file):
    
    # %%%%%%%%%%%%%%%%%%%%%%%%%%%%% Verification of file type %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    if "." in file:  # File with known extension.
        file_type = file.split(".")[-1]
    else:  # File without known extension.
        file_type = magic.from_file(file, mime=True).split("/")[-1]

    return file_type
1176482
def parse(binary, **params):
    """"""
    binary = io.BytesIO(binary)
    collection = list()
    with zipfile.ZipFile(binary, 'r') as zip_:
        for zip_info in zip_.infolist():
            content_type, encoding = mimetypes.guess_type(zip_info.filename)
            content = zip_.read(zip_info)
            content = content_encodings.get(encoding).decode(content)
            content = content_types.get(content_type).parse(content, **params)
            collection.apppend((zip_info.filename, content))
    return collection
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
541763
def get_mime(self, path, isdir):
        ''''''
        if isdir:
            file_type = FOLDER
        else:
            file_type = mimetypes.guess_type(path)[0]
            if not file_type:
                file_type = UNKNOWN
        return file_type
953889
function (mime) {

        var info = {
                type: UNKNOWN,
                format: RAW,
                guessed: true
            },
            match,
            base;

        // extract the mime base
        base = (base = mime.split(SEP)) && base[0] || E;

        // bail out on the mime types that are sure-shot ones with no ambiguity
        match = base.match(AUDIO_VIDEO_IMAGE_TEXT);
        if (match && match[1]) {
            info.type = info.format = match[1];

            // we do special kane matching to extract the format in case the match was text
            // this ensures that we get same formats like we will do in kane match later down the line
            if (info.type === TEXT) {
                match = mime.match(JSON_XML_SCRIPT_SIBLINGS);
                info.format = match && match[1] || PLAIN;
            }
            return info;
        }

        // we do a kane match on entire mime (not just base) to find texts
        match = mime.match(JSON_XML_SCRIPT_SIBLINGS);
        if (match && match[1]) {
            info.type = TEXT;
            info.format = match[1];
            return info;
        }

        // now we match the subtype having names from the sure shot bases
        match = mime.match(AUDIO_VIDEO_IMAGE_TEXT_SUBTYPE);
        if (match && match[1]) {
            info.type = info.format = match[1];
            return info;
        }

        // now that most text and sure-shot types and sub-types are out of our way, we detect standard bases
        // and rest are unknown
        match = base.match(APPLICATION_MESSAGE_MULTIPART);
        if (match && match[1]) {
            info.type = match[1];
            info.format = RAW;
            return info;
        }

        // at this point nothing has matched nothing. it is worth keeping a note of it
        info.orphan = true;
        return info;
    }
1036771
function getMagic() {

	var mmmagic;

	if (magic || magic === false) {
		return magic;
	}

	// Get mmmagic module
	mmmagic = alchemy.use('mmmagic')

	if (mmmagic) {
		magic = new mmmagic.Magic(mmmagic.MAGIC_MIME_TYPE);
	} else {
		log.error('Could not load mmmagic module');
		magic = false;
	}

	return magic;
}
1308192
def _extract_mime_type(params, options) # :nodoc:
      options['resource']  = params['resource'] ? params.delete('resource') : ''
      options['mime_type'] = params['resource'] ? params.delete('mime_type') : ''
    end
390546
def _parse_postmeta(element):
    import phpserialize

    

    metadata = {}
    fields = element.findall("./{%s}postmeta" % WP_NAMESPACE)

    for field in fields:
        key = field.find("./{%s}meta_key" % WP_NAMESPACE).text
        value = field.find("./{%s}meta_value" % WP_NAMESPACE).text

        if key == "_wp_attachment_metadata":
            stream = StringIO(value.encode())
            try:
                data = phpserialize.load(stream)
                metadata["attachment_metadata"] = data
            except ValueError as e:
                pass
            except Exception as e:
                raise(e)

        if key == "_wp_attached_file":
            metadata["attached_file"] = value

    return metadata
95314
def guess_mimetype(filename):
    
    m, encoding = mimetypes.guess_type(filename)
    if encoding:
        m = ENCODING_MIMETYPES.get(encoding, None)
    return m or 'application/octet-stream'
552613
def get_mime_representation(self):
        """"""
        part = deepcopy(self.part)
        part.set_param('maxlinelen', '78', header='Content-Disposition')
        return part
360908
def guess_mimetype (filename, read=None):
    """"""
    mime, encoding = None, None
    if mimedb:
        mime, encoding = mimedb.guess_type(filename, strict=False)
    basename = os.path.basename(filename)
    # Special case for Safari Bookmark files
    if not mime and basename == 'Bookmarks.plist':
        return 'application/x-plist+safari'
    # Special case for Google Chrome Bookmark files.
    if not mime and basename == 'Bookmarks':
        mime = 'text/plain'
    # Some mime types can be differentiated further with content reading.
    if mime in ("text/plain", "application/xml", "text/xml") and read is not None:
        read_mime = guess_mimetype_read(read)
        if read_mime is not None:
            mime = read_mime
    if not mime:
        mime = "application/octet-stream"
    elif ";" in mime:
        # split off not needed extension info
        mime = mime.split(';')[0]
    return mime.strip().lower()
543435
def guess_mime_file_text (file_prog, filename):
    """"""
    cmd = [file_prog, "--brief", filename]
    try:
        output = backtick(cmd).strip()
    except OSError:
        # ignore errors, as file(1) is only a fallback
        return None
    # match output against known strings
    for matcher, mime in FileText2Mime.items():
        if output.startswith(matcher) and mime in ArchiveMimetypes:
            return mime
    return None