ó
î Xc           @  sę   d  d l  m Z d Z d  d l m Z m Z m Z d  d l Z d  d l Z e j	 Z	 e j
 Z e j Z e j Z i d d 6d d 6Z e d	  d
 Z d   Z d   Z d e j f d     YZ e j d e  e j d d  d   Z d S(   i˙˙˙˙(   t   print_functions   0.3(   t   Imaget	   ImageFilet   _binaryNt   rawi   t   jpegi   i    i   c         C  s   t  t |  d  S(   Niü˙˙˙(   t   i32t   PAD(   t   c(    (    s7   /usr/lib/python2.7/dist-packages/PIL/IptcImagePlugin.pyt   i+   s    c         C  s6   x( |  D]  } t  d t |  d d q Wt    d  S(   Ns   %02xt   endt    (   t   printt   i8(   R   R	   (    (    s7   /usr/lib/python2.7/dist-packages/PIL/IptcImagePlugin.pyt   dump/   s    t   IptcImageFilec           B  s8   e  Z d  Z d Z d   Z d   Z d   Z d   Z RS(   t   IPTCs   IPTC/NAAc         C  s   t  |  j |  S(   N(   R	   t   info(   t   selft   key(    (    s7   /usr/lib/python2.7/dist-packages/PIL/IptcImagePlugin.pyt   getint>   s    c         C  s  |  j  j d  } t |  s" d St | d  t | d  f } t | d  d k sx | d d k  sx | d d k r t d   n  t | d  } | d	 k r˛ t d
   nP | d k rÇ d } n; | d k rň t |  j  j | d   } n t | d  } | | f S(   Ni   i    i   i   i   i	   s   invalid IPTC/NAA filei   i   s%   illegal field length in IPTC/NAA filei   (   Ni    (	   t   fpt   readt   lent   NoneR   t   SyntaxErrort   IOErrorR	   t   i16(   R   t   st   tagt   size(    (    s7   /usr/lib/python2.7/dist-packages/PIL/IptcImagePlugin.pyt   fieldA   s     6	c   	      C  s<  xŐ t  r× |  j j   } |  j   \ } } | s= | d k rA Pn  | r\ |  j j |  } n d  } | t |  j j    k rÇ t	 |  j | t  rŞ |  j | j
 |  qÔ |  j | | g |  j | <q | |  j | <q Wt |  j d d  } t |  j d d  } d |  j k r3t |  j d d  d } n d } | d k rX| rXd |  _ nD | d k rz| rzd	 | |  _ n" | d
 k r| rd | |  _ n  |  j d  |  j d  f |  _ y t |  j d  } Wn t k
 rót d   n X| d k r8d | | f d d |  j d |  j d f f g |  _ n  d  S(   Ni   i
   i   i<   i    i   iA   t   Lt   RGBi   t   CMYKi   i   ix   s   Unknown IPTC image compressiont   iptc(   i   i
   (   i   i<   (   i   i<   (   i   iA   (   i   iA   (   i   i   (   i   i   (   i   ix   (   i   i
   (   t   TrueR   t   tellR   R   R   t   listR   t   keyst
   isinstancet   appendR   t   modeR   R   t   COMPRESSIONt   KeyErrorR   t   tile(	   R   t   offsetR   R   t   tagdatat   layerst	   componentt   idt   compression(    (    s7   /usr/lib/python2.7/dist-packages/PIL/IptcImagePlugin.pyt   _open[   s@    	!c         C  sľ  t  |  j  d k s, |  j d d d k r< t j j |   S|  j d \ } } } | \ } } |  j j |  t j d t  \ } } t	 j
 |  } | d k r¸ | j d |  j  n  x t r;|  j   \ } }	 | d
 k ră Pn  xR |	 d k r7|  j j t |	 d	   }
 |
 sPn  | j |
  |	 t  |
  8}	 qć Wqť W| j   zL y t j j |  |  _ Wn, t j |  } | j   | j |  _ n XWd  y t	 j |  Wn n XXd  S(   Ni   i    R#   t   textR   s   P5
%d %d
255
i   i
   i    (   i   i
   (   R   R-   R   t   loadR   t   seekt   tempfilet   mkstempt   Falset   ost   fdopent   writeR   R$   R   R   t   mint   closeR   t   coret   open_ppmt   imt   opent   unlink(   R   t   typeR-   t   boxt   encodingR.   t   o_fdt   outfilet   oR   R   RB   (    (    s7   /usr/lib/python2.7/dist-packages/PIL/IptcImagePlugin.pyR6      s>    ,	

(   t   __name__t
   __module__t   formatt   format_descriptionR   R   R4   R6   (    (    (    s7   /usr/lib/python2.7/dist-packages/PIL/IptcImagePlugin.pyR   9   s   			2R   s   .iimc         C  sV  d d l  m } m } d d  l } d  } t |  t  r> |  j St |  | j  ry$|  j	 d } | d  d k rs| d } d } xđ | | | d !d k ro| d 7} | j
 | |  } | d	 7} t | |  } | | d
 | d
 | !}	 d
 | | } | d
 @r| d
 7} n  | j | |  }
 | d 7} | d k rK| | | |
 !} Pn  | |
 } | d
 @r | d
 7} q q Wn  Wq×t t f k
 rq×XnF t |  | j  r×y |  j j | j } Wq×t t f k
 rÓq×Xn  | d  k rçd  Sd d d     Y} |   }  t |  _ i  |  _ | j |  |  _ y |  j   Wn t t f k
 rNn X|  j S(   Ni˙˙˙˙(   t   TiffImagePlugint   JpegImagePlugint   APP13i   s   Photoshop 3.0 i    i   t   8BIMi   i   i  t	   FakeImagec           B  s   e  Z RS(    (   RK   RL   (    (    (    s7   /usr/lib/python2.7/dist-packages/PIL/IptcImagePlugin.pyRS   ţ   s   (    (   t   PILRO   RP   t   ioR   R(   R   R   t   JpegImageFilet   appR   R   R   t   AttributeErrorR,   t   TiffImageFileR   R/   t   IPTC_NAA_CHUNKt	   __class__t   BytesIOR   R4   t
   IndexError(   RB   RO   RP   RU   t   dataRW   R.   t   codet   name_lent   nameR   RS   (    (    s7   /usr/lib/python2.7/dist-packages/PIL/IptcImagePlugin.pyt   getiptcinfoÇ   s^    






			(   t
   __future__R    t   __version__RT   R   R   R   R;   R8   R   t   i16beR   t   i32beR   t   o8R+   R   R	   R   R   t   register_opent   register_extensionRb   (    (    (    s7   /usr/lib/python2.7/dist-packages/PIL/IptcImagePlugin.pyt   <module>   s$   				
		

