
    (pha                       S SK Jr  S SKrS SKrS SKrS SKrS SKrS SKJrJ	r	J
r
  SSKJr  SSKJr  SSKJr  SrS	rS
r SSSSSS.r S)S jrS*S jrS r " S S\
5      r " S S\R                  5      r " S S5      r " S S\5      r " S S5      rS+S,S jjrS-S.S jjrS  r " S! S"5      r  " S# S$5      r! " S% S&\!5      r" " S' S(\!5      r#g)/    )annotationsN)IOAny
NamedTuple   )Image)	deprecate)is_pathi   i   Fzimage buffer overrun errorzdecoding errorzunknown errorzbad configurationzout of memory error)ic                    [         R                  R                  U 5      nU(       d  U(       a  SOS SU  3nUSU(       a  SOS S3-  n[        U5      $ ! [         a    [        R                  U 5      n NUf = f)Nencoderdecoderz error z when writingreadingz image file)r   coregetcodecstatusAttributeErrorERRORSgetOSError)errorr   msgs      @/var/www/html/venv/lib/python3.13/site-packages/PIL/ImageFile.py_get_oserrorr   D   sv     jj''. %95WUGDVIi8DDC3<   jj s   A A76A7c                ,    [        SSSS9  [        U SS9e)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   O   s%    
G ue
,,    c                    U S   $ )N    )ts    r   	_tilesortr(   Y   s    Q4Kr#   c                  >    \ rS rSr% S\S'   S\S'   S\S'   S\S	'   S
rg)_Tile^   str
codec_nametuple[int, int, int, int]extentsintoffsetztuple[Any, ...] | str | Noneargsr&   N)__name__
__module____qualname____firstlineno____annotations____static_attributes__r&   r#   r   r*   r*   ^   s    O&&K
&&r#   r*   c                  p   ^  \ rS rSrSrSU 4S jjrSS jrU 4S jrSS jrS r	SS jr
SS	 jrS
 rSrU =r$ )	ImageFilej   z*Base class for image file format handlers.c                  > [         TU ]  5         SU l        S U l        S U l         SU l        SU l        [        U l        [        U5      (       a  [        US5      U l        Xl        SU l        OXl        X l        S U l          U R                  5         U R,                  (       a&  U R.                  S   S::  d  U R.                  S   S::  a  Sn[+        U5      eg ! [        [         ["        [$        [&        R(                  4 a  n[+        U5      UeS nAff = f! [0         a-    U R                  (       a  U R                  R3                  5         e f = f)Nr   r   r&   rbTznot 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)selfrH   rI   vr   	__class__s        r   r?   ImageFile.__init__m   s#   #	7'2;;2tnDGM!%D G$M!%D		,

 99		! 1TYYq\Q5F5!#&& 6G  , "!n!+,  	!!		s+   C AD )DDDD 7Ec                    U R                   (       a  U R                   $ U R                  b7  [        R                  R	                  U R                  R                  5       5      $ g N)rA   formatr   MIMEr   upperrV   s    r   get_format_mimetypeImageFile.get_format_mimetype   sD    ''';;"::>>$++"3"3"566r#   c                2   > / U l         [        TU ]	  U5        g r[   )rB   r>   __setstate__)rV   staterX   s     r   rc   ImageFile.__setstate__   s    	U#r#   c                h    U R                   (       a  U R                  R                  5         SU l        g)zCheck file integrityN)rJ   rH   rU   r_   s    r   verifyImageFile.verify   s!    
 GGMMOr#   c                
   U R                   c  Sn[        U5      e[        R                  R                  U 5      nU R                   (       d  U$ SU l        U R
                  =(       a    [        U R                   5      S:H  nU=(       a    [        [        S5      (       + nSn U R                  nSn U R                  nSnU(       Ga^  U R                   S   u  pxp[        U
[         5      (       a  U
SS4n
US:X  Ga+  [        U
5      S:  Ga  U
S   U R"                  :X  Ga  U
S   [        R$                  ;   a   SSKn[)        U R
                  5       nUR'                  UR+                  5       SUR,                  S	9U l        SSS5        XR.                  S   U
S   -  -   U R                  R/                  5       :  a  S
n[        U5      e[        R0                  R3                  U R                  U R.                  XyU
5      U l        SnU R6                  (       a  SU R6                  l        U R=                  5         SnU R                  (       Gd  U R                   R?                  [@        S9   U RB                  n[D        RF                  " U R                   S 5       VVs/ s H  u  nn[I        U5      S   PM     snnU l         U R                    GH  u  pxpU" U	5        [        RJ                  " U R"                  XzU RL                  5      n URO                  U R4                  U5        URP                  (       a0  URS                  U R                  5        URU                  S5      S   nOjUn  U" U RV                  5      nU(       d&  [^        (       a  OAS[        U5       S3n[        U5      eUU-   nURU                  U5      u  nnUS:  a  OUUS nMg  URa                  5         GM     / U l         X@l1        U Re                  5         U Rf                  (       a+  U Rh                  (       a  U R                  Rk                  5         SU l        U R                  (       d  [^        (       d  US:  a
  [m        USS9e[        R                  R                  U 5      $ ! [         a    U R                  R                  n GNf = f! [         a    U R                  R                  n GNf = f! , (       d  f       GNb= f! [        [        [:        4 a    SU l         GNf = f! [         a    Sn GNf = fs  snnf ! [X        [Z        R\                  4 a%  n[^        (       a   SnAGM  Sn[        U5      UeSnAff = f! URa                  5         f = f)z"Load image data based on tile listNzcannot load this imager   pypy_version_infor   Fraw   )accesszbuffer is not large enoughr   keyr#   c                    U S   U S   U S   4$ )Nr   r   rl   r&   )rB   s    r   <lambda> ImageFile.load.<locals>.<lambda>   s    T!Wd1gtAw,Gr#   r   zimage file is truncatedzimage file is truncated (z bytes not processed)r"   )7rB   r   r   loadmaprI   lenhasattrsys	load_readr   rH   read	load_seekseek
isinstancer,   rR   	_MAPMODESmmaprG   filenoACCESS_READrS   r   
map_bufferimpalettedirtyImportErrorload_preparesortr(   tile_prefix	itertoolsgroupbylist_getdecoderrD   setimagepulls_fdsetfddecoderF   rL   rP   r   LOAD_TRUNCATED_IMAGEScleanuprC   load_endrJ   !_close_exclusive_fp_after_loadingrU   r   )rV   r   pixeluse_mmaprC   ry   r{   decoder_namer/   r1   r2   r~   rH   err_codeprefix_tilesr   bsens                         r   rs   ImageFile.load   s    99*C#,  &yyL==8S^q%8EGC1D$E E	 >>DH	 >>DH 26))A,/L6$$$a|%INGtyy(Gu.$dmm,#'99RYY[!DDTDT9#U -		!tAw 66H:%cl*#jj33$))\4DG  !H ||-.* 	xxxIINNyN))) !* 1 1IIG!!HAu UB!DI 8<yy3vV++II|43E3E#&$$TWWg6''dgg.#*>>##6q#9"">$()=)=$> $%#8#8$)),,/F83H)J %( +2#,$6 !AA*1..*;KAx 1u % !!"A3 #8 OO%Q 8AT 	 $"H"HGGMMOxx 5 5(Q,x77{{%%e  	 77<<D	   	 77<<D	 $ -, '= $#DH$ " * %/#= >#8#8$)*CC*1#,A$=>2 OO%s    R	 /R0 4S) /S<B'S) %T TA U'#T%5AU'	 R-,R-0 SS
S&!S) )T	T	TT%U$?U
U'UU$$U''U9c                   U R                   (       aH  U R                   R                  U R                  :w  d$  U R                   R                  U R                  :w  a9  [        R                  R                  U R                  U R                  5      U l         U R                  S:X  a   [        R                  R                  U 5        g g )NP)r   rR   rS   r   r   newrs   r_   s    r   r   ImageFile.load_prepare<  sp    ww$'',,$))3tww||tyy7PjjnnTYY		:DG99KKT" r#   c                    g r[   r&   r_   s    r   r   ImageFile.load_endD      r#   c                    XR                   :  d:  [        U S5      (       a  U R                  b)  XR                  U R                   -   :  a  Sn[	        U5      eU R                  5       U:g  $ )N	_n_framesz attempt to seek outside sequence)r@   rv   r   n_framesrO   tell)rV   framer   s      r   _seek_checkImageFile._seek_checkP  sY    OO# T;//DNN4J]]T__<< 5C3-yy{e##r#   )rJ   r@   rA   rD   rF   rI   rH   r   rt   rC   rB   )NN)returnz
str | Noner   None)r3   r4   r5   r6   __doc__r?   r`   rc   rg   rs   r   r   r   r8   __classcell__)rX   s   @r   r:   r:   j   s6    4.`$I&V#$ $r#   r:   c                  F    \ rS rSrSS jr\R                  SS j5       rSrg)StubHandleri`  c                    g r[   r&   rV   r   s     r   rG   StubHandler.opena  s    r#   c                    g r[   r&   r   s     r   rs   StubHandler.loadd  r   r#   r&   N)r   StubImageFiler   r   )r   r   r   zImage.Image)	r3   r4   r5   r6   rG   abcabstractmethodrs   r8   r&   r#   r   r   r   `  s!     	 r#   r   c                  2    \ rS rSrSrSS jrS rS	S jrSrg)
r   ii  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                    Sn[        U5      e)Nz+StubImageFile subclass must implement _openNotImplementedErrorrV   r   s     r   rK   StubImageFile._openq  s    ;!#&&r#   c                    U R                  5       nUc  SU R                   S3n[        U5      eUR                  U 5      nUc   eUR                  U l        UR
                  U l        UR                  5       $ )Nzcannot find loader for this z file)_loadr\   r   rs   rX   __dict__)rV   loaderr   images       r   rs   StubImageFile.loadu  sj    >0UCC#,D!   zz|r#   c                    Sn[        U5      e)z (Hook) Find actual image loader.z+StubImageFile subclass must implement _loadr   r   s     r   r   StubImageFile._load  s    ;!#&&r#   )rX   r   Nr   )r   zStubHandler | None)	r3   r4   r5   r6   r   rK   rs   r   r8   r&   r#   r   r   r   i  s    '
'r#   r   c                  b    \ rS rSr% SrSrSrS\S'   SrSr	Sr
SrSS jrS rS	 rSS
 jrS rSrg)Parseri  z^
Incremental image parser.  This class implements the standard
feed/close consumer interface.
NzImage.Image | Noner   r   c                ,    U R                   b   S5       eg)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)datar_   s    r   resetParser.reset  s     yy 8"88 r#   c                   U R                   (       a  gU R                  c  Xl        OU R                  U-   U l        U R                  (       a  U R                  S:  as  [	        [        U R                  5      U R                  5      nU R                  US U l        U R                  U-
  U l        U R                  S:  d  U R                  (       d  gU R                  R                  U R                  5      u  p4US:  a&  SU l        SU l         US:  a  SU l        [        USS9egU R                  US U l        gU R                  (       a  g [        R                  " U R                  5       n[        R                  " U5      nSSS5        [        WS5      =(       d    [        US5      nU(       d  [        UR                  5      S:w  a  SU l        OUR                  5         UR                  S   u  pp/ Ul        [        R                   " UR"                  XUR$                  5      U l        U R                  R'                  UR(                  U5        Xl        U R                  [        U R                  5      ::  a%  U R                  U R                  S U l        SU l        X`l        g! , (       d  f       GN+= f! [*         a     gf = f)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"   rz   rx   )finishedr   r   r1   minru   r   r   r   ioBytesIOr   rG   rv   rB   r   r   rR   rD   r   r   r   )rV   r   skipr   r   rH   r   flagdoas              r   feedParser.feed  s
    ==99I		D(DI <<{{Q3tyy>4;;7 IIde,	"kkD0;;?$))<<&&tyy1DA1u 	 !q5!%DJ&q%88 		!"DIZZ  ZZ		*bBB +
 r;/K72{3K3rww<1,"&DK OO%!#JA! BG#(#4#4RWWaBDTDT#UDLLL))"%%3 #$K{{c$))n4$(IIdkkm$<	&'
/ +* s*   
 J7 *J%J7 %
J4/J7 7
KKc                    U $ r[   r&   r_   s    r   	__enter__Parser.__enter__  s    r#   c                $    U R                  5         g r[   )rU   rV   r2   s     r   __exit__Parser.__exit__  s    

r#   c                b   U R                   (       a=  U R                  S5        S=U l        U l         U R                  (       d  Sn[	        U5      eU R
                  (       d  Sn[	        U5      eU R                  (       al  [        R                  " U R                  5       n [        R                  " U5      U l        U R
                  R                  5          SSS5        U R
                  $ U R
                  $ ! U R
                  R                  5         f = f! , (       d  f       U R
                  $ = f)z
(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   rG   rs   )rV   r   rH   s      r   rU   Parser.close  s     <<IIcN'++DI==,cl"zz+C#,99 DII&"&!&BDJJJOO%	 '
 zztzz JJOO%	 '&
 zzs$   D C6;D6DD
D.)r   r   r   r   r   r1   r   )r2   objectr   r   )r3   r4   r5   r6   r   incrementalr   r7   r   r   r1   r   r   r   r   r   rU   r8   r&   r#   r   r   r     sH    
 K $E$DGFH9J Xr#   r   c           	        U R                  5         [        U S5      (       d  SU l        UR                  [        S9  [        [        X0R                  S   S-  5      n UR                  5       nUR                  5         [        XX#U5        [        US5      (       a  UR                  5         gg! [        [        R                  4 a  n[        XX#SU5         SnANPSnAff = f)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&   rn   r      Nflush)rs   rv   r   r   r(   maxrE   rS   r   r   _encode_tiler   r   UnsupportedOperation)r   rH   rB   bufsizefhexcs         r   _saver     s     GGI2''II)I
 (GWWQZ!^4G7YY[

RTB/ r7

  B334 7RTD#667s   -B- -CCCc                N   U GH	  u  pgpUS:  a  UR                  U5        [        R                  " U R                  XiU R                  5      n
 U
R                  U R                  U5        U
R                  (       a%  U
R                  U5        U
R                  5       S   nOJU(       a2   U
R                  U5      SS  u  pUR                  U5        U(       a  OM1  U
R                  XC5      nUS:  a  [        USS9Ue U
R                  5         GM     g ! U
R                  5         f = f)Nr   r   Tr"   )r{   r   _getencoderrR   r   r   r   	pushes_fdr   encode_to_pyfdencodewriteencode_to_filer   r   )r   rH   rB   r   r   r   encoder_namer/   r1   r2   r   errcoder   s                r   r   r   ,  s    /3+vA:GGFO##BGG\AQAQR	RUUG,  b!!00215(/w(?(C"!	  &44RAG{"7D9sB  OO/ 04. OOs   B-DD$c                   US::  a  gU[         ::  a/  U R                  U5      n[        U5      U:  a  Sn[        U5      eU$ / nUnUS:  aN  U R                  [	        U[         5      5      nU(       d  O'UR                  U5        U[        U5      -  nUS:  a  MN  [        S U 5       5      U:  a  Sn[        U5      eSR                  U5      $ )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  8   #    U  H  n[        U5      v   M     g 7fr[   )ru   ).0r   s     r   	<genexpr>_safe_read.<locals>.<genexpr>d  s     
 4a3q664s   )	SAFEBLOCKry   ru   r   r   appendsumjoin)rH   rS   r   r   remaining_sizeblocks         r   
_safe_readr  G  s     qyywwt}t9t'C#,DN
1
NI67E#e*$ 1
 
 4
  4'#cl88D>r#   c                  (    \ rS rSrSS jrSS jrSrg)PyCodecStateij  c                <    SU l         SU l        SU l        SU l        g )Nr   )xsizeysizexoffyoffr_   s    r   r?   PyCodecState.__init__k  s    

		r#   c                    U R                   U R                  U R                   U R                  -   U R                  U R                  -   4$ r[   )r  r  r  r  r_   s    r   r/   PyCodecState.extentsq  s3    yy$))TYY%;TYY=SSSr#   )r  r  r  r  Nr   )r   r.   )r3   r4   r5   r6   r?   r/   r8   r&   r#   r   r
  r
  j  s    Tr#   r
  c                  J    \ rS rSr% S\S'   S rS rSS jrS rSSS	 jjr	S
r
g)PyCodeciu  zIO[bytes] | Nonefdc                l    S U l         [        5       U l        S U l        Xl        U R                  U5        g r[   )r   r
  rd   r  rR   init)rV   rR   r2   s      r   r?   PyCodec.__init__x  s)    !^
			$r#   c                    Xl         g)zx
Override to perform codec specific initialization

:param args: Array of args items from the tile entry
:returns: None
N)r2   r   s     r   r  PyCodec.init  s	     	r#   c                    g)z<
Override to perform codec specific cleanup

:returns: None
Nr&   r_   s    r   r   PyCodec.cleanup  s     	r#   c                    Xl         g)zo
Called from ImageFile to set the Python file-like object

:param fd: A Python file-like object
:returns: None
N)r  )rV   r  s     r   r   PyCodec.setfd  s	     r#   Nc                   Xl         U(       a  Uu  p4pVOSu  p4pVUS:X  a>  US:X  a8  U R                   R                  u  U R                  l        U R                  l        OFX0R                  l        X@R                  l        XS-
  U R                  l        Xd-
  U R                  l        U R                  R                  S::  d  U R                  R                  S::  a  Sn[        U5      eU R                  R                  U R                  R
                  -   U R                   R                  S   :  dH  U R                  R                  U R                  R                  -   U R                   R                  S   :  a  Sn[        U5      eg)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   rS   rd   r  r  r  r  
ValueError)rV   r   r/   x0y0x1y1r   s           r   r   PyCodec.setimage  s    &RR+RR7rQw15.DJJdjj. JJO JJO!wDJJ!wDJJ::q DJJ$4$4$9+CS/! JJtzz.a@zz$**//1DGGLLOC4CS/! Dr#   )r2   r  r   rR   rd   r   r[   )r/   z tuple[int, int, int, int] | Noner   r   )r3   r4   r5   r6   r7   r?   r  r   r   r   r8   r&   r#   r   r  r  u  s&    #" #"r#   r  c                  H    \ rS rSrSrSr\S	S j5       rS
S jrSSS jjr	Sr
g)	PyDecoderi  z
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                    U R                   $ r[   )	_pulls_fdr_   s    r   r   PyDecoder.pulls_fd  s    ~~r#   c                    Sn[        U5      e)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 decoderr   )rV   bufferr   s      r   r   PyDecoder.decode       ,!#&&r#   Nc                n   U(       d  U R                   n[        R                  " U R                   SU5      nU R                  c   eUR	                  U R                  U R
                  R                  5       5        UR                  U5      nUS   S:  a  Sn[        U5      eUS   S:w  a  Sn[        U5      eg)z
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
rk   Nr   znot enough image datar   zcannot decode image data)	rR   r   r   r   r   rd   r/   r   r   )rV   r   rawmoder   r   r   s         r   
set_as_rawPyDecoder.set_as_raw  s     iiGdii8ww"""	

477DJJ..01HHTNQ419)CS/!Q419,CS/! r#   r&   r   bool)r,  bytesr   tuple[int, int]r[   )r   r5  r   r   )r3   r4   r5   r6   r   r)  propertyr   r   r1  r8   r&   r#   r   r'  r'    s/     I 
'" "r#   r'  c                  J    \ rS rSrSrSr\S
S j5       rSS jrSS jr	S r
Srg	)	PyEncoderi  z
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                    U R                   $ r[   )
_pushes_fdr_   s    r   r   PyEncoder.pushes_fd  s    r#   c                    Sn[        U5      e)z
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 encoderr   )rV   r   r   s      r   r   PyEncoder.encode   r.  r#   c                    U R                   (       d  gU R                  S5      u  pnU(       a*  U R                  c   eU R                  R                  U5        X4$ )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   r  r   )rV   bytes_consumedr   r   s       r   r   PyEncoder.encode_to_pyfd  sL     ~~(,A%77&&&GGMM$&&r#   c                    SnUS:X  a5  U R                  U5      u  pCnUS:  a  UR                  XTS 5        US:X  a  M5  U$ )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   r   )rV   r   r   r   statusbufs         r   r   PyEncoder.encode_to_file  sJ     l#';;w#7 FSzW& l r#   r&   Nr3  )r   r0   r   ztuple[int, int, bytes])r   r6  )r3   r4   r5   r6   r   r;  r7  r   r   r   r   r8   r&   r#   r   r9  r9    s/     J 
'' r#   r9  )r   r0   r   r4  r   r   )r   r0   r   r   )r   r   r[   )rB   zlist[_Tile])$
__future__r   r   r   r   rP   rw   typingr   r   r    r   
_deprecater	   _utilr
   rE   r  r   r   r   r   r(   r*   r:   r   r   r   r   r   r  r
  r  r'  r9  r&   r#   r   <module>rK     s   : # 
 	   
 & &  ! 	  N 	%
-
'J 's$ s$l 'I '<C CR86 FT TG" G"T0" 0"f8 8r#   