o �J�h%�@sdZddlZddlZddlZddlZddlZddlmZmZzddl Z Wn e y/dZ Ynwej Z ejZeZzddlZWn e yIdZYnwdZdd�Zdd �Zd d �Zd d �Zdd�Zdd�Zdd�Zejddd��Zd dd�ZdZd!dd�Zdd�Z dS)"zFUtilities for fast persistence of big data, with optional compression.�N�)� _COMPRESSORS� _ZFILE_PREFIXicCst|d|�}t|tj�S)z=Check if fileobj is a raw file object, e.g created with open.�raw)�getattr� isinstance�io�FileIO)�fileobj�r �WC:\pinokio\api\whisper-webui.git\app\env\lib\site-packages\joblib\numpy_pickle_utils.py� _is_raw_file&s  r cCs(dd�t��D�}|tt�g7}t|�S)NcSsg|]}t|j��qSr )�len�prefix)�.0� compressorr r r � <listcomp>.sz)_get_prefixes_max_len.<locals>.<listcomp>)r�valuesrr�max)�prefixesr r r �_get_prefixes_max_len,srcCs�tjdko!|jjdkp!|jjdko!|jjo!tdd�|jj��D��pCtjdkoC|jjdkpC|jjdkoC|jjoCtdd�|jj��D��S) z2Check if numpy array is having byte order mismatch�big�<�|cs��|] }|djdkVqdS)rrN�� byteorder�r�er r r � <genexpr><��z6_is_numpy_array_byte_order_mismatch.<locals>.<genexpr>�little�>csr)rr"Nrrr r r rFr )�sysr�dtype�fields�allr��arrayr r r �#_is_numpy_array_byte_order_mismatch3s   ��  ��r)cCs"t|�r|���|j�d��}|S)zzUse the byte order of the host while preserving values Does nothing if array already uses the system byte order. �=)r)�byteswap�viewr$� newbyteorderr'r r r �_ensure_native_byte_orderLsr.cCsht�}t|d�r|�|�}n |�|�}|�d�|�t�rdSt��D]\}}|�|j �r1|Sq#dS)z�Return the compressor matching fileobj. Parameters ---------- fileobj: file object Returns ------- str in {'zlib', 'gzip', 'bz2', 'lzma', 'xz', 'compat', 'not-compressed'} �peekr�compat�not-compressed) r�hasattrr/�read�seek� startswithrr�itemsr)r �max_prefix_lenZ first_bytes�namerr r r �_detect_compressorXs      �r9cC�tj|td�S)z0Return a buffered version of a read file object.�� buffer_size)r�BufferedReader�_IO_BUFFER_SIZE��fobjr r r �_buffered_read_filex�rAcCr:)z1Return a buffered version of a write file object.r;)r�BufferedWriterr>r?r r r �_buffered_write_file}rBrDccs��t|�}|}|dkrtjd|tdd�||fVdS|tvr-t|}|�|�}t|�}|durdd}t|tj �rDtjdt �dd�n |dkrStjdt �dd�nt |�sbtjd t �dd�n|}||fVdS) 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. r0zjThe 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.r1ztmmap_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.) r9�warnings�warn�DeprecationWarningr�decompressor_filerArr�BytesIO�localsr )r �filename� mmap_moder�validated_mmap_modeZcompressor_wrapper�instr r r �_validate_fileobject_and_memmap�sR���  ������rQ��zlib�cCsP|d}|d}|t��vrt|j||d�}t|�Stdj||d�}t|�S)z6Return the right compressor file object in write mode.rr)� compresslevelrS)r�keys�compressor_filerD)rM�compressZcompressmethodrUZ file_instancer r r �_write_fileobject�s ��rYi�ran out of datacCs�t�} z|�|t|��}||7}t|�dkst|�|kr Wn Wn tjy+Ynwqt|�|kr@d}t|||t|�f��|S)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. Trz)EOF: reading %s, expected %d bytes got %d)�bytesr3rr�BlockingIOError� ValueError)�fp�size�error_template�data�r�msgr r r � _read_bytes�s ��� rdcOsFtjdd�}|dkrddlm}n |dkrddlm}||i|��S)NrEz1.r)� _reconstructz2.)�np� __version__�numpy.core.multiarrayreZnumpy._core.multiarray)�args�kwargsZnp_major_versionZnp_reconstructr r r res  re)N)rR)rZ)!�__doc__� contextlibr�pickler#rGrrr�numpyrf� ImportError� _Unpickler� Unpickler�_Pickler�Pickler�range�xrange�bz2r>r rr)r.r9rArD�contextmanagerrQrY� BUFFER_SIZErdrer r r r �<module>sD  �  �    P  -
Memory