Your IP : 216.73.216.213


Current Path : /opt/alt/python35/lib/python3.5/site-packages/joblib/__pycache__/
Upload File :
Current File : //opt/alt/python35/lib/python3.5/site-packages/joblib/__pycache__/numpy_pickle_utils.cpython-35.pyc



��X�X�@s�dZddlZddlZddlZddlZddlZddlZddlZddlZddlm	Z	ddl
mZmZm
Z
mZyddlmZWn"ek
r�ddlmZYnXer�ejZejZeZnejZejZyddlZWnek
r.dZYnXyddlZWnek
rYdZYnXdZdZd	Zd
ZdZ dZ!d
ddddfZ"ej#ej$gZ%edk	r�e%j&ej'�e(dd�eeee e!fD��Z)ddZ*dd�Z+dd�Z,dd�Z-ej.ddd��Z/d
dfdd �Z0dZ1dZ2dZ3dZ4d!Z5Gd"d#�d#ej6�Z7Gd$d%�d%e7�Z8dd&Z9d'd(d)�Z:dS)*zFUtilities for fast persistence of big data, with optional compression.�N)�closing�)�PY3_OR_LATER�PY26�PY27�_basestring)�RLocksZFsxs�sBZs�7zXZs]�zlib�bz2�lzma�xz�gzipccs|]}t|�VqdS)N)�len)�.0�prefix�r�J/opt/alt/python35/lib/python3.5/site-packages/joblib/numpy_pickle_utils.py�	<genexpr>:sri�cCs�|jd�|jt�}|jd�|jt�r<dS|jt�rOdS|jt�rbdS|jt�rudS|jt�r�dS|jt	�r�dSdS)	z�Return the compressor matching fileobj.

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

    Returns
    -------
    str in {'zlib', 'gzip', 'bz2', 'lzma', 'xz', 'compat', 'not-compressed'}
    rr	r
r
rr�compatznot-compressed)
�seek�read�_MAX_PREFIX_LEN�
startswith�_ZLIB_PREFIX�_GZIP_PREFIX�_BZ2_PREFIX�_LZMA_PREFIX�
_XZ_PREFIX�
_ZFILE_PREFIX)�fileobj�first_bytesrrr�_detect_compressorDs 

r"cCs9tstr"t|tj�r"|Stj|dt�SdS)z0Return a buffered version of a read file object.�buffer_sizeN)rr�
isinstancer
�BZ2File�io�BufferedReader�_IO_BUFFER_SIZE)�fobjrrr�_buffered_read_filedsr*cCs?tstr(t|tj�r(t|�Stj|dt�SdS)z1Return a buffered version of a write file object.r#N)	rrr$r
r%rr&�BufferedWriterr()r)rrr�_buffered_write_fileos
r,ccs�t|�}t|tt��r-|jj}|dkr[tjd|tdd�|Vn�|t	ks|t|tt��r�|dk	r�tjdt
�dd�t|tj�r�|dk	r�tjdt
�dd�t|tt��r�|Vn�|dkrt
t|d	��Vn�|d
kr=t
t|d	��Vn�|dkr�trit
tj|d	��Vq�t
tj|jd	��Vnl|dks�|d
kr�tdk	r�t
tj|d	��Vq�tdjtjdtjd���n|VdS)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
    compressor: str in {'zlib', 'gzip', 'bz2', 'lzma', 'xz', 'compat',
                        'not-compressed'}
    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 file like object

    rzjThe file '%s' has been generated with a joblib version less than 0.10. Please regenerate this pickle file.�
stacklevelrNz�File "%(filename)s" is compressed using "%(compressor)s" which is not compatible with mmap_mode "%(mmap_mode)s" flag passed. mmap_mode option will be ignored.zuIn memory persistence is not compatible with mmap_mode "%(mmap_mode)s" flag passed. mmap_mode option will be ignored.r	�rbr
r
rrzHLzma decompression is not available for this version of python ({0}.{1})rr)r"r$�tuple�_COMPRESSOR_CLASSES�	__class__�__name__�warnings�warn�DeprecationWarning�_COMPRESSORS�localsr&�BytesIOr*�BinaryZlibFile�BinaryGzipFilerr
r%�namer�LZMAFile�NotImplementedError�format�sys�version_info)r �filename�	mmap_mode�
compressorrrr�_read_fileobject|sB	
			
