%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python3/dist-packages/PIL/__pycache__/
Upload File :
Create Path :
Current File : //lib/python3/dist-packages/PIL/__pycache__/ImageFile.cpython-312.pyc

�

��e_��l�ddlmZddlZddlZddlZddlZddlmZmZddl	m
Z
ddlmZddl
mZdZd	Zd
Z	ddd
ddd�Z	d�Zd�Zd�ZGd�de�ZGd�de
j�ZGd�de�ZGd�d�Zd'd�Zd(d)d�Zd�ZGd�d �ZGd!�d"�ZGd#�d$e�ZGd%�d&e�Z y)*�)�annotationsN)�Any�
NamedTuple�)�Image)�	deprecate)�is_pathiiFzimage buffer overrun errorzdecoding errorz
unknown errorzbad configurationzout of memory error)������������i����c���	tjj|�}|s|rdnd�d|��}|d|rdnd�d�z
}t
|�S#t$rtj|�}Y�EwxYw)N�encoder�decoderz error z when �writing�readingz image file)r�core�getcodecstatus�AttributeError�ERRORS�get�OSError)�errorr�msgs   �//usr/lib/python3/dist-packages/PIL/ImageFile.py�_get_oserrorrCsv�� ��j�j�'�'��.���%��9�5�W�U�G�D���V��I�i�8��D�D�C��3�<���� ��j�j���� �s�A�A'�&A'c�8�tddd��t|d���)N�
raise_oserror�z�It is only useful for translating error codes returned by a codec's decode() method, which ImageFile already does automatically.)�actionF�r)rr)rs rrrNs%��
��
�G���u�e�
,�,�c��|dS)N��)�ts r�	_tilesortr'Xs���Q�4�Kr"c�6�eZdZUded<ded<ded<ded<y	)
�_Tile�str�encoder_nameztuple[int, int, int, int]�extents�int�offsetztuple[Any, ...] | str | None�argsN)�__name__�
__module__�__qualname__�__annotations__r%r"rr)r)]s����
&�&��K�
&�&r"r)c�R��eZdZdZd
�fd�	Zd�Z�fd�Zd�Zd�Zd�Z	d�Z
d	�Z�xZS)�	ImageFilez*Base class for image file format handlers.c�~��t�|��d|_d|_d|_	d|_d|_t|_t|�r t|d�|_||_d|_
n||_||_d|_
		|j�|j,r$|j.ddks|j.ddkr
