o �J�hQK�@s�dZddlZddlZddlmZzddlmZWney'ddlmZYnwzddl Z Wn ey9dZ Ynwz ddl Z ddl m Z Wn eyQdZ Ynwzddl Z Wn eycdZ YnwdZiadZdZd Zd Zd Zd Zd Zd'dd�ZGdd�d�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�ZdZdZdZdZ dZ!Gdd �d ej"�Z#Gd!d"�d"e�Z$Gd#d$�d$e#�Z%Gd%d&�d&e�Z&dS)(z/Classes and functions for managing compressors.�N)� LooseVersion)�RLock)� LZ4FrameFilezMLZ4 is not installed. Install it with pip: https://python-lz4.readthedocs.io/sZF�xs�sBZs�7zXZs]s"MFcCs�t|t�s td�|���t|t�std�|���|jdur=t|jd�r5t|jd�r5t|jd�r5t|jd�s=td�|j���|tvrJ|sJtd �|���|t|<dS) z�Register 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)Zcompressor_name� compressor�force�r�OC:\pinokio\api\whisper-webui.git\app\env\lib\site-packages\joblib\compressor.py�register_compressor/s6 � �  � � � ���  rc@s,eZdZdZd dd�Zd dd�Zd d �ZdS) ra�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. ��cCs||_||_||_dS�N)r�prefix� extension)�self�objrrrrr�__init__hs zCompressorWrapper.__init__NcCs$|dur |�|d�S|j|d|d�S��0Returns an instance of a compressor file object.N�wb)� compresslevel�r�r�fileobjr"rrr�compressor_filems z!CompressorWrapper.compressor_filecCs |�|d�S�z2Returns an instance of a decompressor file object.�rbr#�rr%rrr�decompressor_filet� z#CompressorWrapper.decompressor_file)rrr)�__name__� __module__� __qualname__�__doc__rr&r*rrrrrXs    rc@�6eZdZeZdZdd�Zdd�Zd dd�Zd d �Z dS) �BZ2CompressorWrapperz.bz2cCstdur tj|_dSd|_dSr)�bz2�BZ2Filer�rrrrr}s  zBZ2CompressorWrapper.__init__cC�tdurtd��dS)Nz;bz2 module is not compiled on your python standard library.)r2r r4rrr�_check_versions�� ��z$BZ2CompressorWrapper._check_versionsNcC�,|��|dur|�|d�S|j|d|d�Sr�r6rr$rrrr&�� z$BZ2CompressorWrapper.compressor_filecCs|��|�|d�}|Sr'r9r)rrrr*�s z&BZ2CompressorWrapper.decompressor_filer) r,r-r.� _BZ2_PREFIXrrrr6r&r*rrrrr1ys  r1c@s:eZdZeZdZdZdd�Zdd�Zd dd �Z d d �Z dS) �LZMACompressorWrapperz.lzma� FORMAT_ALONEcCs,tdurtj|_tt|j�|_dSd|_dSr)�lzma�LZMAFiler�getattr�_lzma_format_name� _lzma_formatr4rrrr�s zLZMACompressorWrapper.__init__cCr5)Nz<lzma module is not compiled on your python standard library.)r>r r4rrrr6�r7z%LZMACompressorWrapper._check_versionsNcCs.|dur |j|d|jd�S|j|d|j|d�S)r Nr!)r )r �preset)rrBr$rrrr&�s  �z%LZMACompressorWrapper.compressor_filecCs t�|d�Sr')r>r?r)rrrr*�r+z'LZMACompressorWrapper.decompressor_filer) r,r-r.� _LZMA_PREFIXrrrArr6r&r*rrrrr<�s  r<c@seZdZeZdZdZdS)�XZCompressorWrapperz.xz� FORMAT_XZN)r,r-r.� _XZ_PREFIXrrrArrrrrE�srEc@r0) �LZ4CompressorWrapperz.lz4cCstdur t|_dSd|_dSr)�lz4rrr4rrrr�s  zLZ4CompressorWrapper.__init__cCsHtdurtt��tj}|�d�r|dd�}t|�td�kr"tt��dS)N�v�z0.19)rIr �LZ4_NOT_INSTALLED_ERROR� __version__� startswithr)rZ lz4_versionrrrr6�s  �z$LZ4CompressorWrapper._check_versionsNcCr8)r Nr!)�compression_levelr9r$rrrr&�r:z$LZ4CompressorWrapper.compressor_filecCs|��|�|d�Sr'r9r)rrrr*�s z&LZ4CompressorWrapper.decompressor_filer) r,r-r.� _LZ4_PREFIXrrrr6r&r*rrrrrH�s rHrK��i c@s�eZdZdZejZd0dd�Zdd�Ze dd ��Z d d �Z d d �Z dd�Z dd�Zdd�Zdd�Zdd�Zdd�Zdd�Zd1dd�Zd1dd �Zd2d"d#�Zd$d%�Zd&d'�Zd(d)�Zd3d+d,�Zd-d.�Zd/S)4�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(rRcCst�|_d|_d|_t|_d|_d|_||_t |t �r&d|kr%dks-nt d� |���|dkrBt |_t�|j�|_d|_d|_n|d krXt|_t�|jtj|jtjd�|_nt d |f��t |t�rpt�||�|_d |_dSt|d �szt|d �r||_dStd��)NFr�����rK� zS'compresslevel' must be an integer between 1 and 9. You provided 'compresslevel={}'r(rr!zInvalid mode: %rTrrz1filename 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"rrrrs: ��   zBinaryZlibFile.__init__cCsN|j��|jtkr Wd�dSzG|jttfvrd|_n|jtkr/|j�|j � ��d|_ Wz|j r9|j� �Wd|_d|_ t|_d|_ d|_nKd|_d|_ t|_d|_ d|_wz*|j rt|j� �Wd|_d|_ t|_d|_ d|_wWd|_d|_ t|_d|_ d|_wd|_d|_ t|_d|_ d|_wWd�dS1s�wYdS)z�Flush 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. NFrr)rVrZrYr^�_MODE_READ_EOFrbrerWrri�flushrX�closercrdr4rrrrq(sZ � � ��� �� "�zBinaryZlibFile.closecCs |jtkS)zTrue if this file is closed.)rZrYr4rrr�closedBs zBinaryZlibFile.closedcCs|��|j��S)z3Return the file descriptor for the underlying file.)�_check_not_closedrW�filenor4rrrrtG� zBinaryZlibFile.filenocCs|��o|j��S)z)Return whether the file supports seeking.)�readablerW�seekabler4rrrrwLszBinaryZlibFile.seekablecCs|��|jttfvS)z/Return whether the file was opened for reading.)rsrZr^ror4rrrrvPszBinaryZlibFile.readablecCs|��|jtkS)z/Return whether the file was opened for writing.)rsrZrer4rrr�writableUruzBinaryZlibFile.writablecCsB|jrt|jdd�}d}|dur|d�|�7}|d7}t|��dS)N�namezI/O operation on closed filez {}�.)rrr@rWr r )r�fname�msgrrrrs\s�z BinaryZlibFile._check_not_closedcCs$|jttfvr|��t�d��dS)NzFile not open for reading)rZr^rorsrj�UnsupportedOperationr4rrr�_check_can_reades �zBinaryZlibFile._check_can_readcCs |jtkr|��t�d��dS)NzFile not open for writing)rZrersrjr}r4rrr�_check_can_writejs  �zBinaryZlibFile._check_can_writecCs8|jttfvr|��t�d��|j��st�d��dS)Nz3Seeking is only supported on files open for readingz3The underlying file object does not support seeking)rZr^rorsrjr}rWrwr4rrr�_check_can_seekos� ��zBinaryZlibFile._check_can_seekcCs�|jtkrdS|jt|j�krCz|jjp|j�t �}|st �Wnt y0t|_|j |_ YdSw|j� |�|_d|_|jt|j�ksdS)NFrT)rZrord�lenrcrb� unused_datarWr� _BUFFER_SIZE�EOFErrorr[r\� decompress)r�rawblockrrr� _fill_buffer{s" � �� zBinaryZlibFile._fill_bufferTcCsh|j|jd�|_d|_g}|��r+|r|�|j�|jt|j�7_d|_|��s|r2d�|�SdS�Nrr)rcrdr��appendr[r��join)r� return_data�blocksrrr� _read_all�s � �zBinaryZlibFile._read_allcCs�|j|}|t|j�kr&|j|j|�}||_|jt|�7_|r$|SdS|j|jd�|_d|_g}|dkrr|��rr|t|j�krN|jd|�}||_n|j}d|_|r[|�|�|jt|�7_|t|�8}|dkrr|��s<|ryd�|�SdSr�)rdr�rcr[r�r�r�)r�n_bytesr��end�datar�rrr� _read_block�s.    � �zBinaryZlibFile._read_blockrTcCst|j�-|��|dkr Wd�dS|dkr$|��Wd�S|�|�Wd�S1s3wYdS)z�Read 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. rNr)rVr~r�r�)r�sizerrrr�s��$�zBinaryZlibFile.readcCs8|j�tj�||�Wd�S1swYdS)z_Read up to len(b) bytes into b. Returns the number of bytes read (0 for EOF). N)rVrj�BufferedIOBase�readinto)r�brrrr��s $�zBinaryZlibFile.readintocCsv|j�.|��t|t�r|��}|j�|�}|j�|�|j t |�7_ t |�Wd�S1s4wYdS)z�Write 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) rVrr � memoryview�tobytesri�compressrWrr[r�)rr�� compressedrrrr�s   $�zBinaryZlibFile.writecCs8|j�dd�t|_d|_t�|j�|_d|_ d|_ dSr�) rWrr^rZr[r_r`rarbrcrdr4rrr�_rewind�s  zBinaryZlibFile._rewindrcCs�|j�P|��|dkr n&|dkr|j|}n|dkr,|jdkr&|jdd�|j|}ntd|f��||jkr=|��n||j8}|j|dd�|jWd�S1sVwYdS)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. rrKrQF)r�zInvalid value for whence: %sN)rVr�r[r\r�r r�r�)r�offset�whencerrrr�s"       $�zBinaryZlibFile.seekcCs8|j�|��|jWd�S1swYdS)z!Return the current file position.N)rVrsr[r4rrrr s$�zBinaryZlibFile.tellN)r(rR)T)rT)r)r,r-r.r/r_� MAX_WBITSrarrq�propertyrrrtrwrvrxrsr~rr�r�r�r�rr�rr�rr rrrrrS�s0 &       *rSc@�eZdZdd�ZdS)�ZlibCompressorWrappercC�tj|ttdd�dS)Nz.z�rrr)rrrS� _ZLIB_PREFIXr4rrrr!� �zZlibCompressorWrapper.__init__N�r,r-r.rrrrrr� � r�c@seZdZdZdZdS)�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)r,r-r.r/rarrrrr�'s r�c@r�)�GzipCompressorWrappercCr�)Nz.gzr�)rrr�� _GZIP_PREFIXr4rrrr9r�zGzipCompressorWrapper.__init__Nr�rrrrr�8r�r�)F)'r/rjr_Zjoblib.backportsr� threadingr� ImportError�dummy_threadingr2rIZ lz4.framerr>rLrZ _ZFILE_PREFIXr�r�r;rGrDrPrrr1r<rErHrYr^rorer�r�rSr�r�r�rrrr�<module>sh  �  � �  �� )! #:
Memory