rD�cCs�|d}|d}|dkr9tt|dd|��S|dkrattj|dd|��Stdk	r�|dkr�ttj|dd	tjd
|��Stdk	r�|dkr�ttj|dd
|dtj��Stt|dd|��SdS)
z6Return the right compressor file object in write mode.rrr
�wb�
compresslevelr
Nr�check�presetrr>)	r,r:r
r%rr<�
CHECK_NONE�FORMAT_ALONEr9)rA�compress�compressmethodrGrrr�_write_fileobject�s$



	

rNi c@s'eZdZdZejZdddd�Zdd�Ze	dd	��Z
d
d�Zdd
�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zdd�Zddd�Zddd �Zd0d"d#�Zd$d%�Zd&d'�Zd(d)�Zd*d+d,�Zd-d.�Zd/S)1r9a�A file object providing transparent zlib (de)compression.

    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.6.

    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 (default) produces the most compression.
    r.�	cCst�|_d|_d|_t|_d|_d|_t|t	�sfd|ko`dknr{t
dj|���|dkr�t}t
j|j�|_d|_d|_nO|dkr�t}t
j|t
j|jt
jd�|_nt
d	|f��t|t�r<t||�|_d
|_||_n?t|d�sZt|d�ro||_||_ntd
��dS)NFrrrOzFcompresslevel must be between an integer between 1 and 9, you gave {0}r.�rFzInvalid mode: %rTr�writez1filename must be a str or bytes object, or a file���)r�_lock�_fp�_closefp�_MODE_CLOSED�_mode�_pos�_sizer$�int�
ValueErrorr>�
_MODE_READr	�
decompressobj�wbits�
_decompressor�_buffer�_buffer_offset�_MODE_WRITE�compressobj�DEFLATED�
DEF_MEM_LEVEL�_compressorr�open�hasattr�	TypeError)�selfrA�moderG�	mode_coderrr�__init__s<					-					zBinaryZlibFile.__init__cCs�|j��|jtkrdSzV|jttfkrAd|_n1|jtkrr|jj|j	j
��d|_	Wdz|jr�|jj�Wdd|_d|_t|_d|_
d|_XXWdQRXdS)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.
        NFrPr)rSrWrVr\�_MODE_READ_EOFr_rbrTrQrf�flushrU�closer`ra)rjrrrrp9s"

					zBinaryZlibFile.closecCs
|jtkS)zTrue if this file is closed.)rWrV)rjrrr�closedSszBinaryZlibFile.closedcCs|j�|jj�S)z3Return the file descriptor for the underlying file.)�_check_not_closedrT�fileno)rjrrrrsXs
zBinaryZlibFile.filenocCs|j�o|jj�S)z)Return whether the file supports seeking.)�readablerT�seekable)rjrrrru]szBinaryZlibFile.seekablecCs|j�|jttfkS)z/Return whether the file was opened for reading.)rrrWr\rn)rjrrrrtas
zBinaryZlibFile.readablecCs|j�|jtkS)z/Return whether the file was opened for writing.)rrrWrb)rjrrr�writablefs
zBinaryZlibFile.writablecCs]|jrYt|jdd�}d}|dk	rC|dj|�7}|d7}t|��dS)Nr;zI/O operation on closed filez {0}�.)rq�getattrrTr>r[)rj�fname�msgrrrrrms	
z BinaryZlibFile._check_not_closedcCs2|jttfkr.|j�tjd��dS)NzFile not open for reading)rWr\rnrrr&�UnsupportedOperation)rjrrr�_check_can_readvs
zBinaryZlibFile._check_can_readcCs,|jtkr(|j�tjd��dS)NzFile not open for writing)rWrbrrr&r{)rjrrr�_check_can_write{s
zBinaryZlibFile._check_can_writecCsP|jttfkr.|j�tjd��|jj�sLtjd��dS)Nz3Seeking is only supported on files open for readingz3The underlying file object does not support seeking)rWr\rnrrr&r{rTru)rjrrr�_check_can_seek�s

