o
    j|,                     @   s  U d Z ddlmZ dZeeeef df ed< dZdZ	eedf ed< d	d
ddZ
eeef ed< dddZeeef ed< dZdZdZeeeef df ed< dZeeeef df ed< eh dZee ed< dZdZeddhZee ed< eddhZee ed < ed!d"hZee ed#< eh d$Zee ed%< ed&hZee ed'< d(Zd)Zd*ed+efd,d-Zd.ed+efd/d0Zd*ed+ed1B fd2d3Zd1S )4zMagic number detection for binary file types.

Note: ``from __future__ import annotations`` is intentionally omitted because
this module is compiled with mypyc, which does not support PEP 563 string
annotations.
    DetectionResult)()s   PNG

z	image/png)s   GIF87a	image/gif)s   GIF89ar   )s   MM *
image/tiff)s   II* r   )s   8BPSzimage/vnd.adobe.photoshop)s   qoifz	image/qoi)s   BMz	image/bmp)s   z
image/jpeg)s      JXL 

	image/jxl)s   
r   )s      zimage/vnd.microsoft.icon)s   ID3z
audio/mpeg)s   MThdz
audio/midi)s   OggSz	audio/ogg)s   fLaCz
audio/flac)s   Eߣz
video/webm)s   zapplication/gzip)s   BZhzapplication/x-bzip2)s   7zXZ zapplication/x-xz)s   7z'zapplication/x-7z-compressed)s   Rar! application/vnd.rar)s   Rar! r   )s   (/zapplication/zstd)s   %PDF-zapplication/pdf)s   SQLite format 3 zapplication/x-sqlite3)s   ARROW1z!application/vnd.apache.arrow.file)s   PAR1zapplication/vnd.apache.parquet)s    asmzapplication/wasm)s   dex
zapplication/vnd.android.dex)s   ELFzapplication/x-elf)s   application/x-mach-binary)s   r   )s   r   )s   r   )s   MZz-application/vnd.microsoft.portable-executable)s   wOFFz	font/woff)s   wOF2z
font/woff2)s   OTTOzfont/otf)s      zfont/ttf._MAGIC_NUMBERSi  )s   ustar s   ustar _TAR_SIGNATURESz
image/webpz	audio/wavzvideo/x-msvideo)s   WEBPs   WAVEs   AVI _RIFF_SUBTYPESz
audio/aiff)s   AIFFs   AIFC_FORM_SUBTYPESs   PKi   ))s   xl/zAapplication/vnd.openxmlformats-officedocument.spreadsheetml.sheet)s   word/zGapplication/vnd.openxmlformats-officedocument.wordprocessingml.document)s   ppt/zIapplication/vnd.openxmlformats-officedocument.presentationml.presentation)s   META-INF/MANIFEST.MFzapplication/java-archive)s   AndroidManifest.xmlz'application/vnd.android.package-archive)s   META-INF/container.xmlzapplication/epub+zip_ZIP_FILENAME_PREFIXES))s   .dist-info/zapplication/x-wheel+zip_ZIP_FILENAME_SUFFIXES>   '   application/vnd.oasis.opendocument.text+   application/vnd.oasis.opendocument.graphics.   application/vnd.oasis.opendocument.spreadsheet/   application/vnd.oasis.opendocument.presentation_OPENDOCUMENT_MIMESs   ftyp   s   avifs   avis_FTYP_AVIF_BRANDSs   heics   heix_FTYP_HEIC_BRANDSs   mif1s   msf1_FTYP_HEIF_BRANDS>      F4A    M4A    M4B _FTYP_AUDIO_BRANDSs   qt  _FTYP_QUICKTIME_BRANDSs      datareturnc                 C   s  | dt  }d}	 |t|}|dkst||d k r	 dS t||d |d  d}t||d |d  d}|d }t||| k rI	 dS ||||  }tD ]\}}	||r`|	  S qStD ]\}
}	|
|v ro|	  S qc|d	krt||d
 |d  d}|dkr|| | }t||d |d  d}t||| kr||||  }|t	v r|
dS t||d |d
  d}|d
@ rdnt||d |d  d}|| | | }q	)a  Classify a ZIP file by scanning entry filenames and content.

    Scans for local file header signatures within the first
    ``_ZIP_SCAN_LIMIT`` bytes.  For each entry, checks the filename
    against known prefixes/suffixes, and for ``mimetype`` entries reads
    the uncompressed content to detect OpenDocument formats.

    **Limitation:** when an entry has the data-descriptor flag (bit 3)
    set, the compressed size in the header is 0 and we cannot skip past
    the entry content.  The scan may find spurious PK local file header
    signatures inside compressed data.  In practice deflate output rarely produces
    valid ZIP local file headers with recognizable filenames, so false
    positives are unlikely.
    Nr   T         littles   mimetype   
      ascii      zapplication/zip)_ZIP_SCAN_LIMITfind_ZIP_SIGNATURElenint
from_bytesr   
startswithr   r   decode)r   scanoffsetidxname_len	extra_len
name_startnameprefixmimesuffixcompressioncontent_startcontent_lencontentflagscontent_size rC   \/var/www/html/fyndo/pharma/fyndo/venv/lib/python3.10/site-packages/chardet/pipeline/magic.py_classify_zip   sH   #

&rE   r;   c                 C   s   t d dd | dS )Ng      ?)encoding
confidencelanguage	mime_typer   )r;   rC   rC   rD   _make_result   s   rJ   Nc                 C   s  | sdS t | dkr^| ttd  tkr^t| dd d}d|  kr*t | kr^n n2| dd }|tv r:tdS |tv rBtdS |tv rJtdS |t	v rRtd	S |t
v rZtd
S tdS | dd dkr}t | dkr}t| dd }|dur}t|S | dd dkrt | dkrt| dd }|durt|S | trtt| S | dd tkrt | dkrt| dd d}|tkrtdS tdS tD ]\}}| |rt|  S qt | td kr| ttd  }|tv rtdS dS )zCheck *data* for known binary file magic numbers.

    :param data: The raw byte data to examine.
    :returns: A :class:`DetectionResult` with ``encoding=None`` and the
        identified MIME type, or ``None`` if no magic number matches.
    N   r   bigr%   z
image/avifz
image/heicz
image/heifz	audio/mp4zvideo/quicktimez	video/mp4s   RIFFs   FORMr   zapplication/java-vmr)   zapplication/x-tar)r.   _FTYP_OFFSET_FTYP_MARKERr/   r0   r   rJ   r   r   r   r   r   getr   r1   r-   rE   	_CAFEBABE_CAFEBABE_MAX_FAT_ARCHESr	   _TAR_OFFSETr
   )r   box_sizebrandsubtype	nfat_archr:   r;   tar_sigrC   rC   rD   detect_magic   sR    

rX   )__doc__chardet.pipeliner   r	   tuplebytesstr__annotations__rR   r
   r   dictr   r-   r+   r   r   	frozensetr   rN   rM   r   r   r   r   r   rP   rQ   rE   rJ   rX   rC   rC   rC   rD   <module>   s>    ;

: