HEX
Server: Apache
System: Linux srv1.prosuiteplus.com 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64
User: prosuiteplus (1001)
PHP: 8.3.20
Disabled: NONE
Upload Files
File: //lib/python3/dist-packages/PIL/__pycache__/ImageFile.cpython-38.pyc
U

tCf
R�@s�ddlZddlZddlZddlmZddlmZdZdZdZ	dd	d
ddd
�Z
dd�Zdd�ZGdd�dej�Z
Gdd�de
�ZGdd�d�Zd dd�Zdd�ZGdd�d�ZGdd�d�ZdS)!�N�)�Image)�isPathiiFzimage buffer overrun errorzdecoding errorz
unknown errorzbad configurationzout of memory error)���������i����i����cCsLztj�|�}Wntk
r.t�|�}YnX|s<d|}t|d��dS)Nzdecoder error %dz when reading image file)r�coreZgetcodecstatus�AttributeError�ERRORS�get�OSError)�error�message�r�//usr/lib/python3/dist-packages/PIL/ImageFile.py�
raise_ioerror4srcCs|dS)N�r)�trrr�	_tilesortCsrcsReZdZdZd�fdd�	Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
�ZS)�	ImageFilez*Base class for image file format handlers.Ncs�t���d|_d|_d|_d|_d|_t|_t	|�rPt
|d�|_||_d|_
n||_||_d|_
zdz|��Wn6tttttjfk
r�}zt|��W5d}~XYnX|jr�|jddkr�td��Wn&tk
r�|j
r�|j���YnXdS)Nrrr�rbTznot identified by this driver)�super�__init__�
_min_frame�custom_mimetype�tile�readonly�
decoderconfig�MAXBLOCK�decodermaxblockr�open�fp�filename�
_exclusive_fp�_open�
IndexError�	TypeError�KeyError�EOFError�structr
�SyntaxError�mode�size�
BaseException�close)�selfr!r"�v��	__class__rrrPs>
�
zImageFile.__init__cCs,|jr|jS|jdk	r(tj�|j���SdS�N)r�formatrZMIMEr�upper�r/rrr�get_format_mimetype}s
zImageFile.get_format_mimetypecCs|jr|j��d|_dS)zCheck file integrityN)r#r!r.r6rrr�verify�s
zImageFile.verifyc
Cs�tj�|�}|jdkrtd��|js(|Sd|_|jo@t|j�dk}|oPttd�}d}z|j	}d}Wnt
k
r�|jj}YnXz|j
}d}Wnt
k
r�|jj}YnX|�r�|jd\}}}}	|dk�r�t|	�dk�r�|	d|jk�r�|	dtjk�r�z�ttjd	��rLtj�|j�|_|j�|�|j�|j|j|	d|	d
�|_nTddl}
t|jd��}|
j|��d|
jd�|_W5QRXtj�|j|j||||	�|_d}|j�r�d|j_Wn"t
ttfk
�r�d|_YnX|��d
}|j�s4|jjtd�z
|j }
Wnt
k
�r d}
YnX|jD�]\}}}}	t�!|j||	|j"�}z�||�|�$|j|�|j%�r�|�&|j�|�'d�\}}n�|
}z||j(�}Wn2t)t*j+fk
�r�t,�r�Y�q"ntd��YnX|�s�t,�rސq"ntdt|���||}|�'|�\}}|dk�r�q"||d�}�q�W5|�#�X�q(g|_||_-|�.�|j/�rb|j0�rb|j�1�d|_|j�s�t,�s�|dk�r�t2|�tj�|�S)z"Load image data based on tile listNzcannot load this imagerZpypy_version_inforF�raw��mapr�r)�accessr��key�zimage file is truncatedz0image file is truncated (%d bytes not processed))3r�loadrrr;r"�len�hasattr�sys�	load_readr	r!�read�	load_seek�seekr+Z	_MAPMODESrZ	readimager,�im�mmapr �filenoZACCESS_READZ
map_bufferZpaletteZdirty�ImportError�load_prepare�sortrZtile_prefix�_getdecoderr�cleanup�setimage�pulls_fd�setfd�decoderr%r)r
�LOAD_TRUNCATED_IMAGESr�load_endr#Z!_close_exclusive_fp_after_loadingr.r)r/ZpixelZuse_mmaprrFrHZdecoder_name�extents�offset�argsrJr!Zerr_code�prefix�decoderZstatus�b�s�nrrrrA�s�
�
������

���

zImageFile.loadcCsP|jr"|jj|jks"|jj|jkr6tj�|j|j�|_|jdkrLtj�|�dS)N�P)rIr+r,rr�newrAr6rrrrMs"
zImageFile.load_preparecCsdSr3rr6rrrrVszImageFile.load_endcCsB||jks.t|d�r|jdks6||j|jkr6td��|��|kS)N�	_n_framesz attempt to seek outside sequence)rrCraZn_framesr(�tell)r/�framerrr�_seek_check&s����	zImageFile._seek_check)NN)�__name__�
__module__�__qualname__�__doc__rr7r8rArMrVrd�
__classcell__rrr1rrMs-	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.
    cCstd��dS)Nz+StubImageFile subclass must implement _open��NotImplementedErrorr6rrrr$=szStubImageFile._opencCsH|��}|dkrtd|j��|�|�}|dk	s4t�|j|_|j|_dS)Nz#cannot find loader for this %s file)�_loadrr4rA�AssertionErrorr2�__dict__)r/�loader�imagerrrrA@s
zStubImageFile.loadcCstd��dS)z (Hook) Find actual image loader.z+StubImageFile subclass must implement _loadNrkr6rrrrmJszStubImageFile._loadN)rerfrgrhr$rArmrrrrrj5s
rjc@sPeZdZdZdZdZdZdZdZdZ	dd�Z
dd�Zdd	�Zd
d�Z
dd
�ZdS)�Parserzj
    Incremental image parser.  This class implements the standard
    feed/close consumer interface.
    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)�datarnr6rrr�reset\szParser.resetc	Cs�|jr
dS|jdkr||_n|j||_|jr�|jdkrztt|j�|j�}|j|d�|_|j||_|jdksv|jszdS|j�|j�\}}|dkr�d|_d|_|dkr�d|_t|�ndS|j|d�|_n�|jr�n�z&t	�
|j��}t�|�}W5QRXWnt
k
�rYn�Xt|d��p(t|d�}|�s@t|j�dk�rHd|_nv|��|jd\}}}	}
g|_t�|j||
|j�|_|j�|j|�|	|_|jt|j�k�r�|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.
        NrrrGrE)�finishedrsr[rX�minrBrTrqr�io�BytesIOrr rrCrrMrOr+rrQrI)r/rs�skipr^�er!rI�flag�d�o�arrr�feeddsR	


zParser.feedcCs|Sr3rr6rrr�	__enter__�szParser.__enter__cGs|��dSr3)r.�r/rYrrr�__exit__�szParser.__exit__c	Csz|jr*|�d�d|_|_|js*td��|js8td��|jrtt�|j��$}zt	�
|�|_W5|j��XW5QRX|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.
        r@Nzimage was incompletezcannot parse this image)r[rrsrurrqrwrxrArr )r/r!rrrr.�s