zBinaryZlibFile._check_can_seekcCs�|jtkrdSx�|jt|j�kr�y.|jjpL|jjt	�}|s[t
�Wn+t
k
r�t|_|j|_dSYnX|jj
|�|_d|_qWdS)NFrT)rWrnrarr`r_�unused_datarTr�_BUFFER_SIZE�EOFErrorrXrY�
decompress)rj�rawblockrrr�_fill_buffer�s

		
zBinaryZlibFile._fill_bufferTcCs�|j|jd�|_d|_g}xG|j�rq|rM|j|j�|jt|j�7_d|_q+W|r�dj|�SdS)NrrP)r`rar��appendrXr�join)rj�return_data�blocksrrr�	_read_all�s	
zBinaryZlibFile._read_allcCs@|j|}|t|j�krd|j|j|�}||_|jt|�7_|r`|SdS|j|jd�|_d|_g}x�|dkr(|j�r(|t|j�kr�|jd|�}||_n|j}d|_|r|j|�|jt|�7_|t|�8}q�W|r<dj|�SdS)NrrP)rarr`rXr�r�r�)rj�n_bytesr��end�datar�rrr�_read_block�s*
				
zBinaryZlibFile._read_blockrc	CsR|j�B|j�|dkr$dS|dkr:|j�S|j|�SWdQRXdS)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.
        rrPN)rSr|r�r�)rj�sizerrrr�s


zBinaryZlibFile.readc
Cs(|j�tjj||�SWdQRXdS)z_Read up to len(b) bytes into b.

        Returns the number of bytes read (0 for EOF).
        N)rSr&�BufferedIOBase�readinto)rj�brrrr��s
zBinaryZlibFile.readintocCs�|j�r|j�tr6t|t�r6|j�}|jj|�}|jj	|�|j
t|�7_
t|�SWdQRXdS)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)rSr}rr$�
memoryview�tobytesrfrLrTrQrXr)rjr��
compressedrrrrQ�s

zBinaryZlibFile.writecCsP|jjdd�t|_d|_tj|j�|_d|_	d|_
dS)NrrP)rTrr\rWrXr	r]r^r_r`ra)rjrrr�_rewind�s			zBinaryZlibFile._rewindrcCs�|j��|j�|dkr#nj|dkr?|j|}nN|dkrz|jdkrj|jdd�|j|}ntd|f��||jkr�|j�n
||j8}|j|dd�|jSWdQRXdS)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.
        rrrr�FzInvalid value for whence: %sN)rSr~rXrYr�r[r�r�)rj�offset�whencerrrrs 



zBinaryZlibFile.seekc	Cs&|j�|j�|jSWdQRXdS)z!Return the current file position.N)rSrrrX)rjrrr�tell*s

zBinaryZlibFile.tellNrR)r2�
__module__�__qualname__�__doc__r	�	MAX_WBITSr^rmrp�propertyrqrsrurtrvrrr|r}r~r�r�r�rr�rQr�rr�rrrrr9�s,	)	
*r9c@seZdZdZdZdS)r:aA 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 (default) produces the most compression.
    �N)r2r�r�r�r^rrrrr:1sr:�zran out of datacCs�t�}xhyL|j|t|��}||7}t|�dksVt|�|krWPWqtjk
roYqXqWt|�|kr�d}t|||t|�f��n|SdS)aRead from file-like object until size bytes are read.

    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.

    rz)EOF: reading %s, expected %d bytes got %dN)�bytesrrr&�BlockingIOErrorr[)�fpr��error_templater��rrzrrr�_read_bytesHs	
$	"r�);r��pickler?r&r	r
r
r3�
contextlibr�_compatrrrr�	threadingr�ImportError�dummy_threading�
_Unpickler�	Unpickler�_Pickler�Pickler�range�xrange�numpy�nprrrrrrrr6�GzipFiler%r0r�r<�maxrr(r"r*r,�contextmanagerrDrNrVr\rnrbr�r�r9r:�BUFFER_SIZEr�rrrr�<module>st"
					

	
 
Y�;