ó
O'^c           @   sū   d  d l  m Z d  d l m Z d  d l Z d  d l Z d  d l Z d  d l Z d Z d Z	 e
 Z i d d  6d d 6d	 d
 6d d 6d d 6Z d   Z d   Z d e j f d     YZ d e f d     YZ d e f d     YZ d d  Z d   Z d S(   i’’’’(   t   Image(   t   isPathNi   i   s   image buffer overrun errors   decoding erroriž’’’s   unknown erroriż’’’s   bad configurationių’’’s   out of memory errori÷’’’c         C   s`   y t  j j |   } Wn  t k
 r8 t j |   } n X| sL d |  } n  t | d   d  S(   Ns   decoder error %ds    when reading image file(   R    t   coret   getcodecstatust   AttributeErrort   ERRORSt   gett   IOError(   t   errort   message(    (    s/   /tmp/pip-unpacked-wheel-ivxKtu/PIL/ImageFile.pyt   raise_ioerror4   s    c         C   s   |  d S(   Ni   (    (   t   t(    (    s/   /tmp/pip-unpacked-wheel-ivxKtu/PIL/ImageFile.pyt	   _tilesortB   s    t	   ImageFilec           B   sJ   e  Z d  Z d d d  Z d   Z d   Z d   Z d   Z d   Z	 RS(   s*   Base class for image file format handlers.c      	   C   sā   t  j  j |   d  |  _ d |  _ d |  _ t |  _ t |  r^ t	 | d  |  _
 | |  _ n | |  _
 | |  _ y |  j   Wn1 t t t t t j f k
 r± } t |   n X|  j sĻ |  j d d k rŽ t d   n  d  S(   Ni   t   rbi    s   not identified by this driver(    (   R    t   __init__t   Nonet   tilet   readonlyt   decoderconfigt   MAXBLOCKt   decodermaxblockR   t   opent   fpt   filenamet   _opent
   IndexErrort	   TypeErrort   KeyErrort   EOFErrort   structR   t   SyntaxErrort   modet   size(   t   selfR   R   t   v(    (    s/   /tmp/pip-unpacked-wheel-ivxKtu/PIL/ImageFile.pyR   N   s(    						c         C   s   d S(   s   Set draft modeN(    (   R"   R    R!   (    (    s/   /tmp/pip-unpacked-wheel-ivxKtu/PIL/ImageFile.pyt   draftl   s    c         C   s   d |  _ d S(   s   Check file integrityN(   R   R   (   R"   (    (    s/   /tmp/pip-unpacked-wheel-ivxKtu/PIL/ImageFile.pyt   verifyq   s    c         C   sį  t  j  j |   } |  j d	 k r0 t d   n  |  j s= | Sd	 |  _ |  j oa t |  j  d k } | ow t t	 d  } d } y |  j
 } t } Wn t k
 r² |  j j } n Xy |  j } t } Wn t k
 rå |  j j } n X| ro|  j d \ } } } }	 | d k ro|	 d |  j k ro|	 d t  j k royt t  j d  r£t  j j |  j  |  _ |  j j |  |  j j |  j |  j |	 d |	 d  |  _ n d d	 l }
 t |  j d
  } t j j |  j  } |
 j | j   | d |
 j |  _ t  j j |  j |  j | | | |	  |  _ d } |  j rBd |  j _  n  Wqlt t! t" f k
 rhd	 |  _ qlXqon  |  j#   |  j sI|  j j$ d t%  y |  j& } Wn t k
 r»d } n Xx|  j D]|\ } } } } t  j' |  j | | |  j(  } | |  y | j) |  j |  Wn t* k
 r-qĘn X| j+ r_| j, |  j  | j- d  \ } } nŁ | } xŠ t. r7y | |  j/  } Wn0 t0 t1 j2 f k
 r³t3 r¤Pq“t d   n X| rū| j4 rūg  |  _ | j5   t3 rāPqūt d t |    n  | | } | j- |  \ } } | d k  r*Pn  | | } qhW| j5   qĘWn  g  |  _ | |  _6 d	 |  _ |  j rt3 r| d k  rt7 |  n  t |  d  rĒ|  j j8 |  j9  |  _ |  j j |  _ n  |  j:   t  j  j |   S(   s"   Load image data based on tile lists   cannot load this imagei   t   pypy_version_infoi    t   rawt   mapi   i’’’’Nt   rt   accesst   keyt    s   image file is truncateds0   image file is truncated (%d bytes not processed)t   tile_post_rotate(;   R    t   loadR   R   R   R(   R   t   lent   hasattrt   syst	   load_readt   FalseR   R   t   readt	   load_seekt   seekR    t	   _MAPMODESR   t	   readimageR!   t   imt   mmapR   t   ost   patht   getsizet   filenot   ACCESS_READt
   map_buffert   palettet   dirtyt   EnvironmentErrort   ImportErrort   load_preparet   sortR   t   tile_prefixt   _getdecoderR   t   setimaget
   ValueErrort   pulls_fdt   setfdt   decodet   TrueR   R   R   R   t   LOAD_TRUNCATED_IMAGESt   handles_eoft   cleanupR   R
   t   rotateR-   t   load_end(   R"   t   pixelt   use_mmapR   R4   R6   t   dt   et   ot   aR:   R   R!   t   prefixt   decoder_namet   extentst   offsett   argst   decodert   statust   err_codet   bt   st   n(    (    s/   /tmp/pip-unpacked-wheel-ivxKtu/PIL/ImageFile.pyR.   x   s°    			
	
2	&$	!	
	

			

			
c         C   s{   |  j  s4 |  j  j |  j k s4 |  j  j |  j k rU t j j |  j |  j  |  _  n  |  j d k rw t j j |   n  d  S(   Nt   P(   R9   R    R!   R    R   t   newR.   (   R"   (    (    s/   /tmp/pip-unpacked-wheel-ivxKtu/PIL/ImageFile.pyRE   ’   s
    
*!c         C   s   d  S(   N(    (   R"   (    (    s/   /tmp/pip-unpacked-wheel-ivxKtu/PIL/ImageFile.pyRS     s    N(
   t   __name__t
   __module__t   __doc__R   R   R$   R%   R.   RE   RS   (    (    (    s/   /tmp/pip-unpacked-wheel-ivxKtu/PIL/ImageFile.pyR   K   s   					t   StubImageFilec           B   s)   e  Z d  Z d   Z d   Z d   Z RS(   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.
    c         C   s   t  d   d  S(   Ns+   StubImageFile subclass must implement _open(   t   NotImplementedError(   R"   (    (    s/   /tmp/pip-unpacked-wheel-ivxKtu/PIL/ImageFile.pyR     s    c         C   sk   |  j    } | d  k r. t d |  j   n  | j |   } | d  k	 sO t  | j |  _ | j |  _ d  S(   Ns#   cannot find loader for this %s file(   t   _loadR   R   t   formatR.   t   AssertionErrort	   __class__t   __dict__(   R"   t   loadert   image(    (    s/   /tmp/pip-unpacked-wheel-ivxKtu/PIL/ImageFile.pyR.   "  s    c         C   s   t  d   d S(   s    (Hook) Find actual image loader.s+   StubImageFile subclass must implement _loadN(   Rk   (   R"   (    (    s/   /tmp/pip-unpacked-wheel-ivxKtu/PIL/ImageFile.pyRl   ,  s    (   Rg   Rh   Ri   R   R.   Rl   (    (    (    s/   /tmp/pip-unpacked-wheel-ivxKtu/PIL/ImageFile.pyRj     s   		
t   Parserc           B   sM   e  Z d  Z d Z d Z d Z d Z d Z d Z	 d   Z
 d   Z d   Z RS(   sj   
    Incremental image parser.  This class implements the standard
    feed/close consumer interface.
    i    c         C   s   |  j  d k s t d   d S(   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.
        s   cannot reuse parsersN(   t   dataR   Rn   (   R"   (    (    s/   /tmp/pip-unpacked-wheel-ivxKtu/PIL/ImageFile.pyt   reset?  s    c         C   sl  |  j  r d S|  j d k r( | |  _ n |  j | |  _ |  j r |  j d k r« t t |  j  |  j  } |  j | |  _ |  j | |  _ |  j d k s¤ |  j r« d Sn  |  j j |  j  \ } } | d k  rd |  _ d |  _  | d k  rd |  _ t	 |  qd Sn  |  j | |  _ nH|  j r,n<y7 z% t
 j |  j  } t j |  } Wd | j   XWn t k
 rvnņ Xt | d  pt | d  } | s°t | j  d k r¼d |  _ n£ | j   | j d \ } } }	 }
 g  | _ t j | j | |
 | j  |  _ |  j j | j |  |	 |  _ |  j t |  j  k r_|  j |  j |  _ d |  _ n  | |  _ d S(   s¦   
        (Consumer) Feed data to the parser.

        :param data: A string buffer.
        :exception IOError: If the parser failed to parse the image file.
        Ni    i   R5   R2   (   t   finishedRt   R   R_   R]   t   minR/   RM   Rr   R
   t   iot   BytesIOR    R   t   closeR   R0   R   RE   RH   R    R   RI   R9   (   R"   Rt   t   skipRd   RW   R   R9   t   flagRV   RX   RY   (    (    s/   /tmp/pip-unpacked-wheel-ivxKtu/PIL/ImageFile.pyt   feedG  sX    							
		c         C   sÆ   |  j  rA |  j d  d |  _ |  _  |  j sA t d   qA n  |  j sY t d   n  |  j rØ z( t j |  j  } t	 j
 |  |  _ Wd |  j j   | j   Xn  |  j S(   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.
        R,   s   image was incompletes   cannot parse this imageN(   R_   R}   R   Rt   Rv   R   Rr   Rx   Ry   R    R   R.   Rz   (   R"   R   (    (    s/   /tmp/pip-unpacked-wheel-ivxKtu/PIL/ImageFile.pyRz     s    
				N(   Rg   Rh   Ri   R   t   incrementalRr   Rt   R_   R]   Rv   Ru   R}   Rz   (    (    (    s/   /tmp/pip-unpacked-wheel-ivxKtu/PIL/ImageFile.pyRs   3  s   		Ui    c         C   s  |  j    t |  d  s% d |  _ n  | j d t  t t | |  j d d  } | t j	 k ro | j
   d Sy | j   } | j
   Wnt t j f k
 r¢xŃ| D]ņ \ } } } } t j |  j | | |  j  } | d k rų | j | d  n  | j |  j |  | j r6| j |  | j   \ }	 }
 n< x9 t rq| j |  \ }	 }
 } | j |  |
 r9Pq9q9W|
 d k  rt d |
   n  | j   q© WnŌ XxŠ | D]Č \ } } } } t j |  j | | |  j  } | d k rł| j | d  n  | j |  j |  | j r7| j |  | j   \ }	 }
 n | j | |  }
 |
 d k  rht d |
   n  | j   qŖWt | d  r| j
   n  d S(	   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   encoderconfigR+   i    i   Ns(   encoder error %d when writing image filet   flush(    (   R.   R0   R   RF   R   t   maxR   R!   R1   t   stdoutR   R>   R   Rx   t   UnsupportedOperationR    t   _getencoderR    R6   RI   R9   t	   pushes_fdRL   t   encode_to_pyfdRN   t   encodet   writeR   RQ   t   encode_to_file(   R9   R   R   t   bufsizet   fhRW   Rb   RX   RY   t   lRc   RV   (    (    s/   /tmp/pip-unpacked-wheel-ivxKtu/PIL/ImageFile.pyt   _save¼  sT    	

			c         C   s   | d k r d S| t  k r) |  j |  Sg  } xO | d k r |  j t | t    } | s` Pn  | j |  | t |  8} q2 Wd j |  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 <b>read</b> method.
    :param size: Number of bytes to read.
    :returns: A string containing up to <i>size</i> bytes of data.
    i    R,   (   t	   SAFEBLOCKR4   Rw   t   appendR/   t   join(   R   R!   Rt   t   block(    (    s/   /tmp/pip-unpacked-wheel-ivxKtu/PIL/ImageFile.pyt
   _safe_readś  s    
i   (   t   PILR    t	   PIL._utilR   Rx   R;   R1   R   R   R   R3   RO   R   R
   R   R   Rj   t   objectRs   R   R   (    (    (    s/   /tmp/pip-unpacked-wheel-ivxKtu/PIL/ImageFile.pyt   <module>   s*   
			Ź>