code: def ad_hoc_magic_from_file(filename, **kwargs):
      
      with open(filename, 'rb') as stream:
          head = stream.read(16)
          if head[:4] == b'\x7fELF':
              return b'application/x-executable'
          elif head[:2] == b'MZ':
              return b'application/x-dosexec'
          else:
              raise NotImplementedError()
docs: Ad-hoc emulation of magic.from_file from python-magic.