HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //home/arjun/projects/env/lib64/python3.10/site-packages/PIL/__pycache__/ImageFile.cpython-310.pyc
o

we�[�@s�ddlZddlZddlZddlZddlmZddlmZdZdZ	dZ
	dd	d
ddd
�Z	dd�Zdd�Z
Gdd�dej�ZGdd�de�ZGdd�d�Zd&dd�Zd'dd�Zdd�ZGdd�d�ZGd d!�d!�ZGd"d#�d#e�ZGd$d%�d%e�ZdS)(�N�)�Image)�is_pathiiFzimage buffer overrun errorzdecoding errorz
unknown errorzbad configurationzout of memory error)������������i����cCsLztj�|�}Wntyt�|�}Ynw|sd|��}|d7}t|��)Nzdecoder error z when reading image file)r�core�getcodecstatus�AttributeError�ERRORS�get�OSError)�error�msg�r�F/home/arjun/projects/env/lib/python3.10/site-packages/PIL/ImageFile.py�
raise_oserror@s�
rcCs|dS)N�r)�trrr�	_tilesortKsrcs^eZdZdZd�fdd�	Zdd�Z�fdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Z�ZS)�	ImageFilez*Base class for image file format handlers.Ncs�t���d|_d|_d|_	d|_d|_t|_t	|�r)t
|d�|_||_d|_
n	||_||_d|_
z8z|��WntttttjfyP}zt|�|�d}~ww|jrb|jddksb|jddkrhd}t|��WdStyz|j
ry|j���w)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$�vr��	__class__rrrXsJ
�
��"	�
�zImageFile.__init__cCs,|jr|jS|jdurtj�|j���SdS�N)r�formatr�MIMEr
�upper�r1rrr�get_format_mimetype�s

�zImageFile.get_format_mimetypecsg|_t��|�dSr5)rr�__setstate__)r1�stater3rrr;�szImageFile.__setstate__cCs|jr|j��d|_dS)zCheck file integrityN)r%r#r0r9rrr�verify�s

zImageFile.verifycCs�|jdurd}t|��tj�|�}|js|Sd|_|jo"t|j�dk}|o*ttd�}d}z|j	}d}Wn
t
yA|jj}Ynwz|j
}d}Wn
t
yV|jj}Ynw|r�|jd\}}}	}
|dkr�t|
�dkr�|
d|jkr�|
dtjvr�zOddl}t|j��}|j|��d|jd	�|_Wd�n1s�wY|	|jd|
d|j��kr�t�tj�|j|j||	|
�|_d}|jr�d|j_Wnt
ttfy�d|_Ynw|��d
}
|j�s�|jjtd�z|j}Wnt
y�d}Ynwd
d�t �!|jdd��D�|_|jD]�\}}}	}
||	�t�"|j||
|j#�}zw|�$|j|�|j%�r;|�&|j�|�'d�d}
nW|}	z||j(�}Wn t)t*j+f�ye}zt,�rZWYd}~n8d}t|�|�d}~ww|�syt,�rmn%dt|��d�}t|��||}|�'|�\}}
|dk�r�n||d�}�q>W|�-��q
|�-�wg|_||_.|�/�|j0�r�|j1�r�|j�2�d|_|j�s�t,�s�|
dk�r�t3|
�tj�|�S)z"Load image data based on tile listNzcannot load this imager�pypy_version_inforF�raw�)�accessr��key�cSsg|]
\}}t|�d�qS)r)�list)�.0�_�tilesrrr�
<listcomp>�s
��z"ImageFile.load.<locals>.<listcomp>cSs|d|d|dfS)Nrrr@r)rrrr�<lambda>�sz ImageFile.load.<locals>.<lambda>Tzimage file is truncatedzimage file is truncated (z bytes not processed))4rrr�load�mapr$�len�hasattr�sys�	load_readrr#�read�	load_seek�seekr-�	_MAPMODES�mmapr"�fileno�ACCESS_READr.r	�
map_buffer�im�palette�dirty�ImportError�load_prepare�sortr�tile_prefix�	itertools�groupby�_getdecoderr�setimage�pulls_fd�setfd�decoder!r'r+r�LOAD_TRUNCATED_IMAGES�cleanupr�load_endr%�!_close_exclusive_fp_after_loadingr0r)r1r�pixel�use_mmaprrQrS�decoder_name�extents�offset�argsrUr#�err_code�prefix�decoder�b�s�e�nrrrrK�s�
��� ��
�
�
���
����
��
zImageFile.loadcCsT|jr|jj|jks|jj|jkrtj�|j|j�|_|jdkr(tj�|�dSdS)N�P)rYr-r.rr	�newrKr9rrrr]$s
"
�zImageFile.load_preparecCsdSr5rr9rrrri,szImageFile.load_endcCsF||jkst|d�r|jdus||j|jkrd}t|��|��|kS)N�	_n_framesz attempt to seek outside sequence)rrNrz�n_framesr*�tell)r1�framerrrr�_seek_check8s
�
zImageFile._seek_check)NN)
�__name__�
__module__�__qualname__�__doc__rr:r;r=rKr]rir~�
__classcell__rrr3rrUs0	
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.
    cC�d}t|��)Nz+StubImageFile subclass must implement _open��NotImplementedError�r1rrrrr&PszStubImageFile._opencCsT|��}|durd|j�d�}t|��|�|�}|dusJ�|j|_|j|_|��S)Nzcannot find loader for this z file)�_loadr6rrKr4�__dict__)r1�loaderr�imagerrrrKTs
