
    7ThQK                        S r SSKrSSKrSSKJr   SSKJr   SSK	r	 SSK
r
SSKJr   SSKrSr0 qSrSrS	rS
rSrSrSrS%S jr " S S5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      rSrSrSrSr Sr! " S S\RD                  5      r# " S S \5      r$ " S! S"\#5      r% " S# S$\5      r&g! \ a	    SSKJr   Nf = f! \ a    Sr	 Nf = f! \ a    Sr
 Nf = f! \ a    Sr Nf = f)&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c                 b   [        U [        5      (       d  [        SR                  U 5      5      e[        U[        5      (       d  [        SR                  U5      5      eUR
                  b  [        UR
                  S5      (       aQ  [        UR
                  S5      (       a6  [        UR
                  S5      (       a  [        UR
                  S5      (       d$  [        SR                  UR
                  5      5      eU [        ;   a!  U(       d  [        S	R                  U 5      5      eU[        U '   g)
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      I/var/www/auris/envauris/lib/python3.13/site-packages/joblib/compressor.pyregister_compressorr   /   s    os++=DD_U
 	
 j"344%%+VJ%7
 	

 !!-J..77z117;;z116::z116::??Ev**@
 	
 ,&u>EEoVWW$.L!    c                   2    \ rS rSrSrSS jrS	S jrS rSrg)
r   X   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.
c                 (    Xl         X l        X0l        g N)r   prefix	extension)selfobjr   r   s       r   __init__CompressorWrapper.__init__h   s    ""r   Nc                 N    Uc  U R                  US5      $ U R                  USUS9$ 0Returns an instance of a compressor file object.wb)compresslevelr   r    fileobjr(   s      r   compressor_file!CompressorWrapper.compressor_filem   s3     ''66'']'SSr   c                 &    U R                  US5      $ z2Returns an instance of a decompressor file object.rbr)   r    r+   s     r   decompressor_file#CompressorWrapper.decompressor_filet   s    ##GT22r   )r   r   r   )r    r   )	__name__
__module____qualname____firstlineno____doc__r"   r,   r2   __static_attributes__ r   r   r   r   X   s    #
T3r   r   c                   8    \ rS rSr\rSrS rS rS	S jr	S r
Srg)
BZ2CompressorWrappery   z.bz2c                 L    [         b  [         R                  U l        g S U l        g r   )bz2BZ2Filer   r    s    r   r"   BZ2CompressorWrapper.__init__}   s    ?#&;;D #'D r   c                 (    [         c  [        S5      eg )Nz;bz2 module is not compiled on your python standard library.)r@   r   rB   s    r   _check_versions$BZ2CompressorWrapper._check_versions   s    ;M  r   Nc                 n    U R                  5         Uc  U R                  US5      $ U R                  USUS9$ r%   rE   r   r*   s      r   r,   $BZ2CompressorWrapper.compressor_file   s?     ''66'']'SSr   c                 J    U R                  5         U R                  US5      nU$ r/   rH   r1   s     r   r2   &BZ2CompressorWrapper.decompressor_file   s%    &&w5r   r)   r   )r5   r6   r7   r8   _BZ2_PREFIXr   r   r"   rE   r,   r2   r:   r;   r   r   r=   r=   y   s!    FI(Tr   r=   c                   <    \ rS rSr\rSrSrS rS r	S
S jr
S rS	rg)LZMACompressorWrapper   z.lzmaFORMAT_ALONEc                     [         b5  [         R                  U l        [        [         U R                  5      U l        g S U l        g r   )lzmaLZMAFiler   getattr_lzma_format_name_lzma_formatrB   s    r   r"   LZMACompressorWrapper.__init__   s1    #'==D  'd.D.D ED#'D r   c                 (    [         c  [        S5      eg )Nz<lzma module is not compiled on your python standard library.)rR   r   rB   s    r   rE   %LZMACompressorWrapper._check_versions   s    <N  r   Nc                 v    Uc  U R                  USU R                  S9$ U R                  USU R                  US9$ )r&   r'   )r   )r   preset)r   rV   r*   s      r   r,   %LZMACompressorWrapper.compressor_file   sM     ''d>O>O'PP''d&7&7 (  r   c                 0    [         R                  " US5      $ r/   )rR   rS   r1   s     r   r2   'LZMACompressorWrapper.decompressor_file   s    }}Wd++r   )rV   r   r   )r5   r6   r7   r8   _LZMA_PREFIXr   r   rU   r"   rE   r,   r2   r:   r;   r   r   rN   rN      s&    FI&(,r   rN   c                        \ rS rSr\rSrSrSrg)XZCompressorWrapper   z.xz	FORMAT_XZr;   N)	r5   r6   r7   r8   
_XZ_PREFIXr   r   rU   r:   r;   r   r   ra   ra      s    FI#r   ra   c                   8    \ rS rSr\rSrS rS rS	S jr	S r
Srg)
LZ4CompressorWrapper   z.lz4c                 8    [         b  [        U l        g S U l        g r   )lz4r   r   rB   s    r   r"   LZ4CompressorWrapper.__init__   s    ?#/D #'D r   c                     [         c  [        [        5      e[         R                  nUR	                  S5      (       a  USS  n[        U5      [        S5      :  a  [        [        5      eg )Nv   z0.19)ri   r   LZ4_NOT_INSTALLED_ERROR__version__
startswithr   )r    lz4_versions     r   rE   $LZ4CompressorWrapper._check_versions   s[    ;455oo!!#&&%ab/K$|F';;455 <r   Nc                 n    U R                  5         Uc  U R                  US5      $ U R                  USUS9$ )r&   r'   )compression_levelrH   r*   s      r   r,   $LZ4CompressorWrapper.compressor_file   s?     ''66'''WWr   c                 F    U R                  5         U R                  US5      $ r/   rH   r1   s     r   r2   &LZ4CompressorWrapper.decompressor_file   s!    ##GT22r   r)   r   )r5   r6   r7   r8   _LZ4_PREFIXr   r   r"   rE   r,   r2   r:   r;   r   r   rf   rf      s!    FI(6X3r   rf   rm         i    c                       \ rS rSrSr\R                  rSS jrS r	\
S 5       rS rS rS rS	 rS
 rS rS rS rS rSS jrSS jrSS jrS rS rS rSS jrS rSrg)BinaryZlibFile   a  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.
c                 8   [        5       U l        S U l        SU l        [        U l        SU l        SU l        X0l        [        U[        5      (       a  SUs=::  a  S::  d  O  [        SR                  U5      5      eUS:X  a?  [        U l        [        R                  " U R                   5      U l        SU l        SU l        OpUS	:X  a[  [(        U l        [        R*                  " U R                  [        R,                  U R                   [        R.                  S5      U l        O[        S
U< 35      e[        U[2        5      (       a#  [4        R6                  " X5      U l        SU l        g [9        US5      (       d  [9        US5      (       a  Xl        g [;        S5      e)NFr   rm   	   zS'compresslevel' must be an integer between 1 and 9. You provided 'compresslevel={}'r0   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"   BinaryZlibFile.__init__  sA    W
!
	
*---a=6MA6MCCI6-CX 
 4<#DJ!%!3!3DJJ!?DDL"#DT\$DJ#//""DMM4::t?Q?QST D 49::h$$wwx.DH DMXv&&'(G*D*DHOPPr   c                 v   U R                      U R                  [        :X  a
   SSS5        g U R                  [        [        4;   a  SU l        ONU R                  [        :X  a:  U R                  R                  U R                  R                  5       5        SU l	         U R                  (       a  U R                  R                  5         SU l        SU l        [        U l        SU l        SU l         SSS5        g! SU l        SU l        [        U l        SU l        SU l        f = f!  U R                  (       a  U R                  R                  5         SU l        SU l        [        U l        SU l        SU l        f ! SU l        SU l        [        U l        SU l        SU l        f = f= f! , (       d  f       g= f)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   )r   r   r   r   _MODE_READ_EOFr   r   r   r	   r   flushr   closer   r   rB   s    r   r   BinaryZlibFile.close(  sM    ZZzz\) Z,::*n!==)-D&ZZ;.HHNN4#3#3#9#9#;<'+D$,}}(#DH$)DM!-DJ#&DL*+D'% Z  $DH$)DM!-DJ#&DL*+D',}}(#DH$)DM!-DJ#&DL*+D'	  $DH$)DM!-DJ#&DL*+D'% ZsM   F*A0D&+C:	'F*:)D##F*&F'(+E;(F';)F$	$F''F**
F8c                 (    U R                   [        :H  $ )zTrue if this file is closed.)r   r   rB   s    r   closedBinaryZlibFile.closedB  s     zz\))r   c                 V    U R                  5         U R                  R                  5       $ )z3Return the file descriptor for the underlying file.)_check_not_closedr   filenorB   s    r   r   BinaryZlibFile.filenoG  s     xx  r   c                 d    U R                  5       =(       a    U R                  R                  5       $ )z)Return whether the file supports seeking.)readabler   seekablerB   s    r   r   BinaryZlibFile.seekableL  s     }}6488#4#4#66r   c                 T    U R                  5         U R                  [        [        4;   $ )z/Return whether the file was opened for reading.)r   r   r   r   rB   s    r   r   BinaryZlibFile.readableP  s"     zzj.999r   c                 H    U R                  5         U R                  [        :H  $ )z/Return whether the file was opened for writing.)r   r   r   rB   s    r   writableBinaryZlibFile.writableU  s     zz[((r   c                     U R                   (       a@  [        U R                  SS 5      nSnUb  USR                  U5      -  nUS-  n[	        U5      eg )NnamezI/O operation on closed filez {}.)r   rT   r   r   r   )r    fnamemsgs      r   r    BinaryZlibFile._check_not_closed\  sQ    ;;DHHfd3E0C u||E**3JCS/! r   c                     U R                   [        [        4;  a&  U R                  5         [        R
                  " S5      eg )NzFile not open for reading)r   r   r   r   r   UnsupportedOperationrB   s    r   _check_can_readBinaryZlibFile._check_can_reade  s6    ::j.99""$))*EFF :r   c                 x    U R                   [        :w  a&  U R                  5         [        R                  " S5      eg )NzFile not open for writing)r   r   r   r   r   rB   s    r   _check_can_writeBinaryZlibFile._check_can_writej  s1    ::$""$))*EFF %r   c                     U R                   [        [        4;  a&  U R                  5         [        R
                  " S5      eU R                  R                  5       (       d  [        R
                  " S5      eg )Nz3Seeking is only supported on files open for readingz3The underlying file object does not support seeking)r   r   r   r   r   r   r   r   rB   s    r   _check_can_seekBinaryZlibFile._check_can_seeko  se    ::j.99""$))E  xx  ""))E  #r   c                    U R                   [        :X  a  gU R                  [        U R                  5      :X  a   U R
                  R                  =(       d    U R                  R                  [        5      nU(       d  [        e U R
                  R                  U5      U l        SU l        U R                  [        U R                  5      :X  a  M  g! [         a    [        U l         U R                  U l         gf = f)NFr   T)r   r   r   lenr   r   unused_datar   r   _BUFFER_SIZEEOFError
decompressr   r   )r    rawblocks     r   _fill_bufferBinaryZlibFile._fill_buffer{  s    ::' !!S%66
G--99XTXX]]<=X"N    $11<<XF"#D !!S%66   +
!YY
	s   A	C &C:9C:c                 |   U R                   U R                  S  U l         SU l        / nU R                  5       (       ah  U(       a  UR                  U R                   5        U =R                  [        U R                   5      -  sl        SU l         U R                  5       (       a  Mh  U(       a  SR                  U5      $ g Nr   r   )r   r   r   appendr   r   join)r    return_datablockss      r   	_read_allBinaryZlibFile._read_all  s    ||D$7$7$9:!!dll+IIT\\**IDL	 !!
 88F## r   c                    U R                   U-   nU[        U R                  5      ::  aH  U R                  U R                   U nX0l         U =R                  [        U5      -  sl        U(       a  U$ S $ U R                  U R                   S  U l        SU l         / nUS:  a  U R	                  5       (       a  U[        U R                  5      :  a  U R                  S U nXl         OU R                  nSU l        U(       a  UR                  U5        U =R                  [        U5      -  sl        U[        U5      -  nUS:  a  U R	                  5       (       a  M  U(       a  SR                  U5      $ g r   )r   r   r   r   r   r   r   )r    n_bytesr   enddatar   s         r   _read_blockBinaryZlibFile._read_block  s1   !!G+#dll##<< 3 3c:D"%IIT"I&40D0 ||D$7$7$9:kd//11T\\**||HW-&-#||"d#IIT"Is4y G kd//11 88F## r   c                     U R                      U R                  5         US:X  a
   SSS5        gUS:  a  U R                  5       sSSS5        $ U R                  U5      sSSS5        $ ! , (       d  f       g= f)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   )r   r   r   r   )r    sizes     r   r   BinaryZlibFile.read  s\     ZZ  "qy Z ~~' Z ''- ZZs   A'A'A''
A5c                     U R                      [        R                  R                  X5      sSSS5        $ ! , (       d  f       g= f)zORead up to len(b) bytes into b.

Returns the number of bytes read (0 for EOF).
N)r   r   BufferedIOBasereadinto)r    bs     r   r   BinaryZlibFile.readinto  s)    
 ZZ$$--d6 ZZs	   6
Ac                 x   U R                      U R                  5         [        U[        5      (       a  UR	                  5       nU R
                  R                  U5      nU R                  R                  U5        U =R                  [        U5      -  sl	        [        U5      sSSS5        $ ! , (       d  f       g= f)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)r   r   r   
memoryviewtobytesr   compressr   r	   r   r   )r    r   
compresseds      r   r	   BinaryZlibFile.write  sx     ZZ!!#$
++||~))2248JHHNN:&IIT"It9 ZZs   BB++
B9c                     U R                   R                  SS5        [        U l        SU l        [
        R                  " U R                  5      U l        SU l	        SU l
        g r   )r   r
   r   r   r   r   r   r   r   r   r   rB   s    r   _rewindBinaryZlibFile._rewind  sH    a
	!//

;r   c                    U R                      U R                  5         US:X  a  OZUS:X  a  U R                  U-   nODUS:X  a/  U R                  S:  a  U R	                  SS9  U R                  U-   nO[        SU< 35      eXR                  :  a  U R                  5         OXR                  -  nU R                  USS9  U R                  sSSS5        $ ! , (       d  f       g= f)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   rm   ry   F)r   zInvalid value for whence: N)r   r   r   r   r   r   r   r   )r    offsetwhences      r   r
   BinaryZlibFile.seek  s     ZZ  " {1V+1::>NNuN5f, 6!KLL 		!))# V7993 ZZs   B;C
C c                     U R                      U R                  5         U R                  sSSS5        $ ! , (       d  f       g= f)z!Return the current file position.N)r   r   r   rB   s    r   r   BinaryZlibFile.tell  s&    ZZ""$99 ZZs	   3
A)r   r   r   r   r   r   r   r   r   r   r(   N)r0   rz   )T)r   )r   )r5   r6   r7   r8   r9   r   	MAX_WBITSr   r"   r   propertyr   r   r   r   r   r   r   r   r   r   r   r   r   r   r	   r   r
   r   r:   r;   r   r   r|   r|      s    . NNE$QL,4 * *!
7:
)"G
G
	,$ $8.7& (Tr   r|   c                       \ rS rSrS rSrg)ZlibCompressorWrapperi   c                 @    [         R                  U [        [        SS9  g )Nz.zr!   r   r   )r   r"   r|   _ZLIB_PREFIXrB   s    r   r"   ZlibCompressorWrapper.__init__!  s    ""n\T 	# 	
r   r;   Nr5   r6   r7   r8   r"   r:   r;   r   r   r   r          
r   r   c                       \ rS rSrSrSrSrg)BinaryGzipFilei'  a  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.
   r;   N)r5   r6   r7   r8   r9   r   r:   r;   r   r   r   r   '  s     Er   r   c                       \ rS rSrS rSrg)GzipCompressorWrapperi8  c                 @    [         R                  U [        [        SS9  g )Nz.gzr   )r   r"   r   _GZIP_PREFIXrB   s    r   r"   GzipCompressorWrapper.__init__9  s    ""n\U 	# 	
r   r;   Nr   r;   r   r   r   r   8  r   r   r   )F)'r9   r   r   joblib.backportsr   	threadingr   ImportErrordummy_threadingr@   ri   	lz4.framer   rR   rn   r   _ZFILE_PREFIXr   r   rL   rd   r_   rx   r   r   r=   rN   ra   rf   r   r   r   r   r   r   r|   r   r   r   r;   r   r   <module>r     s\   5 	  )&& T 
  $
!&/R3 3B, >,- ,@$/ $3, 3F 
uR&& up	
- 
^ "
- 
]  &%&
  
C  
C
  DsD   B; C 
C C) ;C
	C
CCC&%C&)C43C4