zParser.close)rerfrgrhZincrementalrqrsr[rXrurtrr�r�r.rrrrrrOsPrrc
Cs�|��t|d�sd|_|jtd�tt||jdd�}|tj	krP|�
�dSz|��}|�
�Wn�tt
jfk
�r&|D]�\}}}}t�|j|||j�}|dkr�|�|�|�|j|�|jr�|�|�|��\}	}
n$|�|�\}	}
}|�|�|
rސqq�|
dk�rtd|
��|��q�Yn�X|D]�\}}}}t�|j|||j�}|dk�r`|�|�|�|j|�|j�r�|�|�|��\}	}
n|�||�}
|
dk�r�td|
��|���q,t|d��r�|�
�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
    �
encoderconfigrr>r�Nz(encoder error %d when writing image file�flush)rArCr�rNr�maxrr,rD�stdoutr�rKr	rw�UnsupportedOperationrZ_getencoderr+rHrQrIZ	pushes_fdrSZencode_to_pyfd�encode�writerrPZencode_to_file)rIr!r�bufsizeZfhrzr\r}r~�lr]r|rrr�_save�sR	









r�cCs�|dkrdS|tkr6|�|�}t|�|kr2td��|Sg}|dkrp|�t|t��}|sXqp|�|�|t|�8}q:tdd�|D��|kr�td��d�|�S)a�
    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 <i>size</i> bytes of data.

    Raises an OSError if the file is truncated and the read can not be completed

    rr@zTruncated File Readcss|]}t|�VqdSr3)rB)�.0r|rrr�	<genexpr>3sz_safe_read.<locals>.<genexpr>)�	SAFEBLOCKrFrBrrv�append�sum�join)r!r,rs�blockrrr�
_safe_reads"


r�c@seZdZdd�Zdd�ZdS)�PyCodecStatecCsd|_d|_d|_d|_dS)Nr)�xsize�ysize�xoff�yoffr6rrrr;szPyCodecState.__init__cCs |j|j|j|j|j|jfSr3)r�r�r�r�r6rrrrWAszPyCodecState.extentsN)rerfrgrrWrrrrr�:sr�c@s\eZdZdZdZdd�Zdd�Zedd��Zd	d
�Z	dd�Z
d
d�Zddd�Zddd�Z
dS)�	PyDecoderz�
    Python implementation of a format decoder. Override this class and
    add the decoding logic in the `decode` method.

    See :ref:`Writing Your Own File Decoder in Python<file-decoders-py>`
    FcGs(d|_t�|_d|_||_|�|�dSr3)rIr��state�fdr+�init)r/r+rYrrrrOs
zPyDecoder.__init__cCs
||_dS)z�
        Override to perform decoder specific initialization

        :param args: Array of args items from the tile entry
        :returns: None
        N)rYr�rrrr�VszPyDecoder.initcCs|jSr3)�	_pulls_fdr6rrrrR_szPyDecoder.pulls_fdcCs
t��dS)a'
        Override to perform the decoding process.

        :param buffer: A bytes object with the data to be decoded.
        :returns: A tuple of (bytes consumed, errcode).
            If finished with decoding return <0 for the bytes consumed.
            Err codes are from `ERRORS`
        Nrk)r/�bufferrrrrTcs	zPyDecoder.decodecCsdS)zV
        Override to perform decoder specific cleanup

        :returns: None
        Nrr6rrrrPnszPyDecoder.cleanupcCs
||_dS)z�
        Called from ImageFile to set the python file-like object

        :param fd: A python file-like object
        :returns: None
        N)r�)r/r�rrrrSvszPyDecoder.setfdNcCs�||_|r|\}}}}nd\}}}}|dkrJ|dkrJ|jj\|j_|j_n(||j_||j_|||j_|||j_|jjdks�|jjdkr�td��|jj|jj|jjdks�|jj|jj|jjdkr�td��dS)z�
        Called from ImageFile to set the core output image for the decoder

        :param im: A core image object
        :param extents: a 4 tuple of (x0, y0, x1, y1) defining the rectangle
            for this tile
        :returns: None
        )rrrrrzSize cannot be negativerz Tile cannot extend outside imageN)rIr,r�r�r�r�r��
ValueError)r/rIrWZx0Zy0Zx1Zy1rrrrQs"��zPyDecoder.setimagecCsd|s
|j}t�|jd|�}|�|j|j���|�|�}|ddkrLtd��|ddkr`td��dS)a
        Convenience method to set the internal image from a stream of raw data

        :param data: Bytes to be set
        :param rawmode: The rawmode to be used for the decoder.
            If not specified, it will default to the mode of the image
        :returns: None
        r9rznot enough image datarzcannot decode image dataN)	r+rrOrQrIr�rWrTr�)r/rsZrawmoder|r]rrr�
set_as_raw�s

zPyDecoder.set_as_raw)N)N)rerfrgrhr�rr��propertyrRrTrPrSrQr�rrrrr�Es	
	
#r�)r)rwr)rD�rZ_utilrrr�rUr
rrrrjrrr�r�r�r�rrrr�<module>s0�	
i
>"