zStubImageFile.loadcCr�)z (Hook) Find actual image loader.z+StubImageFile subclass must implement _loadr�r�rrrr�`szStubImageFile._loadN)rr�r�r�r&rKr�rrrrr�Hs
r�c@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|jdus	Jd��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)�datar9rrr�resetsszParser.resetcCs�|jrdS|jdur||_n|j||_|jrh|jdkr=tt|j�|j�}|j|d�|_|j||_|jdks;|js=dS|j�|j�\}}|dkr^d|_d|_|dkr\d|_t|�ndS|j|d�|_dS|jrmdSzt	�
|j��
}t�|�}Wd�n1s�wYWn
t
y�YdSwt|d�p�t|d�}|s�t|j�dkr�d|_n:|��|jd\}}}	}
g|_t�|j||
|j�|_|j�|j|�|	|_|jt|j�kr�|j|jd�|_d|_||_dS)z�
        (Consumer) Feed data to the parser.

        :param data: A string buffer.
        :exception OSError: If the parser failed to parse the image file.
        NrrrRrP)�finishedr�rsro�minrMrfr�r�io�BytesIOrr"rrNrr]rbr-rrcrY)r1r��skiprwrvr#rY�flag�d�o�arrr�feed{sX	


���
zParser.feedcCs|Sr5rr9rrr�	__enter__�szParser.__enter__cGs|��dSr5)r0�r1rprrr�__exit__�szParser.__exit__c	Cs�|jr|�d�d|_|_|jsd}t|��|js d}t|��|jrOt�|j��}z
t�	|�|_W|j�
�n|j�
�wWd�|jS1sJwY|jS)a
        (Consumer) Close the stream.

        :returns: An image object.
        :exception OSError: If the parser failed to parse the image file either
                            because it cannot be identified or cannot be
                            decoded.
        rDNzimage was incompletezcannot parse this image)rsr�r�r�rr�r�r�rr"rK)r1rr#rrrr0�s$


��zParser.close)rr�r�r��incrementalr�r�rsror�r�r�r�r�r0rrrrr�fsMr�c
Cs�|��t|d�sd|_|jtd�tt||jdd�}z|��}|�	�t
|||||�Wnttj
fyM}zt
||||d|�WYd}~nd}~wwt|d�rY|�	�dSdS)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
    �
encoderconfigrrBr�N�flush)rKrNr�r^r�maxr r.rVr��_encode_tilerr��UnsupportedOperation)rYr#r�bufsize�fh�excrrr�_save�s 	
��
�r�c	Cs�|D]g\}}}}	|dkr|�|�t�|j||	|j�}
zI|
�|j|�|
jr2|
�|�|
�	�d}n|rJ	|
�
|�dd�\}}|�|�|rHnq5n|
�||�}|dkr_d|�d�}
t
|
�|�W|
��q|
��wdS)NrrTzencoder error z when writing image file)rSr�_getencoderr-r�rcrY�	pushes_fdre�encode_to_pyfd�encode�write�encode_to_filerrh)rYr#rr�r�r�rvrtr�r��encoder�errcoder�rrrrr�s0


�
��r�cCs�|dkrdS|tkr|�|�}t|�|krd}t|��|Sg}|}|dkr?|�t|t��}|s0n|�|�|t|�8}|dks%tdd�|D��|krPd}t|��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 cannot be completed

    rrDzTruncated File Readcss�|]}t|�VqdSr5)rM)rFr�rrr�	<genexpr>Es�z_safe_read.<locals>.<genexpr>)�	SAFEBLOCKrQrMrr��append�sum�join)r#r.r�r�remaining_size�blockrrr�
_safe_read(s*


�
r�c@seZdZdd�Zdd�ZdS)�PyCodecStatecCsd|_d|_d|_d|_dS)Nr)�xsize�ysize�xoff�yoffr9rrrrLs
zPyCodecState.__init__cCs |j|j|j|j|j|jfSr5)r�r�r�r�r9rrrrnRs zPyCodecState.extentsN)rr�r�rrnrrrrr�Ksr�c@s6eZdZdd�Zdd�Zdd�Zdd�Zdd
d�Zd	S)
�PyCodeccGs(d|_t�|_d|_||_|�|�dSr5)rYr�r<�fdr-�init)r1r-rprrrrWs
zPyCodec.__init__cC�
||_dS)z�
        Override to perform codec specific initialization

        :param args: Array of args items from the tile entry
        :returns: None
        N)rpr�rrrr�^�
zPyCodec.initcCsdS)zT
        Override to perform codec specific cleanup

        :returns: None
        Nrr9rrrrhgszPyCodec.cleanupcCr�)z�
        Called from ImageFile to set the Python file-like object

        :param fd: A Python file-like object
        :returns: None
        N)r�)r1r�rrrreor�z
PyCodec.setfdNcCs�||_|r|\}}}}nd\}}}}|dkr%|dkr%|jj\|j_|j_n||j_||j_|||j_|||j_|jjdksE|jjdkrKd}t|��|jj|jj|jjdksg|jj|jj|jjdkrmd}t|��dS)z�
        Called from ImageFile to set the core output image for the codec

        :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)rYr.r<r�r�r�r��
ValueError)r1rYrn�x0�y0�x1�y1rrrrrcxs$�zPyCodec.setimager5)rr�r�rr�rhrercrrrrr�Vs		r�c@s2eZdZdZdZedd��Zdd�Zd
dd	�ZdS)�	PyDecoderz�
    Python implementation of a format decoder. Override this class and
    add the decoding logic in the :meth:`decode` method.

    See :ref:`Writing Your Own File Codec in Python<file-codecs-py>`
    FcC�|jSr5)�	_pulls_fdr9rrrrd��zPyDecoder.pulls_fdcC�t��)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 -1 for the bytes consumed.
            Err codes are from :data:`.ImageFile.ERRORS`.
        r�)r1�bufferrrrrf��	zPyDecoder.decodeNcCsl|s|j}t�|jd|�}|�|j|j���|�|�}|ddkr(d}t|��|ddkr4d}t|��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
        r?rznot enough image datarzcannot decode image dataN)	r-rrbrcrYr<rnrfr�)r1r��rawmoder�rurrrr�
set_as_raw�s

�zPyDecoder.set_as_rawr5)	rr�r�r�r��propertyrdrfr�rrrrr��s
r�c@s8eZdZdZdZedd��Zdd�Zdd�Zd	d
�Z	dS)�	PyEncoderz�
    Python implementation of a format encoder. Override this class and
    add the decoding logic in the :meth:`encode` method.

    See :ref:`Writing Your Own File Codec in Python<file-codecs-py>`
    FcCr�r5)�
_pushes_fdr9rrrr��r�zPyEncoder.pushes_fdcCr�)a 
        Override to perform the encoding process.

        :param bufsize: Buffer size.
        :returns: A tuple of ``(bytes encoded, errcode, bytes)``.
            If finished with encoding return 1 for the error code.
            Err codes are from :data:`.ImageFile.ERRORS`.
        r�)r1r�rrrr��r�zPyEncoder.encodecCs2|jsdS|�d�\}}}|r|j�|�||fS)z�
        If ``pushes_fd`` is ``True``, then this method will be used,
        and ``encode()`` will only be called once.

        :returns: A tuple of ``(bytes consumed, errcode)``.
            Err codes are from :data:`.ImageFile.ERRORS`.
        )rrr)r�r�r�r�)r1�bytes_consumedr�r�rrrr��szPyEncoder.encode_to_pyfdcCsBd}|dkr|�|�\}}}|dkr|�||d��|dks|S)z�
        :param fh: File handle.
        :param bufsize: Buffer size.

        :returns: If finished successfully, return 0.
            Otherwise, return an error code. Err codes are from
            :data:`.ImageFile.ERRORS`.
        rN)r�r�)r1r�r�r��status�bufrrrr��s	�zPyEncoder.encode_to_fileN)
rr�r�r�r�r�r�r�r�r�rrrrr��s
r�)rr5)r�r`r+rO�r�_utilrr r�rgrrrrr�r�r�r�r�r�r�r�r�rrrr�<module>s>�
t

#H1