d}t+|��y#tt t"t$t&j(f$r}t+|�|�d}~wwxYw#t0$r(|jr|jj3��wxYw)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)�selfrBrC�vr�	__class__s     �rr9zImageFile.__init__ls'���
�������#�����	�7���
����'����2�;��2�t�n�D�G��D�M�!%�D���D�G�$�D�M�!%�D��	�	
,��
�
���9�9��	�	�!��� 1�T�Y�Y�q�\�Q�5F�5��!�#�&�&�6G����������
,�"�!�n�!�+��
,���	��!�!����
�
���		�s*�C�=D�(D�7D�D�D�1D<c��|jr|jS|j�7tjj	|jj��Sy�N)r;�formatr�MIMEr�upper�rPs r�get_format_mimetypezImageFile.get_format_mimetype�sF������'�'�'��;�;�"��:�:�>�>�$�+�+�"3�"3�"5�6�6�#r"c�2��g|_t�|�	|�yrT)r<r8�__setstate__)rP�staterRs  �rr[zImageFile.__setstate__�s�����	�
���U�#r"c�^�|jr|jj�d|_y)zCheck file integrityN)rDrBrOrXs r�verifyzImageFile.verify�s!��
����G�G�M�M�O���r"c�D
�|j�
d}t|��tjj|�}|js|Sd|_|j
xrt
|j�dk(}|xrttd�}d}	|j}d}	|j}d}|�rU|jd\}}}	}
t|
t �r|
ddf}
|dk(�r&t
|
�dk\�r|
d|j"k(�r|
dtj$vr�	ddl}t)|j
�5}|j'|j+�d|j,�	�|_ddd�|	|j.d|
dzz|jj/�kDr
d
}t|��tj0j3|j|j.||	|
�|_d}|j6rd|j6_|j=�d}
|j�s�|jj?t@��	|jB}tEjF|jd��D��cgc]\}}tI|�d��c}}|_|jD�]\}}}	}
||	�tjJ|j"||
|jL�}	|jO|j4|�|jPr0|jS|j�|jUd
�d}
n^|}		||jV�}|s!t^rn?dt
|��d�}t|��||z}|jU|�\}}
|dkrn||d}�[|ja���g|_||_1|je�|jfr&|jhr|jjk�d|_|jst^s|
dkr
tm|
d���tjj|�S#t$r|jj}Y���wxYw#t$r|jj}Y���wxYw#1swY��/xYw#ttt:f$rd|_Y���wxYw#t$rd
}Y��{wxYwcc}}w#tXtZj\f$r}t^rYd}~��ed}t|�|�d}~wwxYw#|ja�wxYw)z"Load image data based on tile listNzcannot load this imager�pypy_version_inforF�raw�)�accesszbuffer is not large enoughr��keyr"c��|d|d|dfS)Nrrrbr%)r<s r�<lambda>z ImageFile.load.<locals>.<lambda>�s��T�!�W�d�1�g�t�A�w�,G�r"r
zimage file is truncatedzimage file is truncated (z bytes not processed)r!)7r<rr�load�maprC�len�hasattr�sys�	load_readrrB�read�	load_seek�seek�
isinstancer*rL�	_MAPMODES�mmaprA�fileno�ACCESS_READrMr�
map_buffer�im�palette�dirty�ImportError�load_prepare�sortr'�tile_prefix�	itertools�groupby�list�_getdecoderr>�setimage�pulls_fd�setfd�decoder@rFrJr�LOAD_TRUNCATED_IMAGES�cleanupr=�load_endrD�!_close_exclusive_fp_after_loadingrOr)rPr�pixel�use_mmapr=rnrp�decoder_namer,r.r/rsrB�err_code�prefix�_�tilesr�b�s�e�ns                      rrhzImageFile.load�s����9�9��*�C��#�,����� � ��&���y�y��L�����=�=�8�S����^�q�%8���E�G�C�1D�$E� E����	 ��>�>�D��H�	 ��>�>�D��H��26�)�)�A�,�/�L�'�6�4��$��$��a��|����%���I��N���G�t�y�y�(���G�u���.�$���d�m�m�,�V��#'�9�9�R�Y�Y�[�!�D�DT�DT�9�#U���V���	�	�!��t�A�w� 6�6�������H�:��%�c�l�*�#�j�j�3�3����$�)�)�\�6�4��D�G� !�H��|�|�-.����*�	
�������x�x��I�I�N�N�y�N�)�
��)�)��!*� 1� 1��I�I�G�!���A�u��U��B���D�I�8<�y�y�(
&�3��g�v�t��V���+�+��I�I�|�T�4�3E�3E���#&��$�$�T�W�W�g�6��'�'��
�
�d�g�g�.�#*�>�>�#�#6�q�#9��"��"�>�$(��)=�)=�$>��$%�#8�$)�),�,/��F�8�3H�)J�%(�+2�#�,�$6� !�A��A�*1�.�.��*;�K�A�x� �1�u� %� !�!�"��A�3#�8�O�O�%�Q(
&�T��	� ��
��
�
�����$�"H�"H��G�G�M�M�O�����x�x� 5�(�Q�,��x��7�7��{�{����%�%��e�	 ��7�7�<�<�D�	 ���	 ��7�7�<�<�D�	 ��$V�V��'���=�$�#�D�H�$��"�
���
����*%/����#=�>�#8�$)�*C�C�*1�#�,�A�$=��
>��2�O�O�%�s��P?�Q%�R�,2R�B#R�R:�1S�AT
�8S�
AT
�?Q"�!Q"�%R�R�R�R�R7�6R7�:S	�S	�T
�+T�1T
�7T�T
�
T
�
Tc�x�|jrF|jj|jk7s#|jj|jk7r9tjj|j|j�|_|jdk(r tjj
|�yy)N�P)rwrLrMrr�newrhrXs rr{zImageFile.load_prepare:sp���w�w�$�'�'�,�,�$�)�)�3�t�w�w�|�|�t�y�y�7P��j�j�n�n�T�Y�Y��	�	�:�D�G��9�9����K�K���T�"�r"c��yrTr%rXs rr�zImageFile.load_endBs��r"c���||jks4t|d�r|j�)||j|jzk\r
d}t	|��|j�|k7S)N�	_n_framesz attempt to seek outside sequence)r:rkr��n_framesrI�tell)rP�framers   r�_seek_checkzImageFile._seek_checkNsZ���D�O�O�#��T�;�/�D�N�N�4J��T�]�]�T�_�_�<�<�5�C��3�-���y�y�{�e�#�#r")NN)
r0r1r2�__doc__r9rYr[r^rhr{r�r��
__classcell__)rRs@rr5r5is1���4�.�`7�$��I&�V#�
�
$r"r5c�"�eZdZdZd�Zd�Zd�Zy)�
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.
    c��d}t|��)Nz+StubImageFile subclass must implement _open��NotImplementedError�rPrs  rrEzStubImageFile._openfs��;��!�#�&�&r"c���|j�}|�d|j�d�}t|��|j|�}|�J�|j|_|j
|_|j�S)Nzcannot find loader for this z file)�_loadrUrrhrR�__dict__)rP�loaderr�images    rrhzStubImageFile.loadjsj��������>�0����
�U�C�C��#�,�����D�!��� � � ����������
��z�z�|�r"c��d}t|��)z (Hook) Find actual image loader.z+StubImageFile subclass must implement _loadr�r�s  rr�zStubImageFile._loadvs��;��!�#�&�&r"N)r0r1r2r�rErhr�r%r"rr�r�^s���'�
�'r"r�c�F�eZdZdZdZdZdZdZdZdZ	d�Z
d�Zd�Zd�Z
d�Zy)	�Parserzj
    Incremental image parser.  This class implements the standard
    feed/close consumer interface.
    Nrc�*�|j�Jd��y)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)�datarXs r�resetzParser.reset�s���y�y� �8�"8�8� r"c�T�|jry|j�||_n|j|z|_|jr�|jdkDrmt	t|j�|j�}|j|d|_|j|z
|_|jdkDs|jsy|jj
|j�\}}|dkr(d|_d|_|dkrd|_t|d���y|j|d|_y|jry	tj|j�5}tj|�}ddd�td�xst|d�}|st|j�dk7rd|_||_y|j�|jd\}}}	}
g|_tj |j"||
|j$�|_|jj'|j(|�|	|_|jt|j�kr%|j|jd|_d|_||_y#1swY��%xYw#t*$rYywxYw)z�
        (Consumer) Feed data to the parser.

        :param data: A string buffer.
        :exception OSError: If the parser failed to parse the image file.
        NrrFr!rorm)�finishedr�rr.�minrjr�r�r�io�BytesIOrrArkr<r{r�rLr>r�rwr)rPr��skipr�r�rBrw�flag�d�o�as           r�feedzParser.feed�s(���=�=���9�9���D�I��	�	�D�(�D�I��<�<��{�{�Q���3�t�y�y�>�4�;�;�7�� �I�I�d�e�,��	�"�k�k�D�0����;�;��?�$�)�)���<�<�&�&�t�y�y�1�D�A�q��1�u� ��	� !��
��q�5�!%�D�J�&�q�%�8�8���	�	�!�"�
�D�I�
�Z�Z�
�
 ��Z�Z��	�	�*�(�b����B��B�(�
�r�;�/�K�7�2�{�3K���3�r�w�w�<�1�,�"&�D�K� ��
��O�O�%�!#�����J�A�q�!�Q� �B�G�#(�#4�#4�R�W�W�a��B�DT�DT�#U�D�L��L�L�)�)�"�%�%��3�#$�D�K��{�{�c�$�)�)�n�4�$(�I�I�d�k�k�m�$<��	�&'�����
�/(�(���
��
�s*�6J�J�+J�J�J�	J'�&J'c��|SrTr%rXs r�	__enter__zParser.__enter__�s���r"c�$�|j�yrT)rO�rPr/s  r�__exit__zParser.__exit__�s���
�
�r"c�,�|jr8|jd�dx|_|_|js
d}t	|��|j
s
d}t	|��|jrjt
j|j�5}	tj|�|_|j
j�	ddd�|j
S|j
S#|j
j�wxYw#1swY|j
SxYw)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.
        r"Nzimage was incompletezcannot parse this image)rr�r�r�rr�r�r�rrArh)rPrrBs   rrOzParser.close�s����<�<��I�I�c�N�'+�+�D�I����=�=�,���c�l�"��z�z�+�C��#�,���9�9����D�I�I�&�
&�"�&�!&���B��D�J��J�J�O�O�%�	
&�
�z�z��t�z�z����J�J�O�O�%��	
&�
�z�z��s$�	C?�C �%C?� C<�<C?�?D)r0r1r2r��incrementalr�r�rr.r�r�r�r�r�rOr%r"rr�r�|sB���
�K��E��D��G�
�F��H�9�J �X��r"r�c	��|j�t|d�sd|_|jt��tt||jddz�}	|j�}|j�t|||||�t|d�r|j�yy#ttjf$r}t||||d|�Yd}~�Ld}~wwxYw)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
    �
encoderconfigr%rdr�N�flush)rhrkr�r|r'�maxr?rMrtr��_encode_tilerr��UnsupportedOperation)rwrBr<�bufsize�fh�excs      r�_saver�s����G�G�I��2��'�����I�I�)�I��
�(�G�R�W�W�Q�Z�!�^�4�G�7�
�Y�Y�[��
���
��R��T�7�B�/��r�7��
���
���
�B�3�3�4�7��R��T�7�D�#�6�6��7�s�/B)�)C�C�Cc�0�|D]�\}}}}	|dkDr|j|�tj|j||	|j�}
	|
j|j|�|
jr%|
j|�|
j�d}nA|r-	|
j|�dd\}}|j|�|rn�,|
j||�}|dkrt|d��|�	|
j���y#|
j�wxYw)NrrTr!)rpr�_getencoderrLr�r�rw�	pushes_fdr��encode_to_pyfd�encode�write�encode_to_filerr�)
rwrBr<r�r�r�r+r,r.r/r�errcoder�s
             rr�r�!s��/3��+��g�v�t��A�:��G�G�F�O��#�#�B�G�G�\�4��AQ�AQ�R��	����R�U�U�G�,�� � ��
�
�b�!�!�0�0�2�1�5����(/���w�(?���(C�
��������"�!�	�&�4�4�R��A�G���{�"�7�D�9�s�B��
�O�O��/��.
�O�O��s
�B!D�Dc��|dkry|tkr.|j|�}t|�|kr
d}t|��|Sg}|}|dkDrG|jt	|t��}|sn%|j|�|t|�z}|dkDr�Gt
d�|D��|kr
d}t|��dj|�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

    rr"zTruncated File Readc3�2K�|]}t|����y�wrT)rj)�.0r�s  r�	<genexpr>z_safe_read.<locals>.<genexpr>Ys����
 �a�3�q�6�
 �s�)�	SAFEBLOCKrnrjrr��append�sum�join)rBrMr�r�remaining_size�blocks      r�
_safe_readr�<s����q�y���y���w�w�t�}���t�9�t��'�C��#�,����
�D��N�
�1�
�����N�I�6�7�������E���#�e�*�$���1�
��
 �4�
 � �4�'�#���c�l���8�8�D�>�r"c��eZdZd�Zd�Zy)�PyCodecStatec�<�d|_d|_d|_d|_y)Nr)�xsize�ysize�xoff�yoffrXs rr9zPyCodecState.__init__`s����
���
���	���	r"c��|j|j|j|jz|j|jzfSrT)r�r�r�r�rXs rr,zPyCodecState.extentsfs3���y�y�$�)�)�T�Y�Y����%;�T�Y�Y����=S�S�Sr"N)r0r1r2r9r,r%r"rr�r�_s
���Tr"r�c�,�eZdZd�Zd�Zd�Zd�Zdd�Zy)�PyCodecc�n�d|_t�|_d|_||_|j|�yrT)rwr�r\�fdrL�init)rPrLr/s   rr9zPyCodec.__init__ks+�����!�^��
������	��	�	�$�r"c��||_y)z�
        Override to perform codec specific initialization

        :param args: Array of args items from the tile entry
        :returns: None
        N)r/r�s  rr�zPyCodec.initrs����	r"c��y)zT
        Override to perform codec specific cleanup

        :returns: None
        Nr%rXs rr�zPyCodec.cleanup{s��	
r"c��||_y)z�
        Called from ImageFile to set the Python file-like object

        :param fd: A Python file-like object
        :returns: None
        N)r�)rPr�s  rr�z
