
    Ngt:                        d Z ddlZddlZddlZddlZddlZddlZddlmZmZm	Z	m
Z
mZmZ eZ G d de          Z G d d          Zi Zd Zd9d
Zd9dZd9dZddlmZ  ej                    Zej
        Zd Zd Zd Z	 ddlm Z  d Z!n# e"$ r d Z!Y nw xY wd Z#ej$        Z$ee$_%        ege$_&        ej'        Z'de'_%        ege'_&        ej(        Z(ee(_%        ege(_&        ej)        Z)ee)_%        ege)_&        ej*        Z+ee+_%        eege+_&        ee+_,        d Z*ej-        Z.ee._%        ee
e	ge._&        ee._,        d Z-ej/        Z/ee/_%        eege/_&        ee/_,        ej/        Z0ee0_%        eege0_&        ee0_,        d Z/ej1        Z2ee2_%        eege2_&        ee2_,        d Z1ej3        Z3ee3_%        eege3_&        ej4        Z4ee4_%        eege4_&        ej5        Z5ee5_%        eege5_&        d	Z6 e7ed          r^ e7ed          rRdZ6ej8        Z9ee9_%        ee ee	          ge9_&        ee9_,        ej:        Z;ee;_%        ee ee	          ge;_&        ee;_,        d Z8d Z:d	Z< e7ed          rdZ<ej=        Z=ee=_%        g e=_&        d  Z>dZ?dZ@d!ZAd"ZBd#ZCd$ZDd%ZEd$ZFd&ZGd'ZHd(ZId)ZJd*ZKd+ZLd,ZMd-ZNd.ZOd/ZPd0ZQd1ZRd2ZSd3ZTd4ZUdZVdZWd!ZXd5ZYd"ZZd6Z[d7Z\d8 Z] e] e^                       dS ):ai  
magic is a wrapper around the libmagic file identification library.

See README for more information.

Usage:

>>> import magic
>>> magic.from_file("testdata/test.pdf")
'PDF document, version 1.2'
>>> magic.from_file("testdata/test.pdf", mime=True)
'application/pdf'
>>> magic.from_buffer(open("testdata/test.pdf").read(1024))
'PDF document, version 1.2'
>>>

    N)c_char_pc_intc_size_tc_void_pbyrefPOINTERc                        e Zd Z fdZ xZS )MagicExceptionc                 f    t          t          |                               |           || _        d S N)super	Exception__init__message)selfr   	__class__s     J/var/www/html/ai-engine/env/lib/python3.11/site-packages/magic/__init__.pyr   zMagicException.__init__!   s,    i''000    )__name__
__module____qualname__r   __classcell__)r   s   @r   r
   r
       s8                r   r
   c                   H    e Zd ZdZ	 	 ddZd Zd Zd Zd Zd	 Z	d
 Z
d ZdS )Magicz;
    Magic is a wrapper around the libmagic C library.
    FNc                    t           | _        |r| xj        t          z  c_        |r| xj        t          z  c_        |r| xj        t          z  c_        |r| xj        t
          z  c_        |r| xj        t          z  c_        |r| xj        t          z  c_        t          | j                  | _	        t          j                    | _        t          | j	        |           |r(t          rt                      dk     rt!          d          t"          r6	 |                     t&          d           dS # t(          $ r}Y d}~dS d}~ww xY wdS )a  
        Create a new libmagic wrapper.

        mime - if True, mimetypes are returned instead of textual descriptions
        mime_encoding - if True, codec is returned
        magic_file - use a mime database other than the system default
        keep_going - don't stop at the first match, keep going
        uncompress - Try to look inside compressed files.
        raw - Do not try to decode "non-printable" chars.
        extension - Print a slash-separated list of valid extensions for the file type found.
        i  z<MAGIC_EXTENSION is not supported in this version of libmagic@   N)
MAGIC_NONEflagsMAGIC_MIME_TYPEMAGIC_MIME_ENCODINGMAGIC_CONTINUEMAGIC_COMPRESS	MAGIC_RAWMAGIC_EXTENSION
magic_opencookie	threadingLocklock
magic_load_has_versionversionNotImplementedError
_has_paramsetparamMAGIC_PARAM_NAME_MAXr
   )	r   mime
magic_filemime_encoding
keep_going
uncompressraw	extensiones	            r   r   zMagic.__init__+   s^     
 	*JJ/)JJ 	.JJ--JJ 	)JJ.(JJ 	)JJ.(JJ 	$JJ)#JJ 	*JJ/)JJ ,,N$$	4;
+++  	fl 	fgii#oo%&deee  	2B77777!    	 	s   D, ,
E<Ec                 x   | j         5  	 t          |          t          k    r't          t          k    r|                    dd          }t          t          | j        |                    cddd           S # t          $ r+}| 	                    |          cY d}~cddd           S d}~ww xY w# 1 swxY w Y   dS )z0
        Identify the contents of `buf`
        utf-8replace)errorsN)
