
    :hwr                    ,   d dl mZ d dlZd dlZd dlZd dlZd dlZd dlZd dlm	Z	m
Z
mZmZ ddlmZmZ ddlmZ ddlmZmZ dZerdd	lmZ  ej0                  e      Zd
ZdZdZ	 ddddddZ	 d+dZd,dZ d-dZ! G d de      Z" G d dej                        Z# G d dejH                        Z% G d de#ejL                        Z' G d d      Z(d.d/d Z)	 d0	 	 	 	 	 	 	 	 	 	 	 	 	 d1d!Z*d2d"Z+ G d# d$      Z, G d% d&      Z- G d' d(e-      Z. G d) d*e-      Z/y)3    )annotationsN)IOAny
NamedTuplecast   )ExifTagsImage)	deprecate)DeferredErroris_pathF)StrOrBytesPathi   i   zimage buffer overrun errorzdecoding errorzunknown errorzbad configurationzout of memory error)ic                   	 t         j                  j                  |       }|s|rdnd d|  }|d|rdnd dz  }t        |      S # t        $ r t        j                  |       }Y Ew xY w)Nencoderdecoderz error z when writingreadingz image file)r
   coregetcodecstatusAttributeErrorERRORSgetOSError)errorr   msgs      K/var/www/urcfiles/bundle/venv/lib/python3.12/site-packages/PIL/ImageFile.py_get_oserrorr!   K   sv     jj''. %95WUGDVIi8DDC3<   jj s   A A'&A'c                8    t        ddd       t        | d      )Nraise_oserror   zIt is only useful for translating error codes returned by a codec's decode() method, which ImageFile already does automatically.)actionFr   )r   r!   )r   s    r    r#   r#   V   s%    
