ó
k4Vdc           @   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[   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/PIL/ImageFile.pyt   raise_ioerror4   s    c         C   s   |  d S(   Ni   (    (   t   t(    (    s[   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/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[   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/PIL/ImageFile.pyR   N   s(    						c         C   s   d S(   s   Set draft modeN(    (   R"   R    R!   (    (    s[   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/PIL/ImageFile.pyt   draftl   s    c         C   s   d |  _ d S(   s   Check file integrityN(   R   R   (   R"   (    (    s[   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/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| rW|  j d \ } } } }	 | d k rW|	 d |  j k rW|	 d t  j k rW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 } WqTt t t  f k
 rPd	 |  _ qTXqWn  |  j!   |  j s1|  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) rG| j* |  j  | j+ d  \ } } nŁ | } xŠ t, ry | |  j-  } Wn0 t. t/ j0 f k
 rt1 rPqt d   n X| rć| j2 rćg  |  _ | j3   t1 rŹPqćt d t |    n  | | } | j+ |  \ } } | d k  rPn  | | } qPW| j3   q®Wn  g  |  _ | |  _4 d	 |  _ |  j rvt1 rv| d k  rvt5 |  n  t |  d  rÆ|  j j6 |  j7  |  _ |  j j |  _ n  |  j8   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(9   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   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[   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/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[   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/PIL/ImageFile.pyRC   ü   s
    
*!c         C   s   d  S(   N(    (   R"   (    (    s[   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/PIL/ImageFile.pyRQ     s    N(
   t   __name__t
   __module__t   __doc__R   R   R$   R%   R.   RC   RQ   (    (    (    s[   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/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[   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/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[   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/PIL/ImageFile.pyR.     s    c         C   s   t  d   d S(   s    (Hook) Find actual image loader.s+   StubImageFile subclass must implement _loadN(   Ri   (   R"   (    (    s[   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/PIL/ImageFile.pyRj   )  s    (   Re   Rf   Rg   R   R.   Rj   (    (    (    s[   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/PIL/ImageFile.pyRh     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(   s   
    Incremental image parser.  This class implements the standard
    feed/close consumer interface.

    In Python 2.x, this is an old-style class.
    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   Rl   (   R"   (    (    s[   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/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   finishedRr   R   R]   R[   t   minR/   RK   Rp   R
   t   iot   BytesIOR    R   t   closeR   R0   R   RC   RF   R    R   RG   R9   (   R"   Rr   t   skipRb   RU   R   R9   t   flagRT   RV   RW   (    (    s[   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/PIL/ImageFile.pyt   feedF  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   Rr   Rt   R   Rp   Rv   Rw   R    R   R.   Rx   (   R"   R   (    (    s[   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/PIL/ImageFile.pyRx     s    
				N(   Re   Rf   Rg   R   t   incrementalRp   Rr   R]   R[   Rt   Rs   R{   Rx   (    (    (    s[   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/PIL/ImageFile.pyRq   0  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}   RD   R   t   maxR   R!   R1   t   stdoutR~   R>   R   Rv   t   UnsupportedOperationR    t   _getencoderR    R6   RG   R9   t	   pushes_fdRJ   t   encode_to_pyfdRL   t   encodet   writeR   RO   t   encode_to_file(   R9   R   R   t   bufsizet   fhRU   R`   RV   RW   t   lRa   RT   (    (    s[   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/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   Ru   t   appendR/   t   join(   R   R!   Rr   t   block(    (    s[   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/PIL/ImageFile.pyt
   _safe_readł  s    
i   (   t   PILR    t	   PIL._utilR   Rv   R;   R1   R   R   R   R3   RM   R   R
   R   R   Rh   t   objectRq   R   R   (    (    (    s[   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/PIL/ImageFile.pyt   <module>   s*   
			Ē>