
    .PhQK                        d Z ddlZddlZddlmZ 	 ddlmZ n# e$ r	 ddlmZ Y nw xY w	 ddl	Z	n# e$ r dZ	Y nw xY w	 ddl
Z
ddlmZ n# e$ r dZ
Y nw xY w	 ddlZn# e$ r dZY nw xY wdZi adZdZd	Zd
ZdZdZdZd&dZ G d d          Z G d de          Z G d de          Z G d de          Z G d de          ZdZdZdZdZ dZ! G d dej"                  Z# G d  d!e          Z$ G d" d#e#          Z% G d$ d%e          Z&dS )'z/Classes and functions for managing compressors.    N)LooseVersion)RLock)LZ4FrameFilezMLZ4 is not installed. Install it with pip: https://python-lz4.readthedocs.io/s   ZF   xs   s   BZs   7zXZs   ] s   "MFc                 T   t          | t                    s"t          d                    |                     t          |t                    s"t          d                    |                    |j        {t          |j        d          r?t          |j        d          r*t          |j        d          rt          |j        d          s't          d                    |j                            | t          v r$|s"t          d	                    |                     |t          | <   dS )
zRegister a new compressor.

    Parameters
    ----------
    compressor_name: str.
        The name of the compressor.
    compressor: CompressorWrapper
        An instance of a 'CompressorWrapper'.
    z/Compressor name should be a string, '{}' given.zHCompressor should implement the CompressorWrapper interface, '{}' given.Nreadwriteseektellz^Compressor 'fileobj_factory' attribute should implement the file object interface, '{}' given.z#Compressor '{}' already registered.)
isinstancestr
ValueErrorformatCompressorWrapperfileobj_factoryhasattr_COMPRESSORS)compressor_name
compressorforces      Q/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/joblib/compressor.pyregister_compressorr   /   sD    os++ 
=DD_UU
 
 	
 j"344 
%%+VJ%7%7
 
 	

 !-J.77 .z17;; . z16:: . z16::	 . ??Ev*@ @
 
 	
 ,&&u&>EEoVVWWW$.L!!!    c                   (    e Zd ZdZddZd	dZd ZdS )