PyCodec.setfd�s����r"Nc��||_|r|\}}}}nd\}}}}|dk(r=|dk(r8|jj\|j_|j_nJ||j_||j_||z
|j_||z
|j_|jjdks|jjdkr
d}t|��|jj|jj
z|jjdkDsG|jj|jjz|jjdkDr
d}t|��y)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)rwrMr\r�r�r�r��
ValueError)rPrwr,�x0�y0�x1�y1rs        rr�zPyCodec.setimage�s,������&��R��R��+��R��R��
��7�r�Q�w�15�����.�D�J�J��d�j�j�.� �D�J�J�O� �D�J�J�O�!�B�w�D�J�J��!�B�w�D�J�J���:�:���q� �D�J�J�$4�$4��$9�+�C��S�/�!�
�J�J���t�z�z���.������a��@��z�z���$�*�*�/�/�1�D�G�G�L�L��O�C�4�C��S�/�!�Dr"rT)r0r1r2r9r�r�r�r�r%r"rr�r�js����
��#"r"r�c�2�eZdZdZdZed��Zd�Zdd�Zy)�	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>`
    Fc��|jSrT)�	_pulls_fdrXs rr�zPyDecoder.pulls_fd�s���~�~�r"c��d}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`.
        zunavailable in base decoderr�)rP�bufferrs   rr�zPyDecoder.decode����,��!�#�&�&r"Nc�@�|s|j}tj|jd|�}|j|j|j
j
��|j|�}|ddk\r
d}t|��|ddk7r
d}t|��y)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
        rarznot enough image datarzcannot decode image dataN)	rLrr�r�rwr\r,r�r�)rPr��rawmoder�r�rs      r�
set_as_rawzPyDecoder.set_as_raw�s�����i�i�G����d�i�i���8��	�
�
�4�7�7�D�J�J�.�.�0�1�
�H�H�T�N���Q�4�1�9�)�C��S�/�!��Q�4�1�9�,�C��S�/�!�r"rT)	r0r1r2r�r��propertyr�r�rr%r"rr�r��s*����I�
����
'�"r"r�c�6�eZdZdZdZed��Zd�Zd�Zd�Z	y)�	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>`
    Fc��|jSrT)�
_pushes_fdrXs rr�zPyEncoder.pushes_fd�s�����r"c��d}t|��)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`.
        zunavailable in base encoderr�)rPr�rs   rr�zPyEncoder.encode�r�r"c��|jsy|jd�\}}}|r|jj|�||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`.
        )rr
r)r�r�r�r�)rP�bytes_consumedr�r�s    rr�zPyEncoder.encode_to_pyfd�s@���~�~��(,���A��%������G�G�M�M�$���w�&�&r"c�|�d}|dk(r4|j|�\}}}|dkDr|j||d�|dk(r�4|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�)rPr�r�r��status�bufs      rr�zPyEncoder.encode_to_file
sN������l�#'�;�;�w�#7� �F�G�S���z�����V�W��&���l��r"N)
r0r1r2r�rrr�r�r�r�r%r"rrr�s/����J�
����
'�
'�r"r)rrT)r<zlist[_Tile])!�
__future__rr�r~rJrl�typingrr�r�
_deprecater�_utilr	r?r�r�rrrr'r)r5r�r�r�r�r�r�r�r�rr%r"r�<module>rs���:#�	��
�
�"��!�����	���N�	%�����
����-��
'�J�'�r$����r$�j'�I�'�<C�C�R�8�6 �FT�T�E"�E"�P/"��/"�d7��7r"

Zerion Mini Shell 1.0