
4ec           @   s  d  d l  Z  d  d l Z d  d l Z d  d l Z d d l m Z m Z m Z d d l m	 Z	 m
 Z m Z m Z m Z d d l m Z d Z e  j e  Z e j d  j Z d Z i d	 d	 f d d
 f 6d d f d d
 f 6d d f d d
 f 6d d f d d
 f 6d d f d d
 f 6d d f d d f 6d d f d d f 6d d f d d f 6d d f d d f 6d d f d d f 6d d f d d f 6d d f d d f 6d d f d d f 6d d f d d f 6d d f d d f 6Z e j d   Z e j Z d! e Z  d"   Z! d
 d#  Z" d$ e# f d%     YZ$ d& e% f d'     YZ& d( e# f d)     YZ' d* e$ f d+     YZ( d,   Z) d- e j f d.     YZ* i d	 d/ f d	 6d0 d/ f d0 6d d1 f d 6d d2 f d 6d d3 f d 6d d4 f d 6d d5 f d 6d d5 f d6 6d d7 f d 6d d8 f d 6d d9 f d 6d d: f d 6d d; f d 6d d< f d 6Z+ d=   Z, d> e# f d?     YZ- e, d@  Z. dA   Z/ e j0 e* j1 e* e)  e j2 e* j1 e.  e j3 e* j1 dB dC g  e j4 e* j1 dD  d S(E   iNi   (   t   Imaget	   ImageFilet   ImagePalette(   t   i8t   i16bet   i32bet   o16bet   o32be(   t   py3s   0.9s   \w\w\w\ws   PNG

t   1i    t   Ls   L;2i   s   L;4i   i   t   Is   I;16Bi   t   RGBs   RGB;16Bt   Ps   P;1i   s   P;2s   P;4t   LAt   RGBAs   LA;16Bi   s   RGBA;16Bs   ^* *$i@   c         C   s:   t  j   } | j |  t  } | j r6 t d   n  | S(   Ns   Decompressed Data Too Large(   t   zlibt   decompressobjt
   decompresst   MAX_TEXT_CHUNKt   unconsumed_tailt
   ValueError(   t   st   dobjt	   plaintext(    (    s<   /usr/local/lib/python2.7/dist-packages/PIL/PngImagePlugin.pyt   _safe_zlib_decompressY   s
    	c         C   s   t  j |  |  d @S(   NI    (   R   t   crc32(   t   datat   seed(    (    s<   /usr/local/lib/python2.7/dist-packages/PIL/PngImagePlugin.pyt   _crc32a   s    t   ChunkStreamc           B   se   e  Z d    Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z	 d   Z
 d	 d
  Z RS(   c         C   s   | |  _  g  |  _ d  S(   N(   t   fpt   queue(   t   selfR   (    (    s<   /usr/local/lib/python2.7/dist-packages/PIL/PngImagePlugin.pyt   __init__j   s    	c         C   s   d } |  j r: |  j j   \ } } } |  j j |  n7 |  j j d  } | d } |  j j   } t |  } t |  s t	 j
 s t d t |    q n  | | | f S(   s.   Fetch a new chunk. Returns header information.i   i   s   broken PNG file (chunk %s)N(   t   NoneR    t   popR   t   seekt   readt   tellt   i32t   is_cidR   t   LOAD_TRUNCATED_IMAGESt   SyntaxErrort   repr(   R!   t   cidt   post   lengthR   (    (    s<   /usr/local/lib/python2.7/dist-packages/PIL/PngImagePlugin.pyR&   o   s    	
	c         C   s   |  S(   N(    (   R!   (    (    s<   /usr/local/lib/python2.7/dist-packages/PIL/PngImagePlugin.pyt	   __enter__   s    c         G   s   |  j    d  S(   N(   t   close(   R!   t   args(    (    s<   /usr/local/lib/python2.7/dist-packages/PIL/PngImagePlugin.pyt   __exit__   s    c         C   s   d  |  _ |  _ |  _ d  S(   N(   R#   R    t   crcR   (   R!   (    (    s<   /usr/local/lib/python2.7/dist-packages/PIL/PngImagePlugin.pyR1      s    c         C   s   |  j  j | | | f  d  S(   N(   R    t   append(   R!   R-   R.   R/   (    (    s<   /usr/local/lib/python2.7/dist-packages/PIL/PngImagePlugin.pyt   push   s    c         C   s9   t  j d | | |  t |  d | j d   | |  S(   s"   Call the appropriate chunk handlers   STREAM %r %s %st   chunk_t   ascii(   t   loggert   debugt   getattrt   decode(   R!   R-   R.   R/   (    (    s<   /usr/local/lib/python2.7/dist-packages/PIL/PngImagePlugin.pyt   call   s    c         C   s   t  j r5 t | d  d ?d @r5 |  j | |  d SyP t | t |   } t |  j j d   } | | k r t d |   n  Wn$ t	 j
 k
 r t d |   n Xd S(   s   Read and verify checksumi    i   i   Ni   s+   broken PNG file (bad header checksum in %r)s+   broken PNG file (incomplete checksum in %r)(   R   R*   R   t   crc_skipR   R(   R   R&   R+   t   structt   error(   R!   R-   R   t   crc1t   crc2(    (    s<   /usr/local/lib/python2.7/dist-packages/PIL/PngImagePlugin.pyR4      s    !c         C   s   |  j  j d  d S(   s3   Read checksum.  Used if the C module is not presenti   N(   R   R&   (   R!   R-   R   (    (    s<   /usr/local/lib/python2.7/dist-packages/PIL/PngImagePlugin.pyR>      s    t   IENDc         C   s   g  } x t  r y |  j   \ } } } Wn  t j k
 rJ t d   n X| | k r[ Pn  |  j | t j |  j |   | j	 |  q	 W| S(   Ns   truncated PNG file(
   t   TrueR&   R?   R@   t   IOErrorR4   R   t
   _safe_readR   R5   (   R!   t   endchunkt   cidsR-   R.   R/   (    (    s<   /usr/local/lib/python2.7/dist-packages/PIL/PngImagePlugin.pyt   verify   s    	(   t   __name__t
   __module__R"   R&   R0   R3   R1   R6   R=   R4   R>   RI   (    (    (    s<   /usr/local/lib/python2.7/dist-packages/PIL/PngImagePlugin.pyR   i   s   									t   iTXtc           B   s#   e  Z d  Z e d d d   Z RS(   sq   
    Subclass of string to allow iTXt chunks to look like strings while
    keeping their extra information

    c         C   s(   t  j |  |  } | | _ | | _ | S(   s   
        :param cls: the class to use when creating the instance
        :param text: value for this key
        :param lang: language code
        :param tkey: UTF-8 version of the key name
        (   t   strt   __new__t   langt   tkey(   t   clst   textRO   RP   R!   (    (    s<   /usr/local/lib/python2.7/dist-packages/PIL/PngImagePlugin.pyRN      s    			N(   RJ   RK   t   __doc__t   staticmethodR#   RN   (    (    (    s<   /usr/local/lib/python2.7/dist-packages/PIL/PngImagePlugin.pyRL      s   t   PngInfoc           B   s>   e  Z d  Z d   Z d   Z d d e d  Z e d  Z RS(   s<   
    PNG chunk container (for use with save(pnginfo=))

    c         C   s   g  |  _  d  S(   N(   t   chunks(   R!   (    (    s<   /usr/local/lib/python2.7/dist-packages/PIL/PngImagePlugin.pyR"      s    c         C   s   |  j  j | | f  d S(   s   Appends an arbitrary chunk. Use with caution.

        :param cid: a byte string, 4 bytes long.
        :param data: a byte string of the encoded data

        N(   RV   R5   (   R!   R-   R   (    (    s<   /usr/local/lib/python2.7/dist-packages/PIL/PngImagePlugin.pyt   add   s    t    c         C   s   t  | t  s$ | j d d  } n  t  | t  sH | j d d  } n  t  | t  sl | j d d  } n  t  | t  s | j d d  } n  | r |  j d | d | d | d t j |   n( |  j d | d | d | d |  d S(	   s   Appends an iTXt chunk.

        :param key: latin-1 encodable text key name
        :param value: value for this key
        :param lang: language code
        :param tkey: UTF-8 version of the key name
        :param zip: compression flag

        s   latin-1t   stricts   utf-8RL   s     s    s      N(   t
   isinstancet   bytest   encodeRW   R   t   compress(   R!   t   keyt   valueRO   RP   t   zip(    (    s<   /usr/local/lib/python2.7/dist-packages/PIL/PngImagePlugin.pyt   add_itxt   s    +c         C   s   t  | t  r1 |  j | | | j | j d | St  | t  s y | j d d  } Wq t k
 r| |  j | | d | SXn  t  | t  s | j d d  } n  | r |  j d | d t	 j
 |   n |  j d | d |  d S(	   s   Appends a text chunk.

        :param key: latin-1 encodable text key name
        :param value: value for this key, text or an
           :py:class:`PIL.PngImagePlugin.iTXt` instance
        :param zip: compression flag

        R`   s   latin-1RY   t   zTXts     t   tEXts    N(   RZ   RL   Ra   RO   RP   R[   R\   t   UnicodeErrorRW   R   R]   (   R!   R^   R_   R`   (    (    s<   /usr/local/lib/python2.7/dist-packages/PIL/PngImagePlugin.pyt   add_text  s    	"$(   RJ   RK   RS   R"   RW   t   FalseRa   Re   (    (    (    s<   /usr/local/lib/python2.7/dist-packages/PIL/PngImagePlugin.pyRU      s
   		
t	   PngStreamc           B   s   e  Z d    Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z	 d   Z
 d	   Z d
   Z d   Z d   Z d   Z d   Z d   Z d   Z RS(   c         C   s\   t  j |  |  i  |  _ i  |  _ d |  _ d  |  _ d  |  _ d  |  _ d  |  _	 d |  _
 d  S(   Ni    (   i    i    (   R   R"   t   im_infot   im_textt   im_sizeR#   t   im_modet   im_tilet
   im_palettet   im_custom_mimetypet   text_memory(   R!   R   (    (    s<   /usr/local/lib/python2.7/dist-packages/PIL/PngImagePlugin.pyR"   '  s    							c         C   s8   |  j  | 7_  |  j  t k r4 t d |  j    n  d  S(   Ns7   Too much memory used in text chunks: %s>MAX_TEXT_MEMORY(   Ro   t   MAX_TEXT_MEMORYR   (   R!   t   chunklen(    (    s<   /usr/local/lib/python2.7/dist-packages/PIL/PngImagePlugin.pyt   check_text_memory6  s
    c         C   s   t  j |  j |  } | j d  } t j d | |   t j d t | |   t | |  } | d k r t d |   n  y t | | d  } Wn? t	 k
 r t  j
 r d  } q   n t j k
 r d  } n X| |  j d <| S(   Ns    s   iCCP profile name %rs   Compression method %si    s+   Unknown compression method %s in iCCP chunki   t   icc_profile(   R   RF   R   t   findR9   R:   R   R+   R   R   R*   R#   R   R@   Rh   (   R!   R.   R/   R   t   it   comp_methodRs   (    (    s<   /usr/local/lib/python2.7/dist-packages/PIL/PngImagePlugin.pyt
   chunk_iCCP>  s$    		
c         C   s   t  j |  j |  } t |  t | d  f |  _ y4 t t | d  t | d  f \ |  _ |  _ Wn t	 k
 r{ n Xt | d  r d |  j
 d <n  t | d  r t d   n  | S(	   Ni   i   i	   i   i   t	   interlacei   s   unknown filter category(   R   RF   R   R(   Rj   t   _MODESR   Rk   t
   im_rawmodet	   ExceptionRh   R+   (   R!   R.   R/   R   (    (    s<   /usr/local/lib/python2.7/dist-packages/PIL/PngImagePlugin.pyt
   chunk_IHDR[  s    4c         C   s5   d d |  j  | |  j f g |  _ | |  _ t  d  S(   NR`   i    (   i    i    (   Rj   Rz   Rl   t   im_idatt   EOFError(   R!   R.   R/   (    (    s<   /usr/local/lib/python2.7/dist-packages/PIL/PngImagePlugin.pyt
   chunk_IDATj  s    "	c         C   s
   t   d  S(   N(   R~   (   R!   R.   R/   (    (    s<   /usr/local/lib/python2.7/dist-packages/PIL/PngImagePlugin.pyt
   chunk_IENDq  s    c         C   s:   t  j |  j |  } |  j d k r6 d | f |  _ n  | S(   NR   R   (   R   RF   R   Rk   Rm   (   R!   R.   R/   R   (    (    s<   /usr/local/lib/python2.7/dist-packages/PIL/PngImagePlugin.pyt
   chunk_PLTEv  s    c         C   s   t  j |  j |  } |  j d k rq t j |  ra | j d  } | d k rn | |  j d <qn q | |  j d <ng |  j d k r t |  |  j d <nB |  j d k r t |  t | d	  t | d
  f |  j d <n  | S(   NR   s    i    t   transparencyR	   R
   R   R   i   i   (   R	   R
   R   (	   R   RF   R   Rk   t   _simple_palettet   matchRt   Rh   t   i16(   R!   R.   R/   R   Ru   (    (    s<   /usr/local/lib/python2.7/dist-packages/PIL/PngImagePlugin.pyt
   chunk_tRNS~  s    3c         C   s0   t  j |  j |  } t |  d |  j d <| S(   Ng     j@t   gamma(   R   RF   R   R(   Rh   (   R!   R.   R/   R   (    (    s<   /usr/local/lib/python2.7/dist-packages/PIL/PngImagePlugin.pyt
   chunk_gAMA  s    c         C   sV   t  j |  j |  } t j d t |  d |  } t d   | D  |  j d <| S(   Ns   >%dIi   c         s   s   |  ] } | d  Vq d S(   g     j@N(    (   t   .0t   elt(    (    s<   /usr/local/lib/python2.7/dist-packages/PIL/PngImagePlugin.pys	   <genexpr>  s    t   chromaticity(   R   RF   R   R?   t   unpackt   lent   tupleRh   (   R!   R.   R/   R   t   raw_vals(    (    s<   /usr/local/lib/python2.7/dist-packages/PIL/PngImagePlugin.pyt
   chunk_cHRM  s     c         C   s,   t  j |  j |  } t |  |  j d <| S(   Nt   srgb(   R   RF   R   R   Rh   (   R!   R.   R/   R   (    (    s<   /usr/local/lib/python2.7/dist-packages/PIL/PngImagePlugin.pyt
   chunk_sRGB  s    c         C   s   t  j |  j |  } t |  t | d  } } t | d  } | d k r t | d d  t | d d  f } | |  j d <n" | d k r | | f |  j d <n  | S(	   Ni   i   i   g
F%u?g      ?t   dpii    t   aspect(   R   RF   R   R(   R   t   intRh   (   R!   R.   R/   R   t   pxt   pyt   unitR   (    (    s<   /usr/local/lib/python2.7/dist-packages/PIL/PngImagePlugin.pyt
   chunk_pHYs  s    (c         C   s   t  j |  j |  } y | j d d  \ } } Wn t k
 rP | } d } n X| r t r | j d d  } | j d d  } n  | |  j | <|  j | <|  j	 t
 |   n  | S(   Ns    i   RX   s   latin-1RY   t   replace(   R   RF   R   t   splitR   R   R<   Rh   Ri   Rr   R   (   R!   R.   R/   R   t   kt   v(    (    s<   /usr/local/lib/python2.7/dist-packages/PIL/PngImagePlugin.pyt
   chunk_tEXt  s    
c         C   sJ  t  j |  j |  } y | j d d  \ } } Wn t k
 rP | } d } n X| rj t | d  } n d } | d k r t d |   n  y t | d  } Wn? t k
 r t  j r d } q   n t	 j
 k
 r d } n X| rFt r| j d d  } | j d d  } n  | |  j | <|  j | <|  j t |   n  | S(	   Ns    i   RX   i    s+   Unknown compression method %s in zTXt chunks   latin-1RY   R   (   R   RF   R   R   R   R   R+   R   R*   R   R@   R   R<   Rh   Ri   Rr   R   (   R!   R.   R/   R   R   R   Rv   (    (    s<   /usr/local/lib/python2.7/dist-packages/PIL/PngImagePlugin.pyt
   chunk_zTXt  s6    
		
c         C   s  t  j |  j |  } } y | j d d  \ } } Wn t k
 rI | SXt |  d k  r` | St | d  t | d  | d } } } y | j d d  \ } }	 }
 Wn t k
 r | SX| d k r*| d k r#y t |
  }
 Wq't k
 rt  j r| S  q't	 j
 k
 r| SXq*| Sn  t ryL | j d d  } | j d d  } |	 j d d  }	 |
 j d d  }
 Wqt k
 r| SXn  t |
 | |	  |  j | <|  j | <|  j t |
   | S(   Ns    i   i   i    s   latin-1RY   s   utf-8(   R   RF   R   R   R   R   R   R   R*   R   R@   R   R<   Rd   RL   Rh   Ri   Rr   (   R!   R.   R/   t   rR   R   t   cft   cmRO   t   tkR   (    (    s<   /usr/local/lib/python2.7/dist-packages/PIL/PngImagePlugin.pyt
   chunk_iTXt  sD    ,	$c         C   s*   t  j |  j |  } d | |  j d <| S(   Ns   Exif  t   exif(   R   RF   R   Rh   (   R!   R.   R/   R   (    (    s<   /usr/local/lib/python2.7/dist-packages/PIL/PngImagePlugin.pyt
   chunk_eXIf  s    c         C   s"   t  j |  j |  } d |  _ | S(   Ns
   image/apng(   R   RF   R   Rn   (   R!   R.   R/   R   (    (    s<   /usr/local/lib/python2.7/dist-packages/PIL/PngImagePlugin.pyt
   chunk_acTL#  s    	(   RJ   RK   R"   Rr   Rw   R|   R   R   R   R   R   R   R   R   R   R   R   R   R   (    (    (    s<   /usr/local/lib/python2.7/dist-packages/PIL/PngImagePlugin.pyRg   &  s"   															%	*	c         C   s   |  d  t  k S(   Ni   (   t   _MAGIC(   t   prefix(    (    s<   /usr/local/lib/python2.7/dist-packages/PIL/PngImagePlugin.pyt   _accept-  s    t   PngImageFilec           B   sb   e  Z d  Z d Z d   Z e d    Z d   Z d   Z d   Z	 d   Z
 d   Z d	   Z RS(
   t   PNGs   Portable network graphicsc         C   st  |  j  j d  t k r' t d   n  t |  j   |  _ x t r |  j j   \ } } } y |  j j | | |  } WnM t k
 r Pn< t	 k
 r t
 j d | | |  t j |  j  |  } n X|  j j | |  q< W|  j j |  _ |  j j |  _ |  j j |  _ d  |  _ |  j j |  _ |  j j |  _ |  j j rg|  j j \ } } t j | |  |  _ n  | |  _ d  S(   Ni   s   not a PNG files   %r %s %s (unknown)(    R   R&   R   R+   Rg   t   pngRD   R=   R~   t   AttributeErrorR9   R:   R   RF   R4   Rk   t   modeRj   t   _sizeRh   t   infoR#   t   _textRl   t   tileRn   t   custom_mimetypeRm   R   t   rawt   palettet   _PngImageFile__prepare_idat(   R!   R-   R.   R/   R   t   rawmodeR   (    (    s<   /usr/local/lib/python2.7/dist-packages/PIL/PngImagePlugin.pyt   _open:  s.    			c         C   s#   |  j  d  k r |  j   n  |  j  S(   N(   R   R#   t   load(   R!   (    (    s<   /usr/local/lib/python2.7/dist-packages/PIL/PngImagePlugin.pyRR   i  s    c         C   s}   |  j  d k r t d   n  |  j  j |  j d d d  |  j j   |  j j   |  j rp |  j  j   n  d |  _  d S(   s   Verify PNG files)   verify must be called directly after openi    i   i   N(	   R   R#   t   RuntimeErrorR%   R   R   RI   R1   t   _exclusive_fp(   R!   (    (    s<   /usr/local/lib/python2.7/dist-packages/PIL/PngImagePlugin.pyRI   r  s    	c         C   sE   |  j  j d  r% |  j d |  _ n  |  j |  _ t j j |   d S(   s"   internal: prepare to read PNG fileRx   i   N(   i   (   R   t   gett   decoderconfigR   t   _PngImageFile__idatR   t   load_prepare(   R!   (    (    s<   /usr/local/lib/python2.7/dist-packages/PIL/PngImagePlugin.pyR     s    c         C   s   xj |  j  d k rl |  j j d  |  j j   \ } } } | d k r` |  j j | | |  d S| |  _  q W| d k r |  j  } n t | |  j   } |  j  | |  _  |  j j |  S(   s   internal: read more image datai    i   t   IDATt   DDATRX   (   R   R   (   R   R   R&   R   R6   t   min(   R!   t
   read_bytesR-   R.   R/   (    (    s<   /usr/local/lib/python2.7/dist-packages/PIL/PngImagePlugin.pyt	   load_read  s    c         C   s  x t  r |  j j d  y |  j j   \ } } } Wn t j t f k
 rR Pn X| d k rc Pn  y |  j j | | |  Wq t k
 r Pq t	 k
 r t
 j |  j |  q t k
 r t j d | | |  t
 j |  j |  q Xq W|  j j |  _ |  j j   d |  _ d S(   s%   internal: finished reading image datai   RC   s   %r %s %s (unknown)N(   RD   R   R&   R   R?   R@   R+   R=   t   UnicodeDecodeErrorR~   R   RF   R   R9   R:   Ri   R   R1   R#   (   R!   R-   R.   R/   (    (    s<   /usr/local/lib/python2.7/dist-packages/PIL/PngImagePlugin.pyt   load_end  s(    	c         C   s?   d |  j  k r |  j   n  d |  j  k r/ d  St |  j    S(   NR   (   R   R   R#   t   dictt   getexif(   R!   (    (    s<   /usr/local/lib/python2.7/dist-packages/PIL/PngImagePlugin.pyt   _getexif  s
    c         C   s,   d |  j  k r |  j   n  t j j |   S(   NR   (   R   R   R   R   (   R!   (    (    s<   /usr/local/lib/python2.7/dist-packages/PIL/PngImagePlugin.pyR     s    (   RJ   RK   t   formatt   format_descriptionR   t   propertyRR   RI   R   R   R   R   R   (    (    (    s<   /usr/local/lib/python2.7/dist-packages/PIL/PngImagePlugin.pyR   5  s   	/							s    s   L;1s    s    s    s   s    s   I;16s   s   s   s   s   s   c         G   se   d j  |  } |  j t t |   |  |  j |  t | t |   } |  j t |   d S(   s'   Write a PNG chunk (including CRC field)RX   N(   t   joint   writet   o32R   R   (   R   R-   R   R4   (    (    s<   /usr/local/lib/python2.7/dist-packages/PIL/PngImagePlugin.pyt   putchunk  s
    t   _idatc           B   s   e  Z d    Z d   Z RS(   c         C   s   | |  _  | |  _ d  S(   N(   R   t   chunk(   R!   R   R   (    (    s<   /usr/local/lib/python2.7/dist-packages/PIL/PngImagePlugin.pyR"     s    	c         C   s   |  j  |  j d |  d  S(   NR   (   R   R   (   R!   R   (    (    s<   /usr/local/lib/python2.7/dist-packages/PIL/PngImagePlugin.pyR     s    (   RJ   RK   R"   R   (    (    (    s<   /usr/local/lib/python2.7/dist-packages/PIL/PngImagePlugin.pyR     s   	c      	   C   s  |  j  } | d k r d |  j k r8 d |  j d >} nA |  j rs t t t |  j j   d  d d  d  } n d } | d k r d } n0 | d k r d } n | d k r d } n d	 } | d	 k r d
 | | f } q n  |  j j d t  |  j j d d  |  j j d d  |  j j d d  f |  _	 y t
 | \ } } Wn! t k
 rht d |   n X| j t  | | d t |  j d  t |  j d  | d d d  d d d d d g } |  j j d |  j j d   }	 |	 r(d }
 |
 d t j |	  } | | d |  | j d  n  |  j j d  } | rd d  d! d" g } xe | j D]W \ } } | | k r| j |  | | | |  q\| | k r\| | | |  q\q\Wn  |  j  d k r#d | d } |  j j d#  |  } x  t |  | k  r| d 7} qW| | d$ |  n  |  j j d% |  j j d% d    } | sY| d k r|  j  d k rd | } t | t  r| | d& | |   q~t d t d' |   } d( | d } | | d& | |   q|  j  d> k rt d t d, |   } | | d& t |   q|  j  d# k r`| \ } } } | | d& t |  t |  t |   qd% |  j k rt d-   qnZ |  j  d k r|  j j   d. k r|  j j d. d/  } d | } | | d& | |   n  |  j j d0  } | r<| | d1 t t | d d2 d3   t t | d d2 d3   d4  n  |  j j d  } | rd5 d6 g } xF | j D]8 \ } } | | k rj| j |  | | | |  qjqjWn  |  j j d7 |  j j d7   } | r#t | t j  r| j  d	  } n  | j! d8  r| d9 } n  | | d: |  n  t" j# |  t$ | |  d; d? |  j d | f g  | | d< d  t% | d=  r| j&   n  d  S(@   NR   t   bitsi   i   i   i   i   i   i   s   %s;%dt   optimizet   compress_levelit   compress_typet
   dictionaryRX   s   cannot write mode %s as PNGt   IHDRi    s    t   cHRMt   gAMAt   sBITt   sRGBt   tIMERs   s   ICC Profiles     t   iCCPt   pnginfot   sPLTRL   Rc   Rb   R   t   PLTER   t   tRNSi   s   R	   R
   R   i  s%   cannot use transparency for this modeR   t   AR   t   pHYsg
F%u?g      ?s   t   bKGDt   hISTR   s   Exif  i   t   eXIfR`   RC   t   flush(   R	   R
   R   (   i    i    ('   R   t   encoderinfoR   t   maxR   R   t   getdataR   Rf   t   encoderconfigt	   _OUTMODESt   KeyErrorRE   R   R   R   t   sizeR   R   R]   t   removeRV   t   imt
   getpaletteR#   RZ   R[   t   o16t   getpalettemodeR   R    t   Exift   tobytest
   startswithR   t   _saveR   t   hasattrR   (   R   R   t   filenameR   R   t   colorsR   R   RV   t   icct   nameR   R   t   chunks_multiple_allowedR-   t   palette_byte_numbert   palette_bytesR   t   alpha_bytest   alphat   redt   greent   blueR   R   (    (    s<   /usr/local/lib/python2.7/dist-packages/PIL/PngImagePlugin.pyR     s    		2			!$
-$

!2c         K   sY   d t  f d     Y} d   } |   } z  | |  _ t |  | d |  Wd |  ` X| j S(   s4   Return a list of PNG chunks representing this image.t	   collectorc           B   s    e  Z g  Z d    Z d   Z RS(   c         S   s   d  S(   N(    (   R!   R   (    (    s<   /usr/local/lib/python2.7/dist-packages/PIL/PngImagePlugin.pyR     s    c         S   s   |  j  j |  d  S(   N(   R   R5   (   R!   R   (    (    s<   /usr/local/lib/python2.7/dist-packages/PIL/PngImagePlugin.pyR5     s    (   RJ   RK   R   R   R5   (    (    (    s<   /usr/local/lib/python2.7/dist-packages/PIL/PngImagePlugin.pyR    s   	c         W   sD   d j  |  } t t | t |    } |  j | | | f  d  S(   NRX   (   R   R   R   R5   (   R   R-   R   R4   (    (    s<   /usr/local/lib/python2.7/dist-packages/PIL/PngImagePlugin.pyR5     s    N(   t   objectR   R   R#   R   (   R   t   paramsR  R5   R   (    (    s<   /usr/local/lib/python2.7/dist-packages/PIL/PngImagePlugin.pyt	   getchunks  s    				s   .pngs   .apngs	   image/png(5   t   loggingt   reR?   R   RX   R    R   R   t   _binaryR   R   R   R   R(   R   R   R   R   t   _utilR   t   __version__t	   getLoggerRJ   R9   t   compileR   R)   R   Ry   R   t	   SAFEBLOCKR   Rp   R   R   R  R   RM   RL   RU   Rg   R   R   R   R   R   R   R
  t   register_openR   t   register_savet   register_extensionst   register_mime(    (    (    s<   /usr/local/lib/python2.7/dist-packages/PIL/PngImagePlugin.pyt   <module>"   sz   (	
	XO 			