r)   typestrbytesencodemaybe_decodemagic_bufferr&   r
   _handle509Bug)r   bufr8   s      r   from_bufferzMagic.from_buffer^   s%    Y 
	- 
	-	-
 99##u**WY*??C#Lc$B$BCC
	- 
	- 
	- 
	- 
	- 
	- 
	- 
	- " - - -))!,,,,,,,
	- 
	- 
	- 
	- 
	- 
	- 
	- 
	--
	- 
	- 
	- 
	- 
	- 
	- 
	- 
	- 
	- 
	-s;   B/A A77
B,B'B,B/'B,,B//B36B3c                 J   t          |          5  	 d d d            n# 1 swxY w Y   | j        5  	 t          t          | j        |                    cd d d            S # t
          $ r+}|                     |          cY d }~cd d d            S d }~ww xY w# 1 swxY w Y   d S r   )
_real_openr)   rA   r2   r&   r
   rC   )r   filenamer8   s      r   	from_filezMagic.from_filen   s[   !! 	 		 	 	 	 	 	 	 	 	 	 	 	 	 	 	 Y 	- 	--#Jt{H$E$EFF	- 	- 	- 	- 	- 	- 	- 	- " - - -))!,,,,,,,		- 	- 	- 	- 	- 	- 	- 	--	- 	- 	- 	- 	- 	- 	- 	- 	- 	-sF   ""B!A  
B*B>B?BBBBBc                     | j         5  	 t          t          | j        |                    cd d d            S # t          $ r+}|                     |          cY d }~cd d d            S d }~ww xY w# 1 swxY w Y   d S r   )r)   rA   magic_descriptorr&   r
   rC   )r   fdr8   s      r   from_descriptorzMagic.from_descriptory   s    Y 	- 	--#$4T["$E$EFF	- 	- 	- 	- 	- 	- 	- 	- " - - -))!,,,,,,,		- 	- 	- 	- 	- 	- 	- 	--	- 	- 	- 	- 	- 	- 	- 	- 	- 	-s8   A0!8
A-A(A-A0(A--A00A47A4c                 6    |j         | j        t          z  rdS |)Nzapplication/octet-stream)r   r   r   )r   r8   s     r   rC   zMagic._handle509Bug   s#     9$*">--Gr   c                 .    t          | j        ||          S r   )magic_setparamr&   )r   paramvals      r   r/   zMagic.setparam   s    dk5#666r   c                 ,    t          | j        |          S r   )magic_getparamr&   )r   rQ   s     r   getparamzMagic.getparam   s    dk5111r   c                     t          | d          r+| j        r&t          r!t          | j                   d | _        d S d S d S d S )Nr&   )hasattrr&   magic_close)r   s    r   __del__zMagic.__del__   s_     4"" 	t{ 	{ 	$$$DKKK	 	 	 	 	 	r   )FNFFFFF)r   r   r   __doc__r   rE   rI   rM   rC   r/   rU   rY    r   r   r   r   &   s          CHJO1 1 1 1f- - - 	- 	- 	-- - -  7 7 72 2 2    r   r   c                 r    t                               |           }|t          |           x}t           | <   |S )N)r1   )
_instancesgetr   )r1   is     r   _get_magic_typer`      s7    tAy$$////JtHr   Fc                 J    t          |          }|                    |           S )z"
    Accepts a filename and returns the detected filetype.  Return
    value is the mimetype if mime=True, otherwise a human readable
    name.

    >>> magic.from_file("testdata/test.pdf", mime=True)
    'application/pdf'
    )r`   rI   )rH   r1   ms      r   rI   rI      s#     	A;;x   r   c                 J    t          |          }|                    |           S )z
    Accepts a binary string and returns the detected filetype.  Return
    value is the mimetype if mime=True, otherwise a human readable
    name.

    >>> magic.from_buffer(open("testdata/test.pdf").read(1024))
    'PDF document, version 1.2'
    )r`   rE   )bufferr1   rb   s      r   rE   rE      s#     	A==   r   c                 J    t          |          }|                    |           S )a  
    Accepts a file descriptor and returns the detected filetype.  Return
    value is the mimetype if mime=True, otherwise a human readable
    name.

    >>> f = open("testdata/test.pdf")
    >>> magic.from_descriptor(f.fileno())
    'PDF document, version 1.2'
    )r`   rM   )rL   r1   rb   s      r   rM   rM      s%     	AR   r      )loaderc                 R    | $t          |d                   }t          |          | S )Nr   magic_errorr
   resultfuncargserrs       r   errorcheck_nullrp      s+    ~$q'""S!!!r   c                 Z    | dk    r$t          |d                   }t          |          | S )Nr   ri   rk   s       r   errorcheck_negative_oners      s/    ||$q'""S!!!r   c                 R    t           t          k    r| S |                     dd          S )Nr:   backslashreplace)r>   r?   decode)ss    r   rA   rA      s'    
e|| xx!3444r   )PathLikec                 X    t          | t                    r|                                 S | S r   )
isinstancerx   
__fspath__rH   s    r   unpathr}      s+    h)) 	&&(((Or   c                     | S r   r[   r|   s    r   r}   r}      s    r   c                    | d S t          |           } t          j        d         dk    rt          | t                    p*t          j        d         dk    ot          | t
                    }|r|                     dd          S | S )Nr         r:   surrogateescape)r}   sysversion_inforz   unicoder>   r@   )rH   
