ó <×ï[c@sddlmZddlmZddlZddlZddlZdZdZe Z idd6dd 6d d 6d d 6dd6Z d„Z d„Z dejfd„ƒYZdefd„ƒYZdefd„ƒYZdd„Zd„Zdefd„ƒYZdefd„ƒYZdS( i(tImage(tisPathiÿÿÿÿNiisimage buffer overrun errorsdecoding erroriþÿÿÿs unknown erroriýÿÿÿsbad configurationiøÿÿÿsout of memory errori÷ÿÿÿcCs`ytjj|ƒ}Wn tk r8tj|ƒ}nX|sLd|}nt|dƒ‚dS(Nsdecoder error %ds when reading image file(RtcoretgetcodecstatustAttributeErrortERRORStgettIOError(terrortmessage((s-/tmp/pip-build-SKekGm/pillow/PIL/ImageFile.pyt raise_ioerror3s  cCs|dS(Ni((tt((s-/tmp/pip-build-SKekGm/pillow/PIL/ImageFile.pyt _tilesortAst ImageFilecBs\eZdZd d d„Zd„Zd„Zd„Zd„Zd„Z d„Z d„Z RS( s*Base class for image file format handlers.c Cstjj|ƒd|_d|_d|_d|_t|_t |ƒrpt |dƒ|_ ||_ t |_n||_ ||_ d|_y|jƒWnJtttttjfk rå}|jrÖ|j jƒnt|ƒ‚nX|j s|jddkrtdƒ‚ndS(Niitrbsnot identified by this driver((Rt__init__t _min_frametNonettiletreadonlyt decoderconfigtMAXBLOCKtdecodermaxblockRtopentfptfilenametTruet _exclusive_fpt_opent IndexErrort TypeErrortKeyErrortEOFErrortstructRtcloset SyntaxErrortmodetsize(tselfRRtv((s-/tmp/pip-build-SKekGm/pillow/PIL/ImageFile.pyRMs2            cCsdS(sSet draft modeN((R&R$R%((s-/tmp/pip-build-SKekGm/pillow/PIL/ImageFile.pytdraftsscCs,|jdkrdStjj|jjƒƒS(N(tformatRRtMIMERtupper(R&((s-/tmp/pip-build-SKekGm/pillow/PIL/ImageFile.pytget_format_mimetypexscCs&|jr|jjƒnd|_dS(sCheck file integrityN(RRR"R(R&((s-/tmp/pip-build-SKekGm/pillow/PIL/ImageFile.pytverify}s c Cs®tjj|ƒ}|jd kr0tdƒ‚n|js=|Sd |_|joat|jƒdk}|owtt dƒ }d}y|j }t }Wnt k r²|j j}nXy|j}t }Wnt k rå|j j}nX|ru|jd\}}}} |dkrut| ƒdkru| d|jkru| dtjkruyttjdƒrµtjj|jƒ|_|jj|ƒ|jj|j|j| d| dƒ|_nud d l} t|jd ƒ+} | j| jƒdd | jƒ|_Wd QXtjj|j|j|||| ƒ|_d}|jrHd|j_nWqrt ttfk rnd |_qrXqun|j ƒd } |js-|jj!dt"ƒy |j#} Wnt k rÇd} nXxb|jD]T\}}}} tj$|j|| |j%ƒ}z||ƒ|j&|j|ƒ|j'rS|j(|j ƒ|j)dƒ\}} nÄ| }x»t*ry||j+ƒ}Wn0t,t-j.fk r§t/r˜Pq¨tdƒ‚nX|sÚt/r¸PqÚg|_tdt|ƒƒ‚n||}|j)|ƒ\}} |dkr Pn||}q\WWd |j0ƒXqÒWng|_||_1|j2ƒ|j3rk|j4rk|j j5ƒnd |_ |j ržt/ rž| dkržt6| ƒntjj|ƒS(s"Load image data based on tile listscannot load this imageitpypy_version_infoitrawitmapiiÿÿÿÿNtrtaccessiýÿÿÿtkeytsimage file is truncateds0image file is truncated (%d bytes not processed)(7RtloadRRRR0Rtlenthasattrtsyst load_readtFalseRRtreadt load_seektseekR$t _MAPMODESRt readimageR%timtmmapRtfilenot ACCESS_READt map_buffertpalettetdirtytEnvironmentErrort ImportErrort load_preparetsortR t tile_prefixt _getdecoderRtsetimagetpulls_fdtsetfdtdecodeRRRR!RtLOAD_TRUNCATED_IMAGEStcleanupRtload_endRt!_close_exclusive_fp_after_loadingR"R (R&tpixeltuse_mmapRR;R=t decoder_nametextentstoffsettargsRARterr_codetprefixtdecodertstatustbtstn((s-/tmp/pip-build-SKekGm/pillow/PIL/ImageFile.pyR5†s°         &                   cCs{|j s4|jj|jks4|jj|jkrUtjj|j|jƒ|_n|jdkrwtjj|ƒndS(NtP(R@R$R%RRtnewR5(R&((s-/tmp/pip-build-SKekGm/pillow/PIL/ImageFile.pyRIs  *!cCsdS(N((R&((s-/tmp/pip-build-SKekGm/pillow/PIL/ImageFile.pyRSscCsc||jksDt|dƒo*|jdk rS||j|jkrStdƒ‚n|jƒ|kS(Nt _n_framess attempt to seek outside sequence(RR7RdRtn_framesR ttell(R&tframe((s-/tmp/pip-build-SKekGm/pillow/PIL/ImageFile.pyt _seek_checks N( t__name__t __module__t__doc__RRR(R,R-R5RIRSRh(((s-/tmp/pip-build-SKekGm/pillow/PIL/ImageFile.pyR Js&   € t StubImageFilecBs)eZdZd„Zd„Zd„ZRS(s± 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. cCstdƒ‚dS(Ns+StubImageFile subclass must implement _open(tNotImplementedError(R&((s-/tmp/pip-build-SKekGm/pillow/PIL/ImageFile.pyR.scCsk|jƒ}|dkr.td|jƒ‚n|j|ƒ}|dk sOt‚|j|_|j|_dS(Ns#cannot find loader for this %s file(t_loadRRR)R5tAssertionErrort __class__t__dict__(R&tloadertimage((s-/tmp/pip-build-SKekGm/pillow/PIL/ImageFile.pyR53s   cCstdƒ‚dS(s (Hook) Find actual image loader.s+StubImageFile subclass must implement _loadN(Rm(R&((s-/tmp/pip-build-SKekGm/pillow/PIL/ImageFile.pyRn=s(RiRjRkRR5Rn(((s-/tmp/pip-build-SKekGm/pillow/PIL/ImageFile.pyRl&s  tParsercBs_eZdZdZdZdZdZdZdZ d„Z d„Z d„Z d„Z d„ZRS(sj Incremental image parser. This class implements the standard feed/close consumer interface. icCs|jdkstdƒ‚dS(sµ (Consumer) Reset the parser. Note that you can only call this method immediately after you've created a parser; parser instances cannot be reused. scannot reuse parsersN(tdataRRo(R&((s-/tmp/pip-build-SKekGm/pillow/PIL/ImageFile.pytresetPsc Csc|jr dS|jdkr(||_n|j||_|jr |jdkr«tt|jƒ|jƒ}|j||_|j||_|jdks¤|j r«dSn|jj|jƒ\}}|dkr d|_d|_|dkrd|_t |ƒq dSn|j||_n?|jr,n3y.t j |jƒ}t j |ƒ}WdQXWntk rmnòXt|dƒp‰t|dƒ}|s§t|jƒdkr³d|_n£|jƒ|jd\}}} } g|_t j|j|| |jƒ|_|jj|j|ƒ| |_|jt|jƒkrV|j|j|_d|_n||_dS(s¦ (Consumer) Feed data to the parser. :param data: A string buffer. :exception IOError: If the parser failed to parse the image file. NiiR<R9(tfinishedRuRR]RYtminR6RPRsR tiotBytesIORRRR7RRIRLR$RRMR@( R&RutskipRateRR@tflagtdtota((s-/tmp/pip-build-SKekGm/pillow/PIL/ImageFile.pytfeedXsT                cCs|S(N((R&((s-/tmp/pip-build-SKekGm/pillow/PIL/ImageFile.pyt __enter__ªscGs|jƒdS(N(R"(R&RZ((s-/tmp/pip-build-SKekGm/pillow/PIL/ImageFile.pyt__exit__­scCs®|jrA|jdƒd|_|_|jsAtdƒ‚qAn|jsYtdƒ‚n|jr§tj|jƒ.}zt j |ƒ|_Wd|jj ƒXWdQXn|jS(s (Consumer) Close the stream. :returns: An image object. :exception IOError: If the parser failed to parse the image file either because it cannot be identified or cannot be decoded. R4simage was incompletescannot parse this imageN( R]RRRuRwRRsRyRzRRR5(R&R((s-/tmp/pip-build-SKekGm/pillow/PIL/ImageFile.pyR"°s     N(RiRjRkRt incrementalRsRuR]RYRwRvRR‚RƒR"(((s-/tmp/pip-build-SKekGm/pillow/PIL/ImageFile.pyRtDs  R  ic Cs–|jƒt|dƒs%d|_n|jdtƒtt||jddƒ}|tj kro|j ƒdSy|j ƒ}|j ƒWnt t jfk r¢xÑ|D]ò\}}}}tj|j|||jƒ}|dkrø|j|dƒn|j|j|ƒ|jr6|j|ƒ|jƒ\} } n<x9trq|j|ƒ\} } } |j| ƒ| r9Pq9q9W| dkr‘td| ƒ‚n|jƒq©WnÔXxÐ|D]È\}}}}tj|j|||jƒ}|dkrù|j|dƒn|j|j|ƒ|jr7|j|ƒ|jƒ\} } n|j||ƒ} | dkrhtd| ƒ‚n|jƒqªWt|dƒr’|j ƒndS( s«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 t encoderconfigR3iiNs(encoder error %d when writing image filetflush((R5R7R…RJR tmaxRR%R8tstdoutR†RBRRytUnsupportedOperationRt _getencoderR$R=RMR@t pushes_fdROtencode_to_pyfdRtencodetwriteRRRtencode_to_file( R@RRtbufsizetfhR|R_RR€tlR`R~((s-/tmp/pip-build-SKekGm/pillow/PIL/ImageFile.pyt_saveÏsT              cCsŽ|dkrdS|tkr)|j|ƒSg}xO|dkr€|jt|tƒƒ}|s`Pn|j|ƒ|t|ƒ8}q2Wdj|ƒS(so 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 read method. :param size: Number of bytes to read. :returns: A string containing up to size bytes of data. iR4(t SAFEBLOCKR;RxtappendR6tjoin(RR%Rutblock((s-/tmp/pip-build-SKekGm/pillow/PIL/ImageFile.pyt _safe_read s    t PyCodecStatecBseZd„Zd„ZRS(cCs(d|_d|_d|_d|_dS(Ni(txsizetysizetxofftyoff(R&((s-/tmp/pip-build-SKekGm/pillow/PIL/ImageFile.pyR&s   cCs*|j|j|j|j|j|jfS(N(RœRRšR›(R&((s-/tmp/pip-build-SKekGm/pillow/PIL/ImageFile.pyRX,s (RiRjRRX(((s-/tmp/pip-build-SKekGm/pillow/PIL/ImageFile.pyR™%s t PyDecodercBsheZdZeZd„Zd„Zed„ƒZd„Z d„Z d„Z d d„Z d d„ZRS( sÉ Python implementation of a format decoder. Override this class and add the decoding logic in the `decode` method. See :ref:`Writing Your Own File Decoder in Python` cGs8d|_tƒ|_d|_||_|j|ƒdS(N(RR@R™tstatetfdR$tinit(R&R$RZ((s-/tmp/pip-build-SKekGm/pillow/PIL/ImageFile.pyR;s     cCs ||_dS(sš Override to perform decoder specific initialization :param args: Array of args items from the tile entry :returns: None N(RZ(R&RZ((s-/tmp/pip-build-SKekGm/pillow/PIL/ImageFile.pyR¡BscCs|jS(N(t _pulls_fd(R&((s-/tmp/pip-build-SKekGm/pillow/PIL/ImageFile.pyRNKscCs tƒ‚dS(s Override to perform the decoding process. :param buffer: A bytes object with the data to be decoded. If `handles_eof` is set, then `buffer` will be empty and `self.fd` will be set. :returns: A tuple of (bytes consumed, errcode). If finished with decoding return <0 for the bytes consumed. Err codes are from `ERRORS` N(Rm(R&tbuffer((s-/tmp/pip-build-SKekGm/pillow/PIL/ImageFile.pyRPOs cCsdS(sV Override to perform decoder specific cleanup :returns: None N((R&((s-/tmp/pip-build-SKekGm/pillow/PIL/ImageFile.pyRR\scCs ||_dS(s Called from ImageFile to set the python file-like object :param fd: A python file-like object :returns: None N(R (R&R ((s-/tmp/pip-build-SKekGm/pillow/PIL/ImageFile.pyROdscCs9||_|r$|\}}}}nd\}}}}|dkro|dkro|jj\|j_|j_n8||j_||j_|||j_|||j_|jjdksË|jjdkrÚtdƒ‚n|jj|jj|jjdks&|jj|jj|jjdkr5tdƒ‚ndS(sú Called from ImageFile to set the core output image for the decoder :param im: A core image object :param extents: a 4 tuple of (x0, y0, x1, y1) defining the rectangle for this tile :returns: None isSize cannot be negativeis Tile cannot extend outside imageN(iiii(R@R%RŸRšR›RœRt ValueError(R&R@RXtx0ty0tx1ty1((s-/tmp/pip-build-SKekGm/pillow/PIL/ImageFile.pyRMms !  $&&cCs—|s|j}ntj|jd|ƒ}|j|j|jjƒƒ|j|ƒ}|ddkrttdƒ‚n|ddkr“tdƒ‚ndS(s 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/isnot enough image dataiscannot decode image dataN( R$RRLRMR@RŸRXRPR¤(R&RutrawmodeR~R`((s-/tmp/pip-build-SKekGm/pillow/PIL/ImageFile.pyt set_as_rawŽs  N(RiRjRkR:R¢RR¡tpropertyRNRPRRRORRMRª(((s-/tmp/pip-build-SKekGm/pillow/PIL/ImageFile.pyRž1s    !i(R4Rt_utilRRyR8R!RR”R:RQRR R R RltobjectRtR“R˜R™Rž(((s-/tmp/pip-build-SKekGm/pillow/PIL/ImageFile.pyts,      Ü‹ >