zmc
2023-08-08 e792e9a60d958b93aef96050644f369feb25d61b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
U
T±dø^ã@sðddlZddlZddlZddlZddlmZddlmZdZdZ    dZ
dd    d
d d 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÷ÿÿÿcCsRztj |¡}Wntk
r.t |¡}YnX|s>d|›}|d7}t|ƒ‚dS)Nzdecoder error z when reading image file)rÚcoreZgetcodecstatusÚAttributeErrorÚERRORSÚgetÚOSError)ÚerrorÚmsg©rúDd:\z\workplace\vscode\pyvenv\venv\Lib\site-packages\PIL/ImageFile.pyÚ raise_oserror@s
rcCs|dS)Nér)ÚtrrrÚ    _tilesortKsrcs^eZdZdZd‡fdd„    Zdd„Z‡fdd„Zd    d
„Zd d „Zd d„Z    dd„Z
dd„Z ‡Z S)Ú    ImageFilez*Base class for image file format handlers.Nc stƒ ¡d|_d|_d|_d|_d|_t|_t    |ƒrPt
|dƒ|_ ||_ d|_ n||_ ||_ d|_ zxz | ¡Wn8tttttjfk
r¨}zt|ƒ|‚W5d}~XYnX|jrÌ|jddksÌ|jddkrØd}t|ƒ‚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#Úvr©Ú    __class__rrrXs@
  û" 
zImageFile.__init__cCs,|jr |jS|jdk    r(tj |j ¡¡SdS©N)rÚformatrZMIMEr Úupper©r0rrrÚget_format_mimetypeˆs
zImageFile.get_format_mimetypecsg|_tƒ |¡dSr4)rrÚ __setstate__)r0Ústater2rrr9ŽszImageFile.__setstate__cCs|jr|j ¡d|_dS)zCheck file integrityN)r$r"r/r7rrrÚverify’s
zImageFile.verifyc Cs¬|jdkrd}t|ƒ‚tj |¡}|js,|Sd|_|joDt|jƒdk}|oTttdƒ }d}z|j    }d}Wnt
k
r„|j j }YnXz|j }d}Wnt
k
r°|j j}YnX|r´|jd\}}}    }
|dkr´t|
ƒdkr´|
d|jkr´|
dtjkr´zŽddl} t|jƒ} | j|  ¡d| jd    |_W5QRX|    |jd|
d|j ¡kr`t‚tj |j|j||    |
¡|_d}|jrŽd|j_Wn"t
ttfk
r²d|_YnX| ¡d
} |jsL|jjtd z
|j}Wnt
k
rúd }YnXd d„t  !|jdd„¡Dƒ|_|jD](\}}}    }
||    ƒt "|j||
|j#¡}zò| %|j|¡|j&r~| '|j ¡| (d ¡d} n¼|}z||j)ƒ}WnJt*t+j,fk
rÚ}z$t-r¼WY¢q:nd}t|ƒ|‚W5d}~XYnX|st-rîq:ndt|ƒ›d}t|ƒ‚||}| (|¡\}} |dkr*q:||d…}q‚W5| $¡Xq g|_||_.| /¡|j0rz|j1rz|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Ú_ZtilesrrrÚ
<listcomp>åsÿz"ImageFile.load.<locals>.<listcomp>cSs|d|d|dfS)Nrrr>r)rrrrÚ<lambda>èrBz ImageFile.load.<locals>.<lambda>zimage file is truncatedzimage file is truncated (z bytes not processed))4rr rÚloadÚmapr#ÚlenÚhasattrÚsysÚ    load_readr
r"ÚreadÚ    load_seekÚseekr,Z    _MAPMODESÚmmapr!ÚfilenoZ ACCESS_READr-r    Z
map_bufferÚimZpaletteZdirtyÚ ImportErrorÚ load_prepareÚsortrZ tile_prefixÚ    itertoolsÚgroupbyÚ _getdecoderrÚcleanupÚsetimageÚpulls_fdÚsetfdÚdecoder r&r*rÚLOAD_TRUNCATED_IMAGESrÚload_endr$Z!_close_exclusive_fp_after_loadingr/r)r0rZpixelZuse_mmaprrNrPZ decoder_nameÚextentsÚoffsetÚargsrQr"Zerr_codeÚprefixÚdecoderÚbÚsÚeÚnrrrrH›sÐ
 ÿ
þ ý ü ""ÿ  
 
ÿþÿ  ÿ
 
zImageFile.loadcCsP|jr"|jj|jks"|jj|jkr6tj |j|j¡|_|jdkrLtj |¡dS)NÚP)rSr,r-rr    ÚnewrHr7rrrrU$s"
zImageFile.load_preparecCsdSr4rr7rrrr`,szImageFile.load_endcCsF||jks.t|dƒr|jdks:||j|jkr:d}t|ƒ‚| ¡|kS)NÚ    _n_framesz attempt to seek outside sequence)rrKrlZn_framesr)Útell)r0ÚframerrrrÚ _seek_check8sÿûûú    zImageFile._seek_check)NN) Ú__name__Ú
__module__Ú __qualname__Ú__doc__rr8r9r;rHrUr`roÚ __classcell__rrr2rrUs0     
 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.
    cCsd}t|ƒ‚dS)Nz+StubImageFile subclass must implement _open©ÚNotImplementedError©r0rrrrr%PszStubImageFile._opencCsT| ¡}|dkr&d|j›d}t|ƒ‚| |¡}|dk    s<t‚|j|_|j|_| ¡S)Nzcannot find loader for this z file)Ú_loadr5r rHÚAssertionErrorr3Ú__dict__)r0ÚloaderrÚimagerrrrHTs
 zStubImageFile.loadcCsd}t|ƒ‚dS)z (Hook) Find actual image loader.z+StubImageFile subclass must implement _loadNrvrxrrrry`szStubImageFile._loadN)rprqrrrsr%rHryrrrrruHs ruc@sPeZdZdZdZdZdZdZdZdZ    dd„Z
dd„Z dd    „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)Údatarzr7rrrÚresetssz 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 OSError: If the parser failed to parse the image file.
        NrrrOrM)ÚfinishedrrerbÚminrJr^r}rÚioÚBytesIOrr!r rKrrUrYr,rr[rS) r0rÚskiprirhr"rSÚflagÚdÚoÚarrrÚfeed{sR    
 
 
z Parser.feedcCs|Sr4rr7rrrÚ    __enter__ÈszParser.__enter__cGs | ¡dSr4)r/©r0rcrrrÚ__exit__ËszParser.__exit__c    Cs‚|jr.| d¡d|_|_|js.d}t|ƒ‚|js@d}t|ƒ‚|jr|t |j¡$}zt     
|¡|_W5|j ¡XW5QRX|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.
        rBNzimage was incompletezcannot parse this image) rerŠrrr r}rƒr„rHrr!)r0rr"rrrr/Îs
 
 z Parser.close)rprqrrrsÚ incrementalr}rrerbrr€rŠr‹rr/rrrrr~fsMr~c
Cs°| ¡t|dƒsd|_|jtdtt||jddƒ}z$| ¡}|     ¡t
|||||ƒWn:t t j fk
r˜}zt
||||d|ƒW5d}~XYnXt|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éNÚflush)rHrKrrVrÚmaxrr-rRr‘Ú _encode_tiler
rƒÚUnsupportedOperation)rSr"rÚbufsizeÚfhÚexcrrrÚ_saveðs    
 $
r˜c    CsÐ|D]Æ\}}}}    |dkr"| |¡t |j||    |j¡}
zˆ|
 |j|¡|
jrd|
     |¡|
 
¡d} n:|r’|
  |¡dd…\} } |  | ¡| rhqžqhn |
  ||¡} | dkr¼d| ›d} t| ƒ|‚W5|
 ¡XqdS)Nrrzencoder error z when writing image file)rPrZ _getencoderr,rrZr[rSÚ    pushes_fdr]Úencode_to_pyfdÚencodeÚwriteÚencode_to_filer )rSr"rr•r–r—rhrfrˆr‰ÚencoderÚerrcoderrrrrr“ s&
 
 
  r“cCs¤|dkr dS|tkr:| |¡}t|ƒ|kr6d}t|ƒ‚|Sg}|}|dkrx| t|tƒ¡}|s`qx| |¡|t|ƒ8}qBtdd„|Dƒƒ|kršd}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
 
    rrBzTruncated File Readcss|]}t|ƒVqdSr4)rJ)rDr‡rrrÚ    <genexpr>Esz_safe_read.<locals>.<genexpr>)Ú    SAFEBLOCKrNrJr r‚ÚappendÚsumÚjoin)r"r-rrZremaining_sizeÚblockrrrÚ
_safe_read(s( 
 
r¦c@seZdZdd„Zdd„ZdS)Ú PyCodecStatecCsd|_d|_d|_d|_dS)Nr)ÚxsizeÚysizeÚxoffÚyoffr7rrrrLszPyCodecState.__init__cCs |j|j|j|j|j|jfSr4)rªr«r¨r©r7rrrraRszPyCodecState.extentsN)rprqrrrrarrrrr§Ksr§c@s6eZdZdd„Zdd„Zdd„Zdd„Zd d
d „Zd    S) ÚPyCodeccGs(d|_tƒ|_d|_||_| |¡dSr4)rSr§r:Úfdr,Úinit)r0r,rcrrrrWs
zPyCodec.__init__cCs
||_dS)z˜
        Override to perform codec specific initialization
 
        :param args: Array of args items from the tile entry
        :returns: None
        N)rcrŒrrrr®^sz PyCodec.initcCsdS)zT
        Override to perform codec specific cleanup
 
        :returns: None
        Nrr7rrrrZgszPyCodec.cleanupcCs
||_dS)z
        Called from ImageFile to set the Python file-like object
 
        :param fd: A Python file-like object
        :returns: None
        N)r­)r0r­rrrr]osz PyCodec.setfdNcCsÞ||_|r|\}}}}n d\}}}}|dkrJ|dkrJ|jj\|j_|j_n(||j_||j_|||j_|||j_|jjdksŠ|jjdkr–d}t|ƒ‚|jj|jj|jjdksÎ|jj|jj|jjdkrÚd}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)rSr-r:r¨r©rªr«Ú
ValueError)r0rSraZx0Zy0Úx1Úy1rrrrr[xs&    ÿþzPyCodec.setimage)N)rprqrrrr®rZr]r[rrrrr¬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>`
    FcCs|jSr4)Ú    _pulls_fdr7rrrr\¨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 -1 for the bytes consumed.
            Err codes are from :data:`.ImageFile.ERRORS`.
        Nrv)r0Úbufferrrrr^¬s    zPyDecoder.decodeNcCsl|s
|j}t |jd|¡}| |j|j ¡¡| |¡}|ddkrPd}t|ƒ‚|ddkrhd}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,rrYr[rSr:rar^r¯)r0rÚrawmoder‡rgrrrrÚ
set_as_raw·s
 
  zPyDecoder.set_as_raw)N)    rprqrrrsr³Úpropertyr\r^r¶rrrrr²žs 
 r²c@s8eZdZdZdZedd„ƒZdd„Zdd„Zd    d
„Z    d S) Ú    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>`
    FcCs|jSr4)Ú
_pushes_fdr7rrrr™ÙszPyEncoder.pushes_fdcCs
tƒ‚dS)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`.
        Nrv)r0r•rrrr›Ýs    zPyEncoder.encodecCs2|js
dS| 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œ)r0Zbytes_consumedrŸrrrrršès  zPyEncoder.encode_to_pyfdcCs<d}|dkr8| |¡\}}}|dkr| ||d…¡q|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œ)r0r–r•rŸÚstatusÚbufrrrr÷s     zPyEncoder.encode_to_fileN)
rprqrrrsr¹r·r™r›ršrrrrrr¸Ïs
 r¸)r)N)rƒrWr*rLÚrZ_utilrrr¡r_r rrrrur~r˜r“r¦r§r¬r²r¸rrrrÚ<module>s8  û 
t
 
# H1