is_unicodes     r   coerce_filenamer      s    thH "1%* /Hg..-"1%* ,Xs++   w(9:::r   c                 <    t          | t          |                    S r   )_magic_filer   r&   rH   s     r   r2   r2   (      vx88999r   c                 >    t          | |t          |                    S r   )_magic_bufferlen)r&   rD   s     r   rB   rB   2  s    c#hh///r   c                 "    t          | |          S r   )_magic_descriptor)r&   rL   s     r   rK   rK   A  s    VR(((r   c                 <    t          | t          |                    S r   )_magic_loadr   r   s     r   r*   r*   K  r   r   rP   rT   Tc                     t           st          d          t          |          }t          | |t	          |                    S )Nzmagic_setparam not implemented)r.   r-   r   _magic_setparamr   )r&   rQ   rR   vs       r   rP   rP   i  s=     D!"BCCCA65%((333r   c                     t           st          d          t                      }t          | |t	          |                     |j        S )Nzmagic_getparam not implemented)r.   r-   r   _magic_getparamr   value)r&   rQ   rR   s      r   rT   rT   p  sC     D!"BCCC
**CFE5::...9r   magic_versionc                  J    t           st          d          t                      S )Nzmagic_version not implemented)r+   r-   r   r[   r   r   r,   r,     s$     C!"ABBB??r   r            i   i       r         i   i   i    i @  i   i   i   i   i   i   r         c                 ~  
 dd l 
dd l}ddlm} 
fd}g d}|D ]} ||j        |                   | |<   |                    d          }t          dg          }|j                                        D ]G\  }}	|                    |          r-|| v r$||v r#| |         |	k    rt          d|z             B|	| |<   Hd S )Nr   )compatc                       fd}|S )Nc                  J                         dt                      | i |S )NzUsing compatibility mode with libmagic's python binding. See https://github.com/ahupp/python-magic/blob/master/COMPAT.md for details.)warnPendingDeprecationWarning)rn   kwargsfnwarningss     r   _z3_add_compat.<locals>.deprecation_wrapper.<locals>._  s9    MM_)+ + +
 2t&v&&&r   r[   )r   r   r   s   ` r   deprecation_wrapperz(_add_compat.<locals>.deprecation_wrapper  s)    	' 	' 	' 	' 	' 	' r   )detect_from_filenamedetect_from_contentdetect_from_fobjopenz	^[A-Z_]+$
MAGIC_MIMEzinconsistent value for )
r   remagicr   __dict__compilesetitemsmatchr   )	to_moduler   r   r   r   fnameis_const_reallowed_inconsistentnamer   r   s             @r   _add_compatr     s7   	 	 	 	 	
 
 
B  G G..vu/EFF	% **[))K~..,,.. 
( 
(eT"" 		(y  ///T?e++#$=$DEEE"'	$
( 
(r   )F)_rZ   r   globctypesctypes.utilr'   loggingr   r   r   r   r   r   r   rG   r   r
   r   r]   r`   rI   rE   rM    rg   load_liblibmagicmagic_trp   rs   rA   osrx   r}   ImportErrorr   r%   restypeargtypesrX   rj   magic_errnor2   r   errcheckrB   r   rK   r   r*   r   magic_setflagsmagic_checkmagic_compiler.   rW   rP   r   rT   r   r+   r   r,   r   MAGIC_DEBUGMAGIC_SYMLINKr"   MAGIC_DEVICESr   r    r   r$   r!   MAGIC_CHECKMAGIC_PRESERVE_ATIMEr#   MAGIC_ERRORMAGIC_NO_CHECK_COMPRESSMAGIC_NO_CHECK_TARMAGIC_NO_CHECK_SOFTMAGIC_NO_CHECK_APPTYPEMAGIC_NO_CHECK_ELFMAGIC_NO_CHECK_ASCIIMAGIC_NO_CHECK_TROFFMAGIC_NO_CHECK_FORTRANMAGIC_NO_CHECK_TOKENSMAGIC_PARAM_INDIR_MAXr0   MAGIC_PARAM_ELF_PHNUM_MAXMAGIC_PARAM_ELF_SHNUM_MAXMAGIC_PARAM_ELF_NOTES_MAXMAGIC_PARAM_REGEX_MAXMAGIC_PARAM_BYTES_MAXr   globalsr[   r   r   <module>r      s   $ 


            F F F F F F F F F F F F F F F F 
    Y   v v v v v v v vr 
  
! 
! 
! 
!
! 
! 
! 
!! ! ! !      6?
/    5 5 5	   
          *  

 g
 " y " y " y ! * & : : : %  !8X6 ( 0 0 0 , #  $e,  +  - $  %u-  ,  ) ) ) ! * . : : : ( "E* " * & !8, 

78%&& 
7778=M+N+N 
7J-O#O '0A0ABO6O-O#O '0A0ABO6O4 4 4   
78_%%  L*M!MM   
  
 	"   !    !          #( #( #(L GGII     s   ?	B	 	BB