Your IP : 216.73.216.213


Current Path : /opt/alt/python35/lib64/python3.5/site-packages/PIL/__pycache__/
Upload File :
Current File : //opt/alt/python35/lib64/python3.5/site-packages/PIL/__pycache__/ImageFile.cpython-35.pyc



�ʴW�?�
@sddlmZddlmZddlZddlZddlZddlZdZdZ	dZ
d dd!d
d"dd#dd$diZdd�Zdd�Z
Gdd�dej�ZGdd�de�ZGdd�de�Zddd�Zdd�ZdS)%�)�Image)�isPathNiiF�zimage buffer overrun error�zdecoding error�z
unknown error�zbad configuration�	zout of memory errorcCs^ytjj|�}Wn!tk
r9tj|�}YnX|sJd|}t|d��dS)Nzdecoder error %dz when reading image file)r�coreZgetcodecstatus�AttributeError�ERRORS�get�IOError)�error�message�r�@/opt/alt/python35/lib64/python3.5/site-packages/PIL/ImageFile.py�
raise_ioerror4s

rcCs|dS)Nrr)�trrr�	_tilesortBsrc@sdeZdZdZdddd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dS)�	ImageFilez*Base class for image file format handlers.NcCs�tjj|�d|_d|_f|_t|_t|�r^t|d�|_	||_
n||_	||_
y|j�WnCtt
tttjfk
r�}zt|��WYdd}~XnX|js�|jddkr�td��dS)Nr�rbrznot identified by this driver)r�__init__�tile�readonly�
decoderconfig�MAXBLOCK�decodermaxblockr�open�fp�filename�_open�
IndexError�	TypeError�KeyError�EOFError�structr�SyntaxError�mode�size)�selfrr�vrrrrNs(						zImageFile.__init__cCsdS)zSet draft modeNr)r)r'r(rrr�draftlszImageFile.draftcCs
d|_dS)zCheck file integrityN)r)r)rrr�verifyqszImageFile.verifyc5Cs�tjj|�}|jdkr-td��|js:|Sd|_|jo^t|j�dk}|otttd�}d}y|j	}d}Wnt
k
r�|jj}YnXy|j
}d}Wnt
k
r�|jj}YnX|rQ|jd\}}}}	|dkrQ|	d|jkrQ|	dtjkrQy�ttjd�r�tjj|j�|_|jj|�|jj|j|j|	d|	d	�|_n�ddl}
t|jd
�}tjj|j�}|
j|j�|d|
j�|_tjj|j|j||||	�|_d}Wn$t
ttfk
rPd|_YnX|j�|js%|jj dt!�y
|j"}
Wnt
k
r�d
}
YnXx�|jD]x\}}}}tj#|j|||j$�}||�y|j%|j|�Wnt&k
rw�YnX|j'rC|j(|j�|j)d
�\}}n�|
}x�y||j*�}Wn1t+t,j-fk
r�t.r�Pntd��YnX|r�|j/r�g|_|j0�t.r�Pntdt|���||}|j)|�\}}|dkrP||d�}qLW|j0�q�Wg|_||_1d|_|jrgt.rg|dkrgt2|�t|d�r�|jj3|j4�|_|jj|_|j5�tjj|�S)z"Load image data based on tile listNzcannot load this imager�pypy_version_inforF�raw�mapr�r�access�key�zimage file is truncatedz0image file is truncated (%d bytes not processed)�tile_post_rotate)6r�loadrr
r/r�len�hasattr�sys�	load_readr
r�read�	load_seek�seekr'Z	_MAPMODESr	Z	readimager(�im�mmapr�os�path�getsize�filenoZACCESS_READZ
map_buffer�EnvironmentError�ImportError�load_prepare�sortrZtile_prefix�_getdecoderr�setimage�
ValueErrorZpulls_fd�setfd�decoderr!r%r�LOAD_TRUNCATED_IMAGESZhandles_eof�cleanuprr�rotater4�load_end)r)ZpixelZuse_mmaprr:r<�d�e�o�ar>rr(�prefixZdecoder_nameZextents�offset�args�decoder�statusZerr_code�b�s�nrrrr5xs�			

	

2	&$	!

	



		

			

zImageFile.loadcCsu|js4|jj|jks4|jj|jkrRtjj|j|j�|_|jdkrqtjj|�dS)N�P)r=r'r(rr	�newr5)r)rrrrE�s

*zImageFile.load_preparecCsdS)Nr)r)rrrrOszImageFile.load_end)
�__name__�
__module__�__qualname__�__doc__rr+r,r5rErOrrrrrKs�	rc@s:eZdZdZdd�Zdd�Zdd�ZdS)	�
StubImageFilez�
    Base class for stub image loaders.

    A stub loader is an image loader that can identify files of a
    certain format, but relies on external code to load the file.
    cCstd��dS)Nz+StubImageFile subclass must implement _open)�NotImplementedError)r)rrrr szStubImageFile._opencCsh|j�}|dkr+td|j��|j|�}|dk	sLt�|j|_|j|_dS)Nz#cannot find loader for this %s file)�_loadr