r   a  A wrapper around a compressor file object.

    Attributes
    ----------
    obj: a file-like object
        The object must implement the buffer interface and will be used
        internally to compress/decompress the data.
    prefix: bytestring
        A bytestring corresponding to the magic number that identifies the
        file format associated to the compressor.
    extension: str
        The file extension used to automatically select this compressor during
        a dump to a file.
    r    c                 0    || _         || _        || _        d S N)r   prefix	extension)selfobjr   r   s       r   __init__zCompressorWrapper.__init__h   s    ""r   Nc                 b    ||                      |d          S |                      |d|          S 0Returns an instance of a compressor file object.Nwb)compresslevelr   r    fileobjr'   s      r   compressor_filez!CompressorWrapper.compressor_filem   s9     ''666'']'SSSr   c                 .    |                      |d          S z2Returns an instance of a decompressor file object.rbr(   r    r*   s     r   decompressor_filez#CompressorWrapper.decompressor_filet   s    ##GT222r   )r   r   r   )__name__
__module____qualname____doc__r"   r+   r0    r   r   r   r   X   sY         # # # #
T T T T3 3 3 3 3r   r   c                   0    e Zd ZeZdZd Zd ZddZd Z	dS )BZ2CompressorWrapperz.bz2c                 H    t           t           j        | _        d S d | _        d S r   )bz2BZ2Filer   r    s    r   r"   zBZ2CompressorWrapper.__init__}   s%    ?#&;D   #'D   r   c                 2    t           t          d          d S )Nz;bz2 module is not compiled on your python standard library.)r9   r   r;   s    r   _check_versionsz$BZ2CompressorWrapper._check_versions   s#    ;M   ;r   Nc                     |                                   ||                     |d          S |                     |d|          S r$   r=   r   r)   s      r   r+   z$BZ2CompressorWrapper.compressor_file   sK     ''666'']'SSSr   c                 Z    |                                   |                     |d          }|S r-   r?   r/   s     r   r0   z&BZ2CompressorWrapper.decompressor_file   s.    &&w55r   r   )
r1   r2   r3   _BZ2_PREFIXr   r   r"   r=   r+   r0   r5   r   r   r7   r7   y   sc        FI( ( (  T T T T    r   r7   c                   4    e Zd ZeZdZdZd Zd ZddZ	d Z
dS )	LZMACompressorWrapperz.lzmaFORMAT_ALONEc                     t           2t           j        | _        t          t           | j                  | _        d S d | _        d S r   )lzmaLZMAFiler   getattr_lzma_format_name_lzma_formatr;   s    r   r"   zLZMACompressorWrapper.__init__   s;    #'=D  'd.D E ED#'D   r   c                 2    t           t          d          d S )Nz<lzma module is not compiled on your python standard library.)rF   r   r;   s    r   r=   z%LZMACompressorWrapper._check_versions   s#    <N   <r   Nc                 |    ||                      |d| j                  S |                      |d| j        |          S )r%   Nr&   )r   )r   preset)r   rJ   r)   s      r   r+   z%LZMACompressorWrapper.compressor_file   sO     ''d>O'PPP''d&7 (   r   c                 ,    t          j        |d          S r-   )rF   rG   r/   s     r   r0   z'LZMACompressorWrapper.decompressor_file   s    }Wd+++r   r   )r1   r2   r3   _LZMA_PREFIXr   r   rI   r"   r=   r+   r0   r5   r   r   rC   rC      se        FI&( ( (     , , , , ,r   rC   c                       e Zd ZeZdZdZdS )XZCompressorWrapperz.xz	FORMAT_XZN)r1   r2   r3   
_XZ_PREFIXr   r   rI   r5   r   r   rQ   rQ      s         FI#r   rQ   c                   0    e Zd ZeZdZd Zd ZddZd Z	dS )LZ4CompressorWrapperz.lz4c                 >    t           t          | _        d S d | _        d S r   )lz4r   r   r;   s    r   r"   zLZ4CompressorWrapper.__init__   s#    ?#/D   #'D   r   c                     t           t          t                    t           j        }|                    d          r
|dd          }t          |          t          d          k     rt          t                    d S )Nv   z0.19)rW   r   LZ4_NOT_INSTALLED_ERROR__version__
startswithr   )r    lz4_versions     r   r=   z$LZ4CompressorWrapper._check_versions   sr    ;4555o!!#&& 	*%abb/K$$|F';';;;4555 <;r   Nc                     |                                   ||                     |d          S |                     |d|          S )r%   Nr&   )compression_levelr?   r)   s      r   r+   z$LZ4CompressorWrapper.compressor_file   sK     ''666'''WWWr   c                 V    |                                   |                     |d          S r-   r?   r/   s     r   r0   z&LZ4CompressorWrapper.decompressor_file   s*    ##GT222r   r   )
r1   r2   r3   _LZ4_PREFIXr   r   r"   r=   r+   r0   r5   r   r   rU   rU      sc        FI( ( (6 6 6X X X X3 3 3 3 3r   rU   rZ         i    c                       e Zd ZdZej        ZddZd Ze	d             Z
d Zd Zd	 Zd
 Zd Zd Zd Zd Zd ZddZddZddZd Zd Zd ZddZd ZdS ) BinaryZlibFilea  A file object providing transparent zlib (de)compression.

    TODO python2_drop: is it still needed since we dropped Python 2 support A
    BinaryZlibFile can act as a wrapper for an existing file object, or refer
    directly to a named file on disk.

    Note that BinaryZlibFile provides only a *binary* file interface: data read
    is returned as bytes, and data to be written should be given as bytes.

    This object is an adaptation of the BZ2File object and is compatible with
    versions of python >= 2.7.

    If filename is a str or bytes object, it gives the name
    of the file to be opened. Otherwise, it should be a file object,
    which will be used to read or write the compressed data.

    mode can be 'rb' for reading (default) or 'wb' for (over)writing

    If mode is 'wb', compresslevel can be a number between 1
    and 9 specifying the level of compression: 1 produces the least
    compression, and 9 produces the most compression. 3 is the default.
    r.   rd   c                 0   t                      | _        d | _        d| _        t          | _        d| _        d| _        || _        t          |t                    rd|cxk    rdk    s$n t          d                    |                    |dk    r9t          | _        t          j        | j                  | _        d| _        d| _        n`|d	k    rHt(          | _        t          j        | j        t          j        | j        t          j        d          | _        nt          d
|          t          |t2                    r#t5          j        ||          | _        d| _        d S t9          |d          st9          |d          r	|| _        d S t;          d          )NFr   rZ   	   zS'compresslevel' must be an integer between 1 and 9. You provided 'compresslevel={}'r.   r   r&   zInvalid mode: Tr   r	   z1filename must be a str or bytes object, or a file)r   _lock_fp_closefp_MODE_CLOSED_mode_pos_sizer'   r   intr   r   
_MODE_READzlibdecompressobjwbits_decompressor_buffer_buffer_offset_MODE_WRITEcompressobjDEFLATEDDEF_MEM_LEVEL_compressorr   ioopenr   	TypeError)r    filenamemoder'   s       r   r"   zBinaryZlibFile.__init__  s    WW
!
	
*--- 	a=6M6M6M6MA6M6M6M6MCCI6-CXCX  
 4<<#DJ!%!3DJ!?!?DDL"#DT\\$DJ#/"DM4:t?QST   D *449:::h$$ 	Qwx..DH DMMMXv&& 	Q'(G*D*D 	QDHHHOPPPr   c                 6   | j         5  | j        t          k    r	 ddd           dS 	 | j        t          t          fv rd| _        nH| j        t          k    r8| j                            | j	        
                                           d| _	        	 | j        r| j                                         d| _        d| _        t          | _        d| _        d| _        n# d| _        d| _        t          | _        d| _        d| _        w xY w# 	 | j        r| j                                         d| _        d| _        t          | _        d| _        d| _        n-# d| _        d| _        t          | _        d| _        d| _        w xY ww xY w	 ddd           dS # 1 swxY w Y   dS )zFlush and close the file.

        May be called more than once without error. Once the file is
        closed, any other operation on it will raise a ValueError.
        NFr   r   )rj   rn   rm   rr   _MODE_READ_EOFrv   ry   rk   r	   r}   flushrl   closerw   rx   r;   s    r   r   zBinaryZlibFile.close(  s    Z 	, 	,z\))	, 	, 	, 	, 	, 	, 	, 	,,:*n!===)-D&&Z;..HNN4#3#9#9#;#;<<<'+D$,} )(((#DH$)DM!-DJ#&DL*+D''	  $DH$)DM!-DJ#&DL*+D'++++,} )(((#DH$)DM!-DJ#&DL*+D''	  $DH$)DM!-DJ#&DL*+D'++++++++'%	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	,sS   FA%D C.)F*DFE= E&)E=*E9	9E==FFFc                 "    | j         t          k    S )zTrue if this file is closed.)rn   rm   r;   s    r   closedzBinaryZlibFile.closedB  s     z\))r   c                 \    |                                   | j                                        S )z3Return the file descriptor for the underlying file.)_check_not_closedrk   filenor;   s    r   r   zBinaryZlibFile.filenoG  s&       x   r   c                 \    |                                  o| j                                        S )z)Return whether the file supports seeking.)readablerk   seekabler;   s    r   r   zBinaryZlibFile.seekableL  s#    }}648#4#4#6#66r   c                 T    |                                   | j        t          t          fv S )z/Return whether the file was opened for reading.)r   rn   rr   r   r;   s    r   r   zBinaryZlibFile.readableP  s&       zj.999r   c                 J    |                                   | j        t          k    S )z/Return whether the file was opened for writing.)r   rn   ry   r;   s    r   writablezBinaryZlibFile.writableU  s!       z[((r   c                     | j         rFt          | j        dd           }d}||d                    |          z  }|dz  }t	          |          d S )NnamezI/O operation on closed filez {}.)r   rH   rk   r   r   )r    fnamemsgs      r   r   z BinaryZlibFile._check_not_closed\  s_    ; 	"DHfd33E0C u||E***3JCS//!	" 	"r   c                     | j         t          t          fvr(|                                  t	          j        d          d S )NzFile not open for reading)rn   rr   r   r   r~   UnsupportedOperationr;   s    r   _check_can_readzBinaryZlibFile._check_can_reade  s@    :j.999""$$$)*EFFF :9r   c                 v    | j         t          k    r(|                                  t          j        d          d S )NzFile not open for writing)rn   ry   r   r~   r   r;   s    r   _check_can_writezBinaryZlibFile._check_can_writej  s;    :$$""$$$)*EFFF %$r   c                     | j         t          t          fvr(|                                  t	          j        d          | j                                        st	          j        d          d S )Nz3Seeking is only supported on files open for readingz3The underlying file object does not support seeking)rn   rr   r   r   r~   r   rk   r   r;   s    r   _check_can_seekzBinaryZlibFile._check_can_seeko  sx    :j.999""$$$)E   x  "" 	)E  	 	r   c                    | j         t          k    rdS | j        t          | j                  k    r	 | j        j        p| j                            t                    }|st          	 | j                            |          | _        n)# t          $ r t          | _         | j        | _        Y dS w xY wd| _        | j        t          | j                  k    dS )NFr   T)rn   r   rx   lenrw   rv   unused_datark   r   _BUFFER_SIZEEOFError
decompressro   rp   )r    rawblocks     r   _fill_bufferzBinaryZlibFile._fill_buffer{  s    :''5 !S%6%666
G-9XTX]]<=X=X #"N#  $1<<XFF    +
!Y
uu	 #$D !S%6%666 ts   4B "B,+B,Tc                 R   | j         | j        d          | _         d| _        g }|                                 rY|r|                    | j                    | xj        t          | j                   z  c_        d| _         |                                 Y|rd                    |          S d S Nr   r   )rw   rx   r   appendro   r   join)r    return_datablockss      r   	_read_allzBinaryZlibFile._read_all  s    |D$7$9$9:!! 	 ,dl+++IIT\***IIDL	 !! 	
  	$88F###	$ 	$r   c                    | j         |z   }|t          | j                  k    r>| j        | j         |         }|| _         | xj        t          |          z  c_        |r|nd S | j        | j         d          | _        d| _         g }|dk    r|                                 r|t          | j                  k     r| j        d |         }|| _         n| j        }d| _        |r|                    |           | xj        t          |          z  c_        |t          |          z  }|dk    r|                                 |rd                    |          S d S r   )rx   r   rw   ro   r   r   r   )r    n_bytesr   enddatar   s         r   _read_blockzBinaryZlibFile._read_block  sc   !G+#dl####< 3c 9:D"%DIIT"II&044D0 |D$7$9$9:kkd//11kT\****|HWH-&-##|" $d###IIT"IIs4yy G kkd//11k  	$88F###	$ 	$r   rh   c                 
   | j         5  |                                  |dk    r	 ddd           dS |dk     r |                                 cddd           S |                     |          cddd           S # 1 swxY w Y   dS )zRead up to size uncompressed bytes from the file.

        If size is negative or omitted, read until EOF is reached.
        Returns b'' if the file is already at EOF.
        r   Nr   )rj   r   r   r   )r    sizes     r   r   zBinaryZlibFile.read  s	    Z 	. 	.  """qyy	. 	. 	. 	. 	. 	. 	. 	. ~~''	. 	. 	. 	. 	. 	. 	. 	. ''--	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	.s   A8A8A88A<?A<c                     | j         5  t          j                            | |          cddd           S # 1 swxY w Y   dS )z_Read up to len(b) bytes into b.

        Returns the number of bytes read (0 for EOF).
        N)rj   r~   BufferedIOBasereadinto)r    bs     r   r   zBinaryZlibFile.readinto  s    
 Z 	7 	7$--dA66	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7s    599c                 ~   | j         5  |                                  t          |t                    r|                                }| j                            |          }| j                            |           | xj	        t          |          z  c_	        t          |          cddd           S # 1 swxY w Y   dS )zWrite a byte string to the file.

        Returns the number of uncompressed bytes written, which is
        always len(data). Note that due to buffering, the file on disk
        may not reflect the data written until close() is called.
        N)rj   r   r   
memoryviewtobytesr}   compressrk   r	   ro   r   )r    r   
compresseds      r   r	   zBinaryZlibFile.write  s     Z 		 		!!###$
++ &||~~)22488JHNN:&&&IIT"IIt99		 		 		 		 		 		 		 		 		 		 		 		 		 		 		 		 		 		s   BB22B69B6c                     | j                             dd           t          | _        d| _        t          j        | j                  | _        d| _	        d| _
        d S r   )rk   r
   rr   rn   ro   rs   rt   ru   rv   rw   rx   r;   s    r   _rewindzBinaryZlibFile._rewind  sP    a
	!/
;;r   r   c                    | j         5  |                                  |dk    rnU|dk    r| j        |z   }nD|dk    r,| j        dk     r|                     d           | j        |z   }nt          d|          || j        k     r|                                  n
|| j        z  }|                     |d           | j        cddd           S # 1 swxY w Y   dS )a  Change the file position.

        The new position is specified by offset, relative to the
        position indicated by whence. Values for whence are:

            0: start of stream (default); offset must not be negative
            1: current stream position
            2: end of stream; offset must not be positive

        Returns the new file position.

        Note that seeking is emulated, so depending on the parameters,
        this operation may be extremely slow.
        r   rZ   rc   F)r   zInvalid value for whence: N)rj   r   ro   rp   r   r   r   r   )r    offsetwhences      r   r
   zBinaryZlibFile.seek  s<    Z 	 	  """ {{1V+1:>>NNuN555f, j66!KLLL 	!!$)# V77793	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   B8CCCc                 z    | j         5  |                                  | j        cddd           S # 1 swxY w Y   dS )z!Return the current file position.N)rj   r   ro   r;   s    r   r   zBinaryZlibFile.tell  s    Z 	 	""$$$9	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   044N)r.   rd   )T)rh   )r   )r1   r2   r3   r4   rs   	MAX_WBITSru   r"   r   propertyr   r   r   r   r   r   r   r   r   r   r   r   r   r   r	   r   r
   r   r5   r   r   rf   rf      s        . NE$Q $Q $Q $QL, , ,4 * * X*! ! !
7 7 7: : :
) ) )" " "G G G
G G G
	 	 	  ,$ $ $ $ $ $ $ $8. . . .7 7 7  &     ( ( ( (T    r   rf   c                       e Zd Zd ZdS )ZlibCompressorWrapperc                 V    t                               | t          t          d           d S )Nz.zr!   r   r   )r   r"   rf   _ZLIB_PREFIXr;   s    r   r"   zZlibCompressorWrapper.__init__!  s2    ""n\T 	# 	
 	
 	
 	
 	
r   Nr1   r2   r3   r"   r5   r   r   r   r      #        
 
 
 
 
r   r   c                       e Zd ZdZdZdS )BinaryGzipFilea  A file object providing transparent gzip (de)compression.

    If filename is a str or bytes object, it gives the name
    of the file to be opened. Otherwise, it should be a file object,
    which will be used to read or write the compressed data.

    mode can be 'rb' for reading (default) or 'wb' for (over)writing

    If mode is 'wb', compresslevel can be a number between 1
    and 9 specifying the level of compression: 1 produces the least
    compression, and 9 produces the most compression. 3 is the default.
       N)r1   r2   r3   r4   ru   r5   r   r   r   r   '  s          EEEr   r   c                       e Zd Zd ZdS )GzipCompressorWrapperc                 V    t                               | t          t          d           d S )Nz.gzr   )r   r"   r   _GZIP_PREFIXr;   s    r   r"   zGzipCompressorWrapper.__init__9  s2    ""n\U 	# 	
 	
 	
 	
 	
r   Nr   r5   r   r   r   r   8  r   r   r   )F)'r4   r~   rs   joblib.backportsr   	threadingr   ImportErrordummy_threadingr9   rW   	lz4.framer   rF   r[   r   _ZFILE_PREFIXr   r   rA   rS   rO   rb   r   r   r7   rC   rQ   rU   rm   rr   r   ry   r   r   rf   r   r   r   r5   r   r   <module>r      s)   5 5 				  ) ) ) ) ) )& & & &%%%%%%%%&JJJJ   
CCCJJJ&&&&&&&   
CCCKKKK   DDD
 T 
  $
!&/ &/ &/ &/R3 3 3 3 3 3 3 3B    ,   >, , , , ,- , , ,@$ $ $ $ $/ $ $ $3 3 3 3 3, 3 3 3F 
u u u u uR& u u up	
 
 
 
 
- 
 
 
    ^   "
 
 
 
 
- 
 
 
 
 
s;    ''0 ::
A	 	AAA A&%A&