
εN                 @   s?  d  Z  d d l Z d d l Td d l m Z d d   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 Z, Z- d Z. Z/ d Z0 Z1 d Z2 Z3 d Z4 Z5 Gd d    d  e6  Z7 g  e7 _8 e9 e7  Z: e d j; Z< e: e< _= e> g e< _? e d j@ ZA d eA _= e: g eA _? e d jB ZC eD eC _= e: eD g eC _? e d jE ZF eD eF _= e: e> g eF _? e d jG ZH eD eH _= e: eI eJ g eH _? e d jK ZL eD eL _= e: g eL _? e d jM ZN e> eN _= e: e> g eN _? e d jO ZP e> eP _= e: eD g eP _? e d jQ ZR e> eR _= e: eD g eR _? e d jS ZT e> eT _= e: eD g eT _? e d jU ZV e> eV _= e: eD g eV _? e d jW ZX e> eX _= e: g eX _? Gd! d"   d" eY  ZZ d# d$   Z[ d S)%z
Python bindings for libmagic
    N)*)find_libraryc               C   s   t  j j t d   S)zd
    Loads the shared library through ctypes and returns a library
    L{ctypes.CDLL} instance 
    magic)ctypesZcdllZLoadLibraryr    r   r   '/usr/lib/python3/dist-packages/magic.py_init   s    r   r                      @         i   i   i  i   i   i    i @  i   i   i   i   i   i    i ? c               @   s   e  Z d  Z d S)	magic_setN)__name__
__module____qualname__r   r   r   r   r   1   s   r   c               @   s   e  Z d  Z d d   Z 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)selfZmsr   r   r   __init__g   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   closej   s    zMagic.closec          
   C   sK   y, t  | d  } t t |  j |  d  SWn t |  j |  SYn Xd 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.
        zutf-8N)bytesstr_filer   )r   filenameZbir   r   r   filep   s
    z
Magic.filec             C   s   t  |  j |  S)zN
        Like the file method, but the argument is a file descriptor.
        )_descriptorr   )r   fdr   r   r   
descriptor|   s    zMagic.descriptorc             C   sN   y& t  t |  j | t |   d  SWn! t |  j | t |   SYn Xd 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.
        zutf-8N)r   _bufferr   len)r   Zbufr   r   r   buffer   s    &zMagic.bufferc          	   C   s6   y t  t |  j  d  SWn t |  j  SYn Xd S)zh
        Returns a textual explanation of the last error or None
        if there was no error.
        zutf-8N)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 |  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   load   s    z
Magic.loadc             C   s   t  |  j |  S)aC  
        Compile 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.
        The compiled files created are named from the basename(1) of each file
        argument with ".mgc" appended to it.
        )_compiler   )r   dbsr   r   r   compile   s    zMagic.compilec             C   s   t  |  j |  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   check   s    zMagic.checkc             C   s   t  |  j |  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.
        )_listr   )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)r   r   r   r   r   r    r#   r&   r(   r+   r-   r0   r2   r4   r6   r   r   r   r   r   f   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)r*   r   r   r   open   s    r8   )\__doc__r   Zctypes.utilr   r   Z
_librariesZ
MAGIC_NONEZNONEZMAGIC_DEBUGDEBUGZMAGIC_SYMLINKZSYMLINKZMAGIC_COMPRESSZCOMPRESSZMAGIC_DEVICESZDEVICESZMAGIC_MIME_TYPEZ	MIME_TYPEZMAGIC_CONTINUEZCONTINUEZMAGIC_CHECKZCHECKZMAGIC_PRESERVE_ATIMEZPRESERVE_ATIMEZ	MAGIC_RAWZRAWZMAGIC_ERRORZERRORZMAGIC_MIME_ENCODINGZMIME_ENCODINGZ
MAGIC_MIMEZ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_BUILTINZ	Structurer   Z_fields_ZPOINTERZmagic_tZ
magic_openr7   ZrestypeZc_intZargtypesZmagic_closer   Z
magic_filer   Zc_char_pZmagic_descriptorr!   Zmagic_bufferr$   Zc_void_pZc_size_tZmagic_errorr'   Zmagic_setflagsr)   Z
magic_loadr,   Zmagic_compiler.   Zmagic_checkr1   Z
magic_listr3   Zmagic_errnor5   objectr   r8   r   r   r   r   <module>   s   
























													k