�formatr5�AssertionError�	__class__�__dict__)r)�loader�imagerrrr5szStubImageFile.loadcCstd��dS)z (Hook) Find actual image loader.z+StubImageFile subclass must implement _loadN)rc)r)rrrrd)szStubImageFile._loadN)r^r_r`rar r5rdrrrrrbs
rbc@s^eZdZdZdZdZdZdZdZdZ	dd�Z
dd�Zdd	�ZdS)
�Parserz�
    Incremental image parser.  This class implements the standard
    feed/close consumer interface.

    In Python 2.x, this is an old-style class.
    NrcCs|jdkstd��dS)z�
        (Consumer) Reset the parser.  Note that you can only call this
        method immediately after you've created a parser; parser
        instances cannot be reused.
        Nzcannot reuse parsers)�datarf)r)rrr�reset>szParser.resetcCsv|jr
dS|jdkr(||_n|j||_|jr&|jdkr�tt|j�|j�}|j|d�|_|j||_|jdks�|jr�dS|jj|j�\}}|dkr
d|_d|_|dkr	d|_t|�ndS|j|d�|_nL|jr2n@y7z%t	j
|j�}tj|�}Wd|j
�XWntk
r}Yn�Xt|d�p�t|d�}|s�t|j�dkr�d|_n�|j�|jd\}}}	}
g|_tj|j||
|j�|_|jj|j|�|	|_|jt|j�kri|j|jd�|_d|_||_dS)z�
        (Consumer) Feed data to the parser.

        :param data: A string buffer.
        :exception IOError: If the parser failed to parse the image file.
        Nrrr;r9)�finishedrlrWrU�minr6rKrjr�io�BytesIOrr�closer
r7rrErGr'rrHr=)r)rl�skipr[rQrr=�flagrPrRrSrrr�feedFsX						
	

			zParser.feedc
Cs�|jr;|jd�d|_|_|js;td��|jsPtd��|jr�z(tj|j�}tj	|�|_Wd|jj
�|j�X|jS)a
        (Consumer) Close the stream.

        :returns: An image object.
        :exception IOError: If the parser failed to parse the image file either
                            because it cannot be identified or cannot be
                            decoded.
        r3Nzimage was incompletezcannot parse this image)rWrurlrnr
rjrprqrrr5rr)r)rrrrrr�s
	
			
zParser.close)
r^r_r`raZincrementalrjrlrWrUrnrmrurrrrrrrk0sUrkcCs||j�t|d�s"f|_|jdt�tt||jdd�}|tj	krl|j
�dSy|j�}|j
�Wn	tt
jfk
r�x�|D]�\}}}}tj|j|||j�}|dkr�|j|d�|j|j|�|jr0|j|�|j�\}	}
n3x0|j|�\}	}
}|j|�|
r3Pq3W|
dkrtd|
��|j�q�WYn�Xx�|D]�\}}}}tj|j|||j�}|dkr�|j|d�|j|j|�|jr#|j|�|j�\}	}
n|j||�}
|
dkrQtd|
��|j�q�Wt|d�rx|j
�dS)z�Helper to save image based on tile list

    :param im: Image object.
    :param fp: File object.
    :param tile: Tile list.
    :param bufsize: Optional buffer size
    �
encoderconfigr2r�Nz(encoder error %d when writing image file�flush)r5r7rvrFr�maxrr(r8�stdoutrxrBr
rp�UnsupportedOperationrZ_getencoderr'r<rHr=Z	pushes_fdrJZencode_to_pyfd�encode�writer
rMZencode_to_file)r=rr�bufsizeZfhrQrYrRrS�lrZrPrrr�_save�sT	
	
	

	
r�cCs�|dkrdS|tkr)|j|�Sg}xL|dkr}|jt|t��}|s]P|j|�|t|�8}q2Wdj|�S)ao
    Reads large blocks in a safe way.  Unlike fp.read(n), this function
    doesn't trust the user.  If the requested size is larger than
    SAFEBLOCK, the file is read block by block.

    :param fp: File handle.  Must implement a <b>read</b> method.
    :param size: Number of bytes to read.
    :returns: A string containing up to <i>size</i> bytes of data.
    rr3)�	SAFEBLOCKr:ro�appendr6�join)rr(rl�blockrrr�
_safe_read�s


r�i���������i����i����)ZPILrZ	PIL._utilrrpr?r8r%rr�rLrrrrrb�objectrkr�r�rrrr�<module>s(	��>