U
    [e                      @   s  d Z ddlZddlmZ ddlT ddlmZ ddlmZ i Ze	 ed< d Z
Zd ZZd	 ZZd
 ZZd ZZd ZZd ZZd ZZd ZZd ZZd ZZd Z Z!d Z"Z#d Z$Z%d Z&Z'd Z(Z)d Z*Z+d Z,Z-d Z.Z/d Z0Z1d Z2Z3d Z4Z5d Z6Z7d Z8Z9edd Z:G d!d" d"e;Z<g e<_=e>e<Z?ed j@ZAe?eA_BeCgeA_Ded jEZFdeF_Be?geF_Ded jGZHeIeH_Be?eIgeH_Ded jJZKeIeK_Be?eCgeK_Ded jLZMeIeM_Be?eNeOgeM_Ded jPZQeIeQ_Be?geQ_Ded jRZSeCeS_Be?eCgeS_Ded jTZUeCeU_Be?eIgeU_Ded jVZWeCeW_Be?eIgeW_Ded jXZYeCeY_Be?eIgeY_Ded jZZ[eCe[_Be?eIge[_Ded j\Z]eCe]_Be?ge]_DG d#d$ d$e^Z_d%d& Z`e_eAe"Zaeab  e_eAe
Zcecb  d'd( Zdd)d* Zed+d, Zfd-d. ZgdS )/z
Python bindings for libmagic
    N)
namedtuple)*)find_library   )loadermagic                @         i   i   i  i   i   i    i @  i   i   i   i   i   i    i ? 	FileMagic)	mime_typeencodingnamec                   @   s   e Zd ZdS )	magic_setN)__name__
__module____qualname__ r   r   N/var/www/html/services/stratfitenv/lib/python3.8/site-packages/magic/compat.pyr   3   s   r   c                   @   s   e Zd Zdd Zdd Zedd Zedd Zd	d
 Zdd Z	dd Z
dd Zdd ZdddZdd Zdd Zdd Zdd ZdS )Magicc                 C   s
   || _ d S )N)_magic_t)selfmsr   r   r   __init__l   s    zMagic.__init__c                 C   s   t | j dS )zO
        Closes the magic database and deallocates any resources used.
        N)_closer   r   r   r   r   closeo   s    zMagic.closec                 C   sH   | d krd S t | tr| S zt| dW S  tk
rB   t|  Y S X d S Nzutf-8)
isinstancestr	TypeError)sr   r   r   Z__tostru   s    
zMagic.__tostrc                 C   sH   | d krd S t | tr| S zt| dW S  tk
rB   t|  Y S X d S r"   )r#   bytesr%   )br   r   r   Z	__tobytes   s    
zMagic.__tobytesc                 C   s   t t| jt |S )z
        Returns a textual description of the contents of the argument passed
        as a filename or None if an error occurred and the MAGIC_ERROR flag
        is set. A call to errno() will return the numeric error code.
        )r   _Magic__tostr_filer   _Magic__tobytesr   filenamer   r   r   file   s    z
Magic.filec                 C   s   t t| j|S )z
        Returns a textual description of the contents of the argument passed
        as a file descriptor or None if an error occurred and the MAGIC_ERROR
        flag is set. A call to errno() will return the numeric error code.
        )r   r)   _descriptorr   )r   fdr   r   r   
descriptor   s    zMagic.descriptorc                 C   s   t t| j|t|S )z
        Returns a textual description of the contents of the argument passed
        as a buffer or None if an error occurred and the MAGIC_ERROR flag
        is set. A call to errno() will return the numeric error code.
        )r   r)   _bufferr   len)r   bufr   r   r   buffer   s    zMagic.bufferc                 C   s   t t| jS )zh
        Returns a textual explanation of the last error or None
        if there was no error.
        )r   r)   _errorr   r    r   r   r   error   s    zMagic.errorc                 C   s   t | j|S )a*  
        Set flags on the magic object which determine how magic checking
        behaves; a bitwise OR of the flags described in libmagic(3), but
        without the MAGIC_ prefix.

        Returns -1 on systems that don't support utime(2) or utimes(2)
        when PRESERVE_ATIME is set.
        )	_setflagsr   )r   flagsr   r   r   setflags   s    	zMagic.setflagsNc                 C   s   t | jt|S )a	  
        Must be called to load entries in the colon separated list of database
        files passed as argument or the default database file if no argument
        before any magic queries can be performed.

        Returns 0 on success and -1 on failure.
        )_loadr   r   r+   r,   r   r   r   load   s    z
