o ܸ` @sdZddlZddlmZddlTddlmZddlmZiZe ed<dZ Z dZ Z d ZZd ZZd ZZd ZZd ZZdZZdZZdZZdZZdZ Z!dZ"Z#dZ$Z%dZ&Z'dZ(Z)dZ*Z+dZ,Z-dZ.Z/dZ0Z1dZ2Z3dZ4Z5dZ6Z7dZ8Z9edd Z:Gd!d"d"e;Ze<Z?edj@ZAe?eA_BeCgeA_DedjEZFdeF_Be?geF_DedjGZHeIeH_Be?eIgeH_DedjJZKeIeK_Be?eCgeK_DedjLZMeIeM_Be?eNeOgeM_DedjPZQeIeQ_Be?geQ_DedjRZSeCeS_Be?eCgeS_DedjTZUeCeU_Be?eIgeU_DedjVZWeCeW_Be?eIgeW_DedjXZYeCeY_Be?eIgeY_DedjZZ[eCe[_Be?eIge[_Dedj\Z]eCe]_Be?ge]_DGd#d$d$e^Z_d%d&Z`e_eAe"Zaeabe_eAe Zcecbd'd(Zdd)d*Zed+d,Zfd-d.ZgdS)/z Python bindings for libmagic N) namedtuple)*) find_library)loadermagic @iiiiii i@iiiiii i? FileMagic) mime_typeencodingnamec@s eZdZdS) magic_setN)__name__ __module__ __qualname__rr./usr/lib/python3/dist-packages/magic/compat.pyr3src@seZdZddZddZeddZeddZd d Zd d Z d dZ ddZ ddZ dddZ ddZddZddZddZdS)MagiccCs ||_dSN)_magic_t)selfmsrrr__init__ls zMagic.__init__cCst|jdS)zO Closes the magic database and deallocates any resources used. N)_closerrrrrcloseosz Magic.closecCB|durdSt|tr |Szt|dWSty t|YSwNzutf-8) isinstancestr TypeError)srrr__tostru    z Magic.__tostrcCr#r$)r%bytesr')brrr __tobytesr*zMagic.__tobytescCstt|jt|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__tobytesrfilenamerrrfilez Magic.filecCstt|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. )rr. _descriptorr)rfdrrr descriptorszMagic.descriptorcCstt|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. )rr._bufferrlen)rbufrrrbufferr4z Magic.buffercCstt|jS)zh Returns a textual explanation of the last error or None if there was no error. )rr._errorrr!rrrerrorsz Magic.errorcCs 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)rflagsrrrsetflagss zMagic.setflagsNcCt|jt|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. )_loadrrr0r1rrrloadz Magic.loadcCrA)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. )_compilerrr0rdbsrrrcompiles z Magic.compilecCrAz 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. )_checkrrr0rFrrrcheckrDz Magic.checkcCrArI)_listrrr0rFrrrlistrDz Magic.listcCs t|jS)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. )_errnorr!rrrerrnos z Magic.errnor)rrrrr" staticmethodr.r0r3r7r;r=r@rCrHrKrMrOrrrrrks"       rcCs tt|S)zd Returns a magic object on success and None on failure. Flags argument as for setflags. )r_open)r?rrropens rRcCs$|d\}}t|||dddS)Nz; zcharset=)rrr)splitrreplace) mime_detected type_detectedr mime_encodingrrr_create_filemagics rYcCtt|t|S)zdDetect mime type, encoding and file type from a filename Returns a `FileMagic` namedtuple. )rY mime_magicr3 none_magic)r2rrrdetect_from_filename r]cCs|}tt|t|S)zjDetect mime type, encoding and file type from file-like object Returns a `FileMagic` namedtuple. )filenorYr[r7r\)fobjfile_descriptorrrrdetect_from_fobjs rbcCrZ)z_Detect mime type, encoding and file type from bytes Returns a `FileMagic` namedtuple. )rYr[r;r\) byte_contentrrrdetect_from_contentr^rd)h__doc__ctypes collectionsr ctypes.utilrrSr _librariesload_lib MAGIC_NONENONE MAGIC_DEBUGDEBUG MAGIC_SYMLINKSYMLINKMAGIC_COMPRESSCOMPRESS MAGIC_DEVICESDEVICESMAGIC_MIME_TYPE MIME_TYPEMAGIC_CONTINUECONTINUE MAGIC_CHECKCHECKMAGIC_PRESERVE_ATIMEPRESERVE_ATIME MAGIC_RAWRAW MAGIC_ERRORERRORMAGIC_MIME_ENCODING MIME_ENCODING MAGIC_MIMEMIME MAGIC_APPLEAPPLEMAGIC_NO_CHECK_COMPRESSNO_CHECK_COMPRESSMAGIC_NO_CHECK_TAR NO_CHECK_TARMAGIC_NO_CHECK_SOFT NO_CHECK_SOFTMAGIC_NO_CHECK_APPTYPENO_CHECK_APPTYPEMAGIC_NO_CHECK_ELF NO_CHECK_ELFMAGIC_NO_CHECK_TEXT NO_CHECK_TEXTMAGIC_NO_CHECK_CDF NO_CHECK_CDFMAGIC_NO_CHECK_TOKENSNO_CHECK_TOKENSMAGIC_NO_CHECK_ENCODINGNO_CHECK_ENCODINGMAGIC_NO_CHECK_BUILTINNO_CHECK_BUILTINr Structurer_fields_POINTERmagic_t magic_openrQrestypec_intargtypes magic_closer magic_filer/c_char_pmagic_descriptorr5 magic_bufferr8c_void_pc_size_t magic_errorr<magic_setflagsr> magic_loadrB magic_compilerE magic_checkrJ magic_listrL magic_errnorNobjectrrRr[rCr\rYr]rbrdrrrrs                         }