Returns a string that describes the type of file, for common Android
    specific formats
501317
def is_android_raw(raw):
    
    val = None

    # We do not check for META-INF/MANIFEST.MF,
    # as you also want to analyze unsigned APKs...
    # AndroidManifest.xml should be in every APK.
    # classes.dex and resources.arsc are not required!
    # if raw[0:2] == b"PK" and b'META-INF/MANIFEST.MF' in raw:
    # TODO this check might be still invalid. A ZIP file with stored APK inside would match as well.
    # probably it would be better to rewrite this and add more sanity checks.
    if raw[0:2] == b"PK" and b'AndroidManifest.xml' in raw:
        val = "APK"
    elif raw[0:3] == b"dex":
        val = "DEX"
    elif raw[0:3] == b"dey":
        val = "DEY"
    elif raw[0:4] == b"\x03\x00\x08\x00" or raw[0:4] == b"\x00\x00\x08\x00":
        val = "AXML"
    elif raw[0:4] == b"\x02\x00\x0C\x00":
        val = "ARSC"

    return val
334976
def determine_file_type(filename):
    
    if filename.endswith('.cls'):
        return FileType.CLS
    elif filename.endswith('.go'):
        return FileType.GO
    elif filename.endswith('.java'):
        return FileType.JAVA
    elif filename.endswith('.js'):
        return FileType.JAVASCRIPT
    elif filename.endswith('.php'):
        return FileType.PHP
    elif filename.endswith('.py'):
        return FileType.PYTHON
    elif (
        filename.endswith(
            ('.yaml', '.yml'),
        )
    ):
        return FileType.YAML
    return FileType.OTHER
105802
public static function determineContentType($ext = '', $content = '', $local_file = '', $default = '')
    {
        self::initMimeTypes();

        $defaultMime = 'application/octet-stream';

        if ( ! empty($default))
        {
            $defaultMime = $default;
        }

        $mime = '';

        if (class_exists('finfo'))
        {
            $fileInfo = new finfo(FILEINFO_MIME_TYPE);
            if ( ! empty($content))
            {
                $mime = $fileInfo->buffer($content);
            }
            elseif ( ! empty($local_file))
            {
                $mime = $fileInfo->file($local_file);
            }
        }

        if (empty($mime) ||
            (0 === strcasecmp($mime, $defaultMime)) ||
            (0 === strcasecmp('text/plain', $mime)) ||
            (0 === strcasecmp('text/x-asm', $mime)) ||
            (0 === strcasecmp('text/x-c', $mime)) ||
            (0 === strcasecmp('text/x-c++', $mime)) ||
            (0 === strcasecmp('text/x-java', $mime))
        )
        {
            if (0 === strcasecmp('dfpkg', $ext))
            {
                $mime = 'application/zip';
            }
            else
            {
                $mime = Arr::get(self::$mimeTypes, $ext);
            }
        }
        if (empty($mime))
        {
            return $defaultMime;
        }

        return $mime;
    }
806397
def determine_file_type(self, z):
        """"""

        content = z.read('[Content_Types].xml')
        with io.BytesIO(content) as b:
            encoding = self._analyze_file(b)
            if encoding is None:
                encoding = 'utf-8'
            b.seek(0)
            text = b.read().decode(encoding)
            soup = bs4.BeautifulSoup(text, 'xml')
            for o in soup.find_all('Override'):
                name = o.attrs.get('PartName')
                for k, v in MIMEMAP.items():
                    if name.startswith('/{}/'.format(k)):
                        self.type = v
                        break
                if self.type:
                    break
        self.filepattern = DOC_PARAMS[self.type]['filepattern']
        self.namespaces = DOC_PARAMS[self.type]['namespaces']
        self.captures = sv.compile(DOC_PARAMS[self.type]['captures'], DOC_PARAMS[self.type]['namespaces'])
128445
def get_filetypes(filelist, path=None, size=os.path.getsize):
    
    path = path or (lambda _: _)

    # Get total size for each file extension
    histo = defaultdict(int)
    for entry in filelist:
        ext = os.path.splitext(path(entry))[1].lstrip('.').lower()
        if ext and ext[0] == 'r' and ext[1:].isdigit():
            ext = "rar"
        elif ext == "jpeg":
            ext = "jpg"
        elif ext == "mpeg":
            ext = "mpg"
        histo[ext] += size(entry)

    # Normalize values to integer percent
    total = sum(histo.values())
    if total:
        for ext, val in histo.items():
            histo[ext] = int(val * 100.0 / total + .499)

    return sorted(zip(histo.values(), histo.keys()), reverse=True)
