
    7Th%                     4   S r SSKrSSKrSSKrSSKrSSKrSSKJrJr   SSK	r
\R                  r\R                  r\r SSKrSrS rS rS rS	 rS
 rS rS r\R6                  SS j5       rSS jrSrSS jrS r g! \ a    Sr
 Ndf = f! \ a    Sr NSf = f)zFUtilities for fast persistence of big data, with optional compression.    N   )_COMPRESSORS_ZFILE_PREFIXi   c                 P    [        U SU 5      n [        U [        R                  5      $ )z=Check if fileobj is a raw file object, e.g created with open.raw)getattr
isinstanceioFileIO)fileobjs    Q/var/www/auris/envauris/lib/python3.13/site-packages/joblib/numpy_pickle_utils.py_is_raw_filer   &   s!    gug.Ggryy))    c                      [         R                  " 5        V s/ s H  n [        U R                  5      PM     nn U[        [        5      /-  n[        U5      $ s  sn f N)r   valueslenprefixr   max)
compressorprefixess     r   _get_prefixes_max_lenr   ,   sN    9E9L9L9NO9N:J%%&9NHO]#$$Hx= Ps   Ac                    [         R                  S:H  =(       a    U R                  R                  S:H  =(       dq    U R                  R                  S:H  =(       aQ    U R                  R                  =(       a4    [	        S U R                  R                  R                  5        5       5      =(       d    [         R                  S:H  =(       a    U R                  R                  S:H  =(       dq    U R                  R                  S:H  =(       aQ    U R                  R                  =(       a4    [	        S U R                  R                  R                  5        5       5      $ )z2Check if numpy array is having byte order mismatchbig<|c              3   D   #    U  H  oS    R                   S:H  v   M     g7f)r   r   N	byteorder.0es     r   	<genexpr>6_is_numpy_array_byte_order_mismatch.<locals>.<genexpr><        S7R!!#-7R    little>c              3   D   #    U  H  oS    R                   S:H  v   M     g7f)r   r(   Nr   r    s     r   r#   r$   F   r%   r&   )sysr   dtypefieldsallr   arrays    r   #_is_numpy_array_byte_order_mismatchr0   3   s     	 	
KK!!S( %%, TKK&&TSu{{7I7I7P7P7RSS 	! 	
KK!!S( %%, TKK&&TSu{{7I7I7P7P7RSS#r   c                     [        U 5      (       a8  U R                  5       R                  U R                  R	                  S5      5      n U $ )zrUse the byte order of the host while preserving values

Does nothing if array already uses the system byte order.
=)r0   byteswapviewr+   newbyteorderr.   s    r   _ensure_native_byte_orderr6   L   s:    
 +511 %%ekk&>&>s&CDLr   c                 \   [        5       n[        U S5      (       a  U R                  U5      nO"U R                  U5      nU R	                  S5        UR                  [        5      (       a  g[        R                  " 5        H)  u  p4UR                  UR                  5      (       d  M'  Us  $    g)zReturn the compressor matching fileobj.

Parameters
----------
fileobj: file object

Returns
-------
str in {'zlib', 'gzip', 'bz2', 'lzma', 'xz', 'compat', 'not-compressed'}
peekr   compatnot-compressed)
r   hasattrr8   readseek
startswithr   r   itemsr   )r   max_prefix_lenfirst_bytesnamer   s        r   _detect_compressorrC   X   s     +,Nw ll>2 ll>2Qm,, , 2 2 4D%%j&7&788 !5 r   c                 4    [         R                  " U [        S9$ )z0Return a buffered version of a read file object.buffer_size)r
   BufferedReader_IO_BUFFER_SIZEfobjs    r   _buffered_read_filerK   x       T??r   c                 4    [         R                  " U [        S9$ )z1Return a buffered version of a write file object.rE   )r
   BufferedWriterrH   rI   s    r   _buffered_write_filerO   }   rL   r   c              #     #    [        U 5      nUnUS:X  a#  [        R                  " SU-  [        SS9  X4v   gU[        ;   a%  [        U   nUR                  U 5      n[        U5      n Ub  Sn[        U [        R                  5      (       a!  [        R                  " S[        5       -  SS9  OZUS:w  a!  [        R                  " S[        5       -  SS9  O3[        U 5      (       d!  [        R                  " S	[        5       -  SS9  OUnX4v   g7f)
a  Utility function opening the right fileobject from a filename.

The magic number is used to choose between the type of file object to open:
* regular file object (default)
* zlib file object
* gzip file object
* bz2 file object
* lzma file object (for xz and lzma compressor)

Parameters
----------
fileobj: file object
filename: str
    filename path corresponding to the fileobj parameter.
mmap_mode: str
    memory map mode that should be used to open the pickle file. This
    parameter is useful to verify that the user is not trying to one with
    compression. Default: None.

Returns
-------
    a tuple with a file like object, and the validated mmap_mode.

r9   zjThe file '%s' has been generated with a joblib version less than 0.10. Please regenerate this pickle file.   )
stacklevelNzuIn memory persistence is not compatible with mmap_mode "%(mmap_mode)s" flag passed. mmap_mode option will be ignored.r:   ztmmap_mode "%(mmap_mode)s" is not compatible with compressed file %(filename)s. "%(mmap_mode)s" flag will be ignored.zP"%(fileobj)r" is not a raw file, mmap_mode "%(mmap_mode)s" flag will be ignored.)rC   warningswarnDeprecationWarningr   decompressor_filerK   r	   r
   BytesIOlocalsr   )r   filename	mmap_moder   validated_mmap_modecompressor_wrapperinsts          r   _validate_fileobject_and_memmapr^      s%    6 $G,J#X 	24<= 	
 ++% ".j!9%77@D)$/G
  "&'2::..8:@(C  !	 //<>DhG  !	 "'**<>DhG  '0#**s   DDc                     US   nUS   nU[         R                  " 5       ;   a!  [         U   R                  XS9n[        U5      $ [         S   R                  XS9n[        U5      $ )z6Return the right compressor file object in write mode.r   r   )compresslevelzlib)r   keyscompressor_filerO   )rY   compresscompressmethodr`   file_instances        r   _write_fileobjectrg      sz    a[NQKM**,,$^4DD E 
 $M22$V,<< = 
 $M22r   i   c                 ,   [        5       n  U R                  U[        U5      -
  5      nX4-  n[        U5      S:X  d  [        U5      U:X  a  O MD  [        U5      U:w  a  Sn[        XRU[        U5      4-  5      eU$ ! [        R                   a     NDf = f)a_  Read from file-like object until size bytes are read.

TODO python2_drop: is it still needed? The docstring mentions python 2.6
and it looks like this can be at least simplified ...

Raises ValueError if not EOF is encountered before size bytes are read.
Non-blocking objects only supported if they derive from io objects.

Required as e.g. ZipExtFile in python 2.6 can return less data than
requested.

This function was taken from numpy/lib/format.py in version 1.10.2.

Parameters
----------
fp: file-like object
size: int
error_template: str

Returns
-------
a bytes object
    The data read in bytes.

r   z)EOF: reading %s, expected %d bytes got %d)bytesr<   r   r
   BlockingIOError
ValueError)fpsizeerror_templatedatarmsgs         r   _read_bytesrr      s    4 7D
	s4y()AID1v{c$i4/ 0  4yD9c$i@@AA !! 		s   ?A< <BBc                  j    [         R                  S S nUS:X  a  SSKJn  OUS:X  a  SSKJn  W" U 0 UD6$ )NrQ   z1.r   )_reconstructz2.)np__version__numpy.core.multiarrayrt   numpy._core.multiarray)argskwargsnp_major_versionnp_reconstructs       r   rt   rt     s;     ~~bq)4H	T	!I4*6**r   r   ))ra      )zran out of data)!__doc__
contextlibr
   pickler*   rS   r   r   r   numpyru   ImportError
_Unpickler	Unpickler_PicklerPicklerrangexrangebz2rH   r   r   r0   r6   rC   rK   rO   contextmanagerr^   rg   BUFFER_SIZErr   rt    r   r   <module>r      s    L  	  
  3 	
//	
 
 *2@@
@
 M+ M+`3( *Z+M  	B  
Cs"   A> B >B	B	BB