G ue
,,    _Tilec                    | d   S )N    )ts    r    	_tilesortr-   `   s    Q4Kr'   c                  >    e Zd ZU ded<   ded<   dZded<   dZd	ed
<   y)r(   str
codec_name tuple[int, int, int, int] | Noneextentsr   intoffsetNztuple[Any, ...] | str | Noneargs)__name__
__module____qualname____annotations__r4   r5   r+   r'   r    r(   r(   e   s!    O--FCO)-D
&-r'   c                       e Zd ZdZ	 d	 	 	 	 	 d fdZddZd Zd fdZddZddZ	d fdZ
d fd	Zdd
ZddZddZddZddZ xZS )	ImageFilez*Base class for image file format handlers.c                   t         |           d| _        d | _        g | _        	 d| _        d| _        t        | _        t        |      r3t        |d      | _        t        j                  |      | _        d| _        n.t!        t"        t$           |      | _        ||nd| _        d| _        	 	 | j'                          | j6                  r$| j8                  d   dk  s| j8                  d   dk  rd}t5        |      y # t(        t*        t,        t.        t0        j2                  f$ r}t5        |      |d }~ww xY w# t:        $ r( | j                  r| j                  j=                           w xY w)	Nr   r   r+   rbT Fznot identified by this driver)super__init__
_min_framecustom_mimetypetilereadonlydecoderconfigMAXBLOCKdecodermaxblockr   openfposfspathfilename_exclusive_fpr   r   bytes_open
IndexError	TypeErrorKeyErrorEOFErrorstructr   SyntaxErrormodesizeBaseExceptionclose)selfrI   rL   vr   	__class__s        r    r@   zImageFile.__init__t   sC    	+/!#	*.0'2;2tnDGIIbMDM!%D 2e9b)DG(0(<H"DM!&D		,

 99		! 1TYYq\Q5F5!#&& 6G  , "!n!+,  	!!		s*   -C; ==D7 ;(D4#D//D44D7 71E(c                     y Nr+   rZ   s    r    rO   zImageFile._open       r'   c                8   t        | dd      rft        | j                  t              sL| j                  | j                  k7  r| j                  j                          t        t        d            | _        | j                  r| j                  j                          y y )N_fpFzOperation on closed image)getattr
isinstancerb   r   rI   rY   
ValueErrorr_   s    r    	_close_fpzImageFile._close_fp   sd    4&z$((M/Rxx477" $Z0K%LMDH77GGMMO r'   c                    	 | j                          d| _        t
        |           y# t        $ r }t        j	                  d|       Y d}~3d}~ww xY w)a  
        Closes the file pointer, if possible.

        This operation will destroy the image core and release its memory.
        The image data will be unusable afterward.

        This function is required to close images that have multiple frames or
        have not had their file read and closed by the
        :py:meth:`~PIL.Image.Image.load` method. See :ref:`file-handling` for
        more information.
        NzError closing: %s)rf   rI   	Exceptionloggerdebugr?   rY   )rZ   r   r\   s     r    rY   zImageFile.close   sH    	3NNDG 	  	3LL,c22	3s   ) 	AAAc                   g }| j                         }g }t        j                  j                  |v r[|t        j                  j                     }|r<t	        |t
              s|f}|D ]$  }|j                  |j                  |      |f       & |j                  t        j                  j                        }|r^|j                  t        j                  j                        r5|j                  J |j                  ||j                  j                  f       d }|D ]w  \  }}	| j                  J | j                  j!                         }
||
}| j                  }||j                  t        j                  j                        }||t#        | dd      z  }| j                  j%                  |       |j                  t        j                  j&                        }t	        |t(              sJ | j                  j+                  |      }t-        j.                  |      }t1        j2                  |      5 }ddlm} /t	        ||j8                        r|	g|_        |j=                  d       |j?                          |j                  |       d d d        z |)| j                  J | j                  j%                  |       |S # 1 sw Y   xY w)N_exif_offsetr   r   )TiffImagePlugin) getexifr	   BaseSubIFDsrd   tupleappend_get_ifd_dictget_ifdIFDIFD1r   JpegIFOffset_infonextrI   tellrc   seekJpegIFByteCountr3   readioBytesIOr
   rH   r>   rm   TiffImageFile
_frame_pos_seekload)rZ   child_imagesexififdssubifd_offsetssubifd_offsetifd1r4   ifd
ifd_offsetcurrent_offsetrI   thumbnail_offsetlengthdataimrm   s                    r    get_child_imageszImageFile.get_child_images   s9   ||~==  D(!(--"7"78N!.%8&4%6N%3MKK!3!3M!BM RS &4||HLL--.DHHX]]778::)))KKtzz/0#OC77&&&!WW\\^N~'B#&778==+E+E#F #/$na(HH$GGLL!12 WWX]]%B%BCF%fc22277<</DD)BB2-#+
551 &0LBMHHQK	##B'  %  $: 77&&&GGLL   s   0AKK	c                    | j                   r| j                   S | j                  7t        j                  j	                  | j                  j                               S y r^   )rB   formatr
   MIMEr   upperr_   s    r    get_format_mimetypezImageFile.get_format_mimetype   sD    ''';;"::>>$++"3"3"566r'   c                <    t         |          | j                  gz   S r^   )r?   __getstate__rL   )rZ   r\   s    r    r   zImageFile.__getstate__   s    w#%77r'   c                F    g | _         |d   | _        t        |   |       y )N   )rC   rL   r?   __setstate__)rZ   stater\   s     r    r   zImageFile.__setstate__  s"    	aU#r'   c                ^    | j                   r| j                  j                          d| _        y)zCheck file integrityN)rM   rI   rY   r_   s    r    verifyzImageFile.verify  s!    
 GGMMOr'   c                
   | j                   s| j                  d}t        |      t        j                  j	                  |       }| j                   s|S d| _        | j                  xr t        | j                         dk(  }d}t        | d      r| j                  }d}n| j                  j                  }t        | d      r| j                  }d}n| j                  j                  }|rf| j                   d   \  }}}	}
t        |
t              r|
ddf}
|dk(  r7t        |
t               r&t        |
      d	k\  r|
d   | j"                  k(  r|
d   t        j$                  v r	 ddl}t)        | j                        5 }|j'                  |j+                         d|j,                  
      | _        ddd       |	| j.                  d   |
d   z  z   | j
                  j/                         kD  rd}t        |      t        j0                  j3                  | j
                  | j.                  ||	|
      | _        d}| j6                  rd| j6                  _        | j?                          d}| j
                  s| j                   jA                  tB               tE        | dd      }tG        jH                  | j                   d       D cg c]  \  }}tK        |      d    c}}| _         tM        | j                         D ]I  \  }\  }}}	}
 ||	       t        jN                  | j"                  ||
| jP                        }	 |jS                  | j4                  |       |jT                  r0|jW                  | j                         |jY                  d      d   }n|}	 | jZ                  }|dz   t        | j                         k  r&| j                   |dz      j\                  }||	kD  r||	z
  }	  ||      }|s!td        rn?dt        |       d}t        |      ||z   }|jY                  |      \  }}|dk  rn||d }|jg                          L g | _         || _4        | jk                          | jl                  r&| jn                  r| j                  jq                          d| _
        | j
                  std        s|dk  rts        |d      t        j                  j	                  |       S # 1 sw Y   2xY w# t:        t        t<        f$ r d| _        Y w xY wc c}}w # t^        t`        jb                  f$ r}td        rY d}~d}t        |      |d}~ww xY w# |jg                          w xY w)z"Load image data based on tile listNzcannot load this imager   r   	load_readF	load_seekraw   )accesszbuffer is not large enoughr   keytile_prefixr'   c                    | d   | d   | d   fS )Nr   r   r   r+   )rC   s    r    <lambda>z ImageFile.load.<locals>.<lambda>[  s    T!Wd1gtAw,Gr'   r   zimage file is truncatedzimage file is truncated (z bytes not processed)r&   ):rC   _imr   r
   r   maprL   lenhasattrr   rI   r}   r   r{   rd   r/   rq   rV   	_MAPMODESmmaprH   filenoACCESS_READrW   r   
map_bufferr   palettedirtyr   ImportErrorload_preparesortr-   rc   	itertoolsgroupbylist	enumerate_getdecoderrE   setimagepulls_fdsetfddecoderG   r4   rP   rT   r   LOAD_TRUNCATED_IMAGEScleanuprD   load_endrM   !_close_exclusive_fp_after_loadingrY   r!   )rZ   r   pixeluse_mmaprD   r}   r{   decoder_namer2   r4   r5   r   rI   err_codeprefix_tilesir   b
read_bytesnext_offsetsens                            r    r   zImageFile.load  s    yyTXX-*C#,  &yyL%)==8S^q%8 4%>>DH77<<D4%>>DH77<<D26))A,/L'64$$a|%tU+INGtyy(Gu.$dmm,#'99RYY[!DDTDT9#U -		!tAw 66H:%cl*#jj33$))\64DG  !H ||-.* 	xxIINNyN) T=#6F
 !* 1 1IIG!!HAu UB!DI =Fdii<P88L'64V++II|T43E3E(&$$TWWg6''dgg.#*>>##6q#9"")-)=)=J 1us499~5.2iiA.>.E.E#.#71<v1EJ>$($4 $%#8$)),,/F83H)J %( +2#,$6 !AA*1..*;KAx 1u % !!"A= #B OO%[ =Q^ 	 $"H"HGGMMOxx 5(Q,x77{{%%y -, '= $#DH$4 %/#= >#8$)*CC*1#,A$=>2 OO%so   S' 82S*B#S' =T	4B(U
T%AU
S$S' 'TTU(U.U
4UUU

Uc                    | j                   9t        j                  j                  | j                  | j
                        | _        | j                  dk(  r t        j                  j                  |        y y )NP)r   r
   r   newrV   rW   r   r   r_   s    r    r   zImageFile.load_prepare  sM    88jjnnTYY		:DG99KKT" r'   c                     y r^   r+   r_   s    r    r   zImageFile.load_end      r'   c                    || j                   k  s4t        | d      r| j                  )|t        | d      | j                   z   k\  rd}t	        |      | j                         |k7  S )N	_n_framesn_framesz attempt to seek outside sequence)rA   r   r   rc   rS   rz   )rZ   framer   s      r    _seek_checkzImageFile._seek_check  s]    DOO# T;/DNN4JWT:6HH 5C3-yy{e##r'   r^   )rI   zStrOrBytesPath | IO[bytes]rL   zstr | bytes | NonereturnNoner   r   )r   zlist[ImageFile])r   
str | None)r   	list[Any])r   r   r   r   r   zImage.core.PixelAccess | None)r   r3   r   bool)r6   r7   r8   __doc__r@   rO   rf   rY   r   r   r   r   r   r   r   r   r   __classcell__)r\   s   @r    r;   r;   q   sj    4 NR0,08J0	0d(1f8$
J&X#$r'   r;   c                  :    e Zd ZddZej
                  dd       Zy)StubHandlerc                     y r^   r+   rZ   r   s     r    rH   zStubHandler.open  r`   r'   c                     y r^   r+   r   s     r    r   zStubHandler.load  r   r'   N)r   StubImageFiler   r   )r   r   r   Image.Image)r6   r7   r8   rH   abcabstractmethodr   r+   r'   r    r   r     s!     	 r'   r   c                  d    e Zd ZdZej
                  dd       ZddZej
                  dd       Zy)	r   z
    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                     y r^   r+   r_   s    r    rO   zStubImageFile._open  r   r'   c                    | j                         }|d| j                   d}t        |      |j                  |       }|J |j                  | _        |j
                  | _        |j                         S )Nzcannot find loader for this z file)_loadr   r   r   r\   __dict__)rZ   loaderr   images       r    r   zStubImageFile.load  sj    >0UCC#,D!   zz|r'   c                     y)z (Hook) Find actual image loader.Nr+   r_   s    r    r   zStubImageFile._load  s     	r'   Nr   r   )r   zStubHandler | None)	r6   r7   r8   r   r   r   rO   r   r   r+   r'   r    r   r     s@     	 
 	 r'   r   )	metaclassc                  p    e Zd ZU dZdZdZded<   dZded<   dZded<   d	Z	d	Z
dd
ZddZddZddZddZy)Parserzj
    Incremental image parser.  This class implements the standard
    feed/close consumer interface.
    NzImage.Image | Noner   zbytes | Noner   z,Image.core.ImagingDecoder | PyDecoder | Noner   r   c                *    | j                   J d       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.
        Nzcannot reuse parsers)r   r_   s    r    resetzParser.reset  s     yy 8"88 r'   c                T   | j                   ry| j                  || _        n| j                  |z   | _        | j                  r| j                  dkD  rmt	        t        | j                        | j                        }| j                  |d | _        | j                  |z
  | _        | j                  dkD  s| j                  sy| j                  j                  | j                        \  }}|dk  r(d| _        d| _         |dk  rd| _        t        |d      y| j                  |d | _        y| j                  ry	 t        j                  | j                        5 }t        j                  |      }ddd       t        d      xs t        |d      }|st        |j                        dk7  rd| _        || _        y|j                          |j                  d   \  }}}	}
g |_        t        j                   |j"                  ||
|j$                        | _        | j                  j'                  |j(                  |       |	| _        | j                  t        | j                        k  r%| j                  | j                  d | _        d| _        || _        y# 1 sw Y   %xY w# t*        $ r Y yw xY w)z
        (Consumer) Feed data to the parser.

        :param data: A string buffer.
        :exception OSError: If the parser failed to parse the image file.
        Nr   r   Fr&   r   r   )finishedr   r   r4   minr   r   r   r!   r~   r   r
   rH   r   rC   r   r   rV   rE   r   r   r   )rZ   r   skipr   r   rI   r   flagdoas              r    feedzParser.feed  s!    ==99DI		D(DI <<{{Q3tyy>4;;7 IIde,	"kkD0;;?$))<<&&tyy1DAq1u 	 !q5!%DJ&q%88 		!"DIZZ  ZZ		*bBB +
 r;/K72{3K3rww<1,"&DK  
 OO%!#JAq!Q BG#(#4#4RWWaBDTDT#UDLLL))"%%3 #$DK{{c$))n4$(IIdkkm$<	&'
/ +* s*   6J J+J JJ 	J'&J'c                    | S r^   r+   r_   s    r    	__enter__zParser.__enter__H  s    r'   c                $    | j                          y r^   )rY   rZ   r5   s     r    __exit__zParser.__exit__K  s    

r'   c                ,   | j                   r8| j                  d       dx| _        | _         | j                  sd}t	        |      | j
                  sd}t	        |      | j                  rjt        j                  | j                        5 }	 t        j                  |      | _        | j
                  j                          	 ddd       | j
                  S | j
                  S # | j
                  j                          w xY w# 1 sw Y   | j
                  S xY w)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'   Nzimage was incompletezcannot parse this image)r   r  r   r   r   r   r~   r   r
   rH   r   )rZ   r   rI   s      r    rY   zParser.closeN  s     <<IIcN'++DI==,cl"zz+C#,99 DII&"&!&BDJJJOO%	 '
 zztzz JJOO%	 '
 zzs$   	C?C %C? C<<C??Dr   )r   rN   r   r   )r   r   )r5   objectr   r   )r   r   )r6   r7   r8   r   incrementalr   r9   r   r   r4   r   r   r  r  r	  rY   r+   r'   r    r   r     sS    
 K $E$D,<@G9@FH9J Xr'   r   c           	        | j                          t        | d      sd| _        |j                  t               t        t        || j                  d   dz        }	 |j                         }|j                          t        | ||||       t        |d      r|j                          yy# t        t        j                  f$ r}t        | |||d|       Y d}~Ld}~ww xY w)zHelper 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+   r   r      Nflush)r   r   r  r   r-   maxrF   rW   r   r  _encode_tiler   r~   UnsupportedOperation)r   rI   rC   bufsizefhexcs         r    _saver  p  s     GGI2'II)I
 (GRWWQZ!^4G7YY[

RT7B/ r7

  B334 7RT7D#667s   /B) )CCCc                <   |D ]  \  }}}}	|dkD  r|j                  |       t        j                  | j                  ||	| j                        }
	 |
j                  | j                  |       |
j                  r%|
j                  |       |
j                         d   }nE|r-	 |
j                  |      dd  \  }}|j                  |       |rn,|J |
j                  ||      }|dk  rt        |d      |	 |
j                           y # |
j                          w xY w)Nr   r   Tr&   )r{   r
   _getencoderrV   r  r   r   	pushes_fdr   encode_to_pyfdencodewriteencode_to_filer!   r   )r   rI   rC   r  r  r  encoder_namer2   r4   r5   r   errcoder   s                r    r  r    s    04+gvtA:GGFO##BGG\4AQAQR	RUUG,  b!!00215(/w(?(C"!	  >)>%44RAG{"7D9sB  OO1 040 OOs   B%D		Dc                   |dk  ry|t         k  r.| j                  |      }t        |      |k  rd}t        |      |S g }|}|dkD  rG| j                  t	        |t                     }|sn%|j                  |       |t        |      z  }|dkD  rGt        d |D              |k  rd}t        |      dj                  |      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

    r   r'   zTruncated File Readc              3  2   K   | ]  }t        |        y wr^   )r   ).0blocks     r    	<genexpr>z_safe_read.<locals>.<genexpr>  s     
*6%3u:6s   )	SAFEBLOCKr}   r   r   r   rr   sumjoin)rI   rW   r   r   blocksremaining_sizer$  s          r    
_safe_readr+    s     qyywwt}t9t'C#,FN
1
NI67e#e*$ 1
 
*6
**T1#cl88Fr'   c                      e Zd ZddZddZy)PyCodecStatec                <    d| _         d| _        d| _        d| _        y )Nr   )xsizeysizexoffyoffr_   s    r    r@   zPyCodecState.__init__  s    

		r'   c                    | j                   | j                  | j                   | j                  z   | j                  | j                  z   fS r^   )r1  r2  r/  r0  r_   s    r    r2   zPyCodecState.extents  s3    yy$))TYY%;TYY=SSSr'   Nr   )r   ztuple[int, int, int, int])r6   r7   r8   r@   r2   r+   r'   r    r-  r-    s    Tr'   r-  c                  N    e Zd ZU ded<   d	dZd
dZddZddZ	 d	 	 	 	 	 ddZy)PyCodeczIO[bytes] | Nonefdc                n    d | _         t               | _        d | _        || _        | j                  |       y r^   )r   r-  r   r6  rV   init)rZ   rV   r5   s      r    r@   zPyCodec.__init__  s+    15!^
			$r'   c                    || _         y)z
        Override to perform codec specific initialization

        :param args: Tuple of arg items from the tile entry
        :returns: None
        N)r5   r  s     r    r8  zPyCodec.init  s     	r'   c                     y)zT
        Override to perform codec specific cleanup

        :returns: None
        Nr+   r_   s    r    r   zPyCodec.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)r6  )rZ   r6  s     r    r   zPyCodec.setfd  s     r'   Nc                    || _         |r|\  }}}}nd\  }}}}|dk(  r=|dk(  r8| j                   j                  \  | j                  _        | j                  _        nJ|| j                  _        || j                  _        ||z
  | j                  _        ||z
  | j                  _        | j                  j                  dk  s| j                  j                  dk  rd}t        |      | j                  j                  | j                  j
                  z   | j                   j                  d   kD  sG| j                  j                  | j                  j                  z   | j                   j                  d   kD  r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
        )r   r   r   r   r   zSize cannot be negativer   z Tile cannot extend outside imageN)r   rW   r   r/  r0  r1  r2  re   )rZ   r   r2   x0y0x1y1r   s           r    r   zPyCodec.setimage  s,    &RR+RR7rQw15.DJJdjj. DJJO DJJO!BwDJJ!BwDJJ::q DJJ$4$4$9+CS/! JJtzz.a@zz$**//1DGGLLOC4CS/! Dr'   )rV   r/   r5   r   r   r   )r5   tuple[Any, ...]r   r   r   )r6  	IO[bytes]r   r   r^   )r   zImage.core.ImagingCorer2   r1   r   r   )	r6   r7   r8   r9   r@   r8  r   r   r   r+   r'   r    r5  r5    sB     59'""'" 2'" 
	'"r'   r5  c                  H    e Zd ZdZdZedd       ZddZ	 d		 	 	 	 	 	 	 d
dZy)	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                    | j                   S r^   )	_pulls_fdr_   s    r    r   zPyDecoder.pulls_fd5  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`.
        zunavailable in base decoderNotImplementedError)rZ   bufferr   s      r    r   zPyDecoder.decode9       ,!#&&r'   Nc                ^   |s| j                   }t        j                  | j                   d||      }| j                  J |j	                  | j                  | j
                  j                                |j                  |      }|d   dk\  rd}t        |      |d   dk7  rd}t        |      y)aS  
        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
        :param extra: Extra arguments for the decoder.
        :returns: None
        r   Nr   znot enough image datar   zcannot decode image data)	rV   r
   r   r   r   r   r2   r   re   )rZ   r   rawmodeextrar  r   r   s          r    