Magic.loadc                 C   s   t | jt|S )aD  
        Compile entries in the colon separated list of database files
        passed as argument or the default database file if no argument.
        The compiled files created are named from the basename(1) of each file
        argument with ".mgc" appended to it.

        Returns 0 on success and -1 on failure.
        )_compiler   r   r+   r   Zdbsr   r   r   compile   s    	zMagic.compilec                 C   s   t | jt|S z
        Check the validity of entries in the colon separated list of
        database files passed as argument or the default database file
        if no argument.

        Returns 0 on success and -1 on failure.
        )_checkr   r   r+   r>   r   r   r   check   s    zMagic.checkc                 C   s   t | jt|S r@   )_listr   r   r+   r>   r   r   r   list   s    z
Magic.listc                 C   s
   t | jS )a  
        Returns a numeric error code. If return value is 0, an internal
        magic error occurred. If return value is non-zero, the value is
        an OS error code. Use the errno module or os.strerror() can be used
        to provide detailed error information.
        )_errnor   r    r   r   r   errno   s    zMagic.errno)N)r   r   r   r   r!   staticmethodr)   r+   r.   r1   r5   r7   r:   r<   r?   rB   rD   rF   r   r   r   r   r   k   s    







r   c                 C   s   t t| S )zd
    Returns a magic object on success and None on failure.
    Flags argument as for setflags.
    )r   _open)r9   r   r   r   open   s    rI   c                 C   s$   |  d\}}t|||dddS )Nz; zcharset= )r   r   r   )splitr   replace)Zmime_detectedZtype_detectedr   Zmime_encodingr   r   r   _create_filemagic   s    
rM   c                 C   s   t t| t| S )zdDetect mime type, encoding and file type from a filename

    Returns a `FileMagic` namedtuple.
    )rM   
mime_magicr.   
none_magic)r-   r   r   r   detect_from_filename   s    
rP   c                 C   s   |   }tt|t|S )zjDetect mime type, encoding and file type from file-like object

    Returns a `FileMagic` namedtuple.
    )filenorM   rN   r1   rO   )Zfobjfile_descriptorr   r   r   detect_from_fobj  s    
rS   c                 C   s   t t| t| S )z_Detect mime type, encoding and file type from bytes

    Returns a `FileMagic` namedtuple.
    )rM   rN   r5   rO   )Zbyte_contentr   r   r   detect_from_content  s    
rT   )h__doc__ctypescollectionsr   ctypes.utilr   rJ   r   Z
_librariesZload_libZ
MAGIC_NONENONEZMAGIC_DEBUGDEBUGZMAGIC_SYMLINKZSYMLINKZMAGIC_COMPRESSZCOMPRESSZMAGIC_DEVICESZDEVICESZMAGIC_MIME_TYPEZ	MIME_TYPEZMAGIC_CONTINUECONTINUEZMAGIC_CHECKZCHECKZMAGIC_PRESERVE_ATIMEZPRESERVE_ATIMEZ	MAGIC_RAWZRAWZMAGIC_ERRORERRORZMAGIC_MIME_ENCODINGZMIME_ENCODINGZ
MAGIC_MIMEMIMEZMAGIC_APPLEZAPPLEZMAGIC_NO_CHECK_COMPRESSZNO_CHECK_COMPRESSZMAGIC_NO_CHECK_TARZNO_CHECK_TARZMAGIC_NO_CHECK_SOFTZNO_CHECK_SOFTZMAGIC_NO_CHECK_APPTYPEZNO_CHECK_APPTYPEZMAGIC_NO_CHECK_ELFZNO_CHECK_ELFZMAGIC_NO_CHECK_TEXTZNO_CHECK_TEXTZMAGIC_NO_CHECK_CDFZNO_CHECK_CDFZMAGIC_NO_CHECK_TOKENSZNO_CHECK_TOKENSZMAGIC_NO_CHECK_ENCODINGZNO_CHECK_ENCODINGZMAGIC_NO_CHECK_BUILTINZNO_CHECK_BUILTINr   Z	Structurer   Z_fields_ZPOINTERZmagic_tZ
magic_openrH   restypec_intZargtypesZmagic_closer   Z
magic_filer*   c_char_pZmagic_descriptorr/   Zmagic_bufferr2   Zc_void_pZc_size_tZmagic_errorr6   Zmagic_setflagsr8   Z
magic_loadr;   Zmagic_compiler=   magic_checkrA   Z
magic_listrC   Zmagic_errnorE   objectr   rI   rN   r<   rO   rM   rP   rS   rT   r   r   r   r   <module>   s   



















}	