555304
def fileName(self):
        
        if self._filename:
            return self._filename
        
        filename = nativestring(super(XSettings, self).fileName())
        if self._customFormat:
            filename, ext = os.path.splitext(filename)
            filename += '.' + self._customFormat.extension()
        return filename
481320
def determine_type(filename):
    ''''''
    ftype = magic.from_file(filename, mime=True).decode('utf8')
    if ftype == 'text/plain':
        ftype = 'text'
    elif ftype == 'image/svg+xml':
        ftype = 'svg'
    else:
        ftype = ftype.split('/')[1]
    return ftype
809704
def type_string(self):
        """"""
        if self.is_tuple:
            subtypes = [item.type_string for item in self.children]
            return '{}({})'.format(
                '' if self.val_guaranteed else '*',
                ', '.join(subtypes))
        elif self.is_list:
            return '{}[{}]'.format(
                '' if self.val_guaranteed else '*',
                self.children[0].type_string)
        else:
            return '{}{}'.format(
                '' if self.val_guaranteed else '*',
                self.type_.__name__)
816383
public static String fileExtensionForMIMEType(String mimeType) {
        loadMappings();

        String ext = mimeTypeToExtensionMap.get(mimeType);

        if (ext == null) ext = "dat";

        return ext;
    }
647872
private static DumpContentType guessDumpContentType(String fileName) {
		String lcDumpName = fileName.toLowerCase();
		if (lcDumpName.contains(".json.gz")) {
			return DumpContentType.JSON;
		} else if (lcDumpName.contains(".json.bz2")) {
			return DumpContentType.JSON;
		} else if (lcDumpName.contains(".sql.gz")) {
			return DumpContentType.SITES;
		} else if (lcDumpName.contains(".xml.bz2")) {
			if (lcDumpName.contains("daily")) {
				return DumpContentType.DAILY;
			} else if (lcDumpName.contains("current")) {
				return DumpContentType.CURRENT;
			} else {
				return DumpContentType.FULL;
			}
		} else {
			logger.warn("Could not guess type of the dump file \"" + fileName
					+ "\". Defaulting to json.gz.");
			return DumpContentType.JSON;
		}
	}
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;
        }
    }
393320
public static String fileTypeAsString( int fileType ) {

		String result;
		switch( fileType ) {
		case AGGREGATOR:
			result = "aggregator";
			break;

		case GRAPH:
			result = "graph";
			break;

		case INSTANCE:
			result = "intsnace";
			break;

		case UNDETERMINED:
			result = "undetermined";
			break;

		default:
			result = "unknown";
			break;
		}

		return result;
	}
377783
def _guess_file_type(self, filename):
        

        # First attempt to guess from the file name.
        namelc = filename.lower()

        if namelc.endswith('.fits') or namelc.endswith('.fit'):
            return 'fits'
        elif namelc.endswith('.json'):
            return 'json'
        elif namelc.endswith('.txt') or namelc.endswith('.ascii'):
            return 'ascii'

        # Otherwise, if the file exists, look at the first character.
        if isfile(filename):
            with open(filename, 'r') as f:
                c = f.read(1)

            if c == 'S':
                return 'fits'
            elif c == '{':
                return 'json'
            elif c.isdigit():
                return 'ascii'

        raise ValueError('Unable to determine format of {0}'.format(filename))
673539
def detect_format(filename):
    
    filename = Path(filename)

    if filename.suffix == '.csv':
        recformat = 'csv'
    elif filename.suffix == '.sfp':
        recformat = 'sfp'

    else:
        recformat = 'unknown'

    return recformat
1258280
function getParseType (file) {
  let ext = path.extname(file)

  for (let type in FILE_TYPE_MAP) {
    let exts = FILE_TYPE_MAP[type]

    if (exts.indexOf(ext) >= 0) {
      return type
    }
  }
}
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'
914399
def show_filetypes(extensions):
	
	for item in extensions.items():
		val = item[1]
		if type(item[1]) == list:
			val = ", ".join(str(x) for x in item[1])
		print("{0:4}: {1}".format(val, item[0]))