set_as_rawzPyDecoder.set_as_rawE  s     iiGdii?ww"""	

477DJJ..01HHTNQ419)CS/!Q419,CS/! r'   r   r   )rJ  z$bytes | Image.SupportsArrayInterfacer   tuple[int, int])Nr+   )r   rN   rM  r   rN  rA  r   r   )	r6   r7   r8   r   rF  propertyr   r   rO  r+   r'   r    rD  rD  +  sQ     I 
' QS""$.">M"	"r'   rD  c                  >    e Zd ZdZdZedd       Zd	dZd
dZdd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                    | j                   S r^   )
_pushes_fdr_   s    r    r  zPyEncoder.pushes_fdk  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`.
        zunavailable in base encoderrH  )rZ   r  r   s      r    r  zPyEncoder.encodeo  rK  r'   c                    | j                   sy| j                  d      \  }}}|r)| j                  J | j                  j                  |       ||fS )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`.
        )r   r   r   )r  r  r6  r  )rZ   bytes_consumedr   r   s       r    r  zPyEncoder.encode_to_pyfd{  sP     ~~(,A%77&&&GGMM$w&&r'   c                    d}|dk(  r9| j                  |      \  }}}|dkD  rt        j                  |||d        |dk(  r9|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`.
        r   N)r  rJ   r  )rZ   r  r  r   statusbufs         r    r  zPyEncoder.encode_to_file  sP     l#';;w#7 FGSzS\* l r'   NrP  )r  r3   r   ztuple[int, int, bytes])r   rQ  )r  r3   r  r3   r   r3   )
r6   r7   r8   r   rV  rR  r  r  r  r  r+   r'   r    rT  rT  a  s/     J 
'' r'   rT  )r   r3   r   r   r   r   )r   r3   r   r   )r,   r(   r   r3   )r   )
r   r   rI   rB  rC   list[_Tile]r  r3   r   r   r^   )r   r   rI   rB  rC   r]  r  r3   r  z
int | Noner  zBaseException | Noner   r   )rI   rB  rW   r3   r   rN   )0
__future__r   r   r~   r   loggingrJ   rT   typingr   r   r   r   r>   r	   r
   
_deprecater   _utilr   r   TYPE_CHECKING_typingr   	getLoggerr6   ri   rF   r&  r   r   r!   r#   r-   r(   r;   ABCr   ABCMetar   r   r  r  r+  r-  r5  rD  rT  r+   r'   r    <module>rh     s`  : # 
 	   	  , ,  ! )'			8	$	  N 	%
-
.J .L$ L$^
#'' I <C CRD !%      	 
 	  
  
 F FT TK" K"\3" 3"l8 8r'   