a @ f"@sdZddlZddlZddlmZddlTddlmZddZiZeed<dZ Z d Z Z d Z Zd ZZd ZZd ZZdZZdZZdZZdZZdZZdZZ dZ!Z"dZ#Z$dZ%Z&dZ'Z(dZ)Z*dZ+Z,dZ-Z.dZ/Z0dZ1Z2dZ3Z4dZ5Z6dZ7Z8ed d!Z9Gd"d#d#e:Z;ge;_edj?Z@e>e@_AeBge@_CedjDZEdeE_Ae>geE_CedjFZGeHeG_Ae>eHgeG_CedjIZJeHeJ_Ae>eBgeJ_CedjKZLeHeL_Ae>eMeNgeL_CedjOZPeHeP_Ae>geP_CedjQZReBeR_Ae>eBgeR_CedjSZTeBeT_Ae>eHgeT_CedjUZVeBeV_Ae>eHgeV_CedjWZXeBeX_Ae>eHgeX_CedjYZZeBeZ_Ae>eHgeZ_Cedj[Z\eBe\_Ae>ge\_CGd$d%d%e]Z^d&d'Z_Gd(d)d)e]Z`eaZbd*d+Zcd,d-Zdd.d/Zed0d1Zfd2d3ZgdS)4z Python bindings for libmagic N) namedtuple)*) find_librarycCstjtdS)zc Loads the shared library through ctypes and returns a library L{ctypes.CDLL} instance magic)ctypesZcdllZ LoadLibraryrrr)/usr/lib/python3.9/site-packages/magic.py_initsr r @iiiiii i@iiiiii i? FileMagic) mime_typeencodingnamec@s eZdZdS) magic_setN)__name__ __module__ __qualname__rrrrr9src@seZdZddZddZeddZeddZd d Zd d Z d dZ ddZ ddZ dddZ ddZddZddZddZdS)MagiccCs ||_dSN)_magic_t)selfmsrrr__init__pszMagic.__init__cCst|jdS)zO Closes the magic database and deallocates any resources used. N)_closerrrrrclosessz Magic.closecCsF|dur dSt|tr|Sz t|dWSty@t|YS0dSNzutf-8) isinstancestr TypeError)srrrZ__tostrys   z Magic.__tostrcCsF|dur dSt|tr|Sz t|dWSty@t|YS0dSr$)r%bytesr')brrrZ __tobytess   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__tobytesrfilenamerrrfilesz 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)rbufrrrbuffersz 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.setflagsNcCst|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. )_loadrrr-r.rrrloadsz Magic.loadcCst|jt|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. )_compilerrr-rZdbsrrrcompiles z Magic.compilecCst|jt|Sz 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. )_checkrrr-r@rrrchecksz Magic.checkcCst|jt|SrB)_listrrr-r@rrrlistsz 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"rrrerrnosz Magic.errno)N)rrrr r# staticmethodr+r-r0r3r7r9r<r>rArDrFrHrrrrros       rcCs tt|S)zd Returns a magic object on success and None on failure. Flags argument as for setflags. )r_open)r;rrropensrKc@seZdZddZddZdS) MagicDetectcCs4ttt|_|jttt|_|jdSr)rrJ MAGIC_MIME mime_magicr> MAGIC_NONE none_magicr"rrrr s zMagicDetect.__init__cCs|j|jdSr)rNr#rPr"rrr__del__s zMagicDetect.__del__N)rrrr rQrrrrrLsrLcCs*ttdd}|dur&t}ttd||S)NZmagic_instance)getattr threadlocalrLsetattr)vrrr _detect_makes   rVcCsDz|d\}}Wnty,t|Yn0t|||dddS)Nz; zcharset=)rrr)split ValueErrorrreplace)Z mime_detectedZ type_detectedrZ mime_encodingrrr_create_filemagic s  r[cCs t}t|j||j|S)zdDetect mime type, encoding and file type from a filename Returns a `FileMagic` namedtuple. )rVr[rNr0rP)r/xrrrdetect_from_filenames  r]cCs(|}t}t|j||j|S)zjDetect mime type, encoding and file type from file-like object Returns a `FileMagic` namedtuple. )filenorVr[rNr3rP)ZfobjZfile_descriptorr\rrrdetect_from_fobjs   r_cCs t}t|j||j|S)z_Detect mime type, encoding and file type from bytes Returns a `FileMagic` namedtuple. )rVr[rNr7rP)Z byte_contentr\rrrdetect_from_content)s  r`)h__doc__r threading collectionsrZ ctypes.utilrr Z _librariesrOZNONEZ MAGIC_DEBUGDEBUGZ MAGIC_SYMLINKZSYMLINKZMAGIC_COMPRESSZCOMPRESSZ MAGIC_DEVICESZDEVICESZMAGIC_MIME_TYPEZ MIME_TYPEZMAGIC_CONTINUEZCONTINUEZ MAGIC_CHECKZCHECKZMAGIC_PRESERVE_ATIMEZPRESERVE_ATIMEZ MAGIC_RAWZRAWZ MAGIC_ERRORZERRORZMAGIC_MIME_ENCODINGZ MIME_ENCODINGrMZMIMEZ MAGIC_APPLEZAPPLEZMAGIC_NO_CHECK_COMPRESSZNO_CHECK_COMPRESSZMAGIC_NO_CHECK_TARZ NO_CHECK_TARZMAGIC_NO_CHECK_SOFTZ NO_CHECK_SOFTZMAGIC_NO_CHECK_APPTYPEZNO_CHECK_APPTYPEZMAGIC_NO_CHECK_ELFZ NO_CHECK_ELFZMAGIC_NO_CHECK_TEXTZ NO_CHECK_TEXTZMAGIC_NO_CHECK_CDFZ NO_CHECK_CDFZMAGIC_NO_CHECK_TOKENSZNO_CHECK_TOKENSZMAGIC_NO_CHECK_ENCODINGZNO_CHECK_ENCODINGZMAGIC_NO_CHECK_BUILTINZNO_CHECK_BUILTINrZ StructurerZ_fields_ZPOINTERZmagic_tZ magic_openrJZrestypeZc_intargtypesZ magic_closer!Z magic_filer,Zc_char_pZmagic_descriptorr1Z magic_bufferr4Zc_void_pZc_size_tZ magic_errorr8Zmagic_setflagsr:Z magic_loadr=Z magic_compiler?Z magic_checkrCZ magic_listrEZ magic_errnorGobjectrrKrLlocalrSrVr[r]r_r`rrrrs                        }