code: def guess_mime_file (filename):
      
      mime, encoding = None, None
      base, ext = os.path.splitext(filename)
      if ext.lower() in ('.alz',):
          # let mimedb recognize these extensions
          return mime, encoding
      if os.path.isfile(filename):
          file_prog = find_program("file")
          if file_prog:
              mime, encoding = guess_mime_file_mime(file_prog, filename)
              if mime is None:
                  mime = guess_mime_file_text(file_prog, filename)
                  encoding = None
      if mime in Mime2Encoding:
          # try to look inside compressed archives
          cmd = [file_prog, "--brief", "--mime", "--uncompress", filename]
          try:
              outparts = backtick(cmd).strip().split(";")
          except OSError:
              # ignore errors, as file(1) is only a fallback
              return mime, encoding
          mime2 = outparts[0].split(" ", 1)[0]
          # Some file(1) implementations return an empty or unknown mime type
          # when the uncompressor program is not installed, other
          # implementation return the original file type.
          # The following detects both cases.
          if (mime2 in ('application/x-empty', 'application/octet-stream') or
              mime2 in Mime2Encoding):
              # The uncompressor program file(1) uses is not installed
              # or is not able to uncompress.
              # Try to get mime information from the file extension.
              mime2, encoding2 = guess_mime_mimedb(filename)
              if mime2 in ArchiveMimetypes:
                  mime = mime2
                  encoding = encoding2
          elif mime2 in ArchiveMimetypes:
              mime = mime2
              encoding = get_file_mime_encoding(outparts)
      # Only return mime and encoding if the given mime can natively support the encoding.
      if program_supports_compression(ArchiveMimetypes.get(mime), encoding):
          return mime, encoding
      else:
          # If encoding is None, default back to `mime`.
          return Encoding2Mime.get(encoding, mime), None
docs: Determine MIME type of filename with file(1):
       (a) using `file --mime`
       (b) using `file` and look the result string
      @return: tuple (mime, encoding)