ó
î Xc           @   s¿  d  Z  d d l Z d d l Z d d l m Z m Z m Z e j Z e j	 Z
 e j d ƒ Z e j d ƒ Z d Z d d l Z e j j d ƒ rd d l Z e e d ƒ rµ e j Z n d d l Z e j j Z x3 d D]" Z e e ƒ d k	 rÔ e Z PqÔ qÔ We Z n  d „  Z d d „ Z d d d „  ƒ  YZ d „  Z d e j f d „  ƒ  YZ  d d „ Z! e j" e  j# e  e ƒ e j$ e  j# e! ƒ e j% e  j# d ƒ e j% e  j# d ƒ e j& e  j# d ƒ d S(   s   0.5iÿÿÿÿN(   t   Imaget	   ImageFilet   _binarys   ^%%([^:]*):[ \t]*(.*)[ \t]*$s   ^%[%!\w]([^:]*)[ \t]*$t   wint   whicht   gswin32ct   gswin64ct   gsc          C   sv   t  r
 t St j j d ƒ sr d d  l }  y3 |  j d d g d |  j ƒ} | j j	 ƒ  t SWqr t
 k
 rn qr Xn  t S(   NR   iÿÿÿÿR   s	   --versiont   stdout(   t   gs_windows_binaryt   Truet   syst   platformt
   startswitht
   subprocesst   Popent   PIPER   t   readt   OSErrort   False(   R   R   (    (    s6   /usr/lib/python2.7/dist-packages/PIL/EpsImagePlugin.pyt   has_ghostscript8   s    i   c         C   sæ  |  d \ } }  } } | \ } } t  | ƒ p1 d } | d | | d | f } t d | d | d | d ƒ t d | d | d | d ƒ f }	 d d l }
 d d l } d d l } | j ƒ  \ } } |
 j | ƒ d } t | d ƒ r|
 j	 j
 | j ƒ r| j } n¾ | j ƒ  \ } } |
 j | ƒ | } t | d	 ƒ ˆ } | j d d ƒ | j ƒ  } | j d ƒ | } xO | d k rÈ| j t | d ƒ ƒ } | s¨Pn  | t | ƒ 8} | j | ƒ qzWWd QXd d d | d |	 d d d | d d | d | d f d | g } t d k	 rDt s7t d ƒ ‚ n  t | d <n  zi | j | d | j d | j ƒ} | j j ƒ  | j ƒ  } | ršt d | ƒ ‚ n  t j j | ƒ } Wd y' |
 j | ƒ | rÖ|
 j | ƒ n  Wn n XX| S(   s!   Render an image using Ghostscripti    i   g      R@i   i   iÿÿÿÿNt   namet   wbid   i   R   s   -qs   -g%dx%ds   -r%fx%fs   -dNOPAUSE -dSAFERs   -sDEVICE=ppmraws   -sOutputFile=%ss   -cs   %d %d translates   -fs%   Unable to locate Ghostscript on pathst   stdinR   s   gs failed (status %d)i  (   t   intt   floatt   osR   t   tempfilet   mkstempt   closet   Nonet   hasattrt   patht   existsR   t   opent   seekt   tellR   t   mint   lent   writeR	   t   WindowsErrorR   R   R   t   waitt   IOErrorR    t   coret   open_ppmt   unlink(   t   tilet   sizet   fpt   scalet   decodert   offsett   datat   lengtht   bboxt   resR   R   R   t   out_fdt   outfilet   infile_tempt   infilet   in_fdt   ft   fsizet
   lengthfilet   st   commandR   t   statust   im(    (    s6   /usr/lib/python2.7/dist-packages/PIL/EpsImagePlugin.pyt   GhostscriptG   sp    !'$t   PSFilec           B   s,   e  Z d  Z d „  Z d d „ Z d „  Z RS(   sP   
    Wrapper for bytesio object that treats either CR or LF as end of line.
    c         C   s   | |  _  d  |  _ d  S(   N(   R0   R   t   char(   t   selfR0   (    (    s6   /usr/lib/python2.7/dist-packages/PIL/EpsImagePlugin.pyt   __init__¤   s    	i    c         C   s    d  |  _ |  j j | | ƒ d  S(   N(   R   RF   R0   R#   (   RG   R3   t   whence(    (    s6   /usr/lib/python2.7/dist-packages/PIL/EpsImagePlugin.pyR#   ¨   s    	c         C   s–   |  j  p d } d  |  _  |  j j d ƒ } x, | d k rX | | } |  j j d ƒ } q- W|  j j d ƒ |  _  |  j  d k r‰ d  |  _  n  | j d ƒ S(   Nt    i   s   
s   latin-1(   RF   R   R0   R   t   decode(   RG   R@   t   c(    (    s6   /usr/lib/python2.7/dist-packages/PIL/EpsImagePlugin.pyt   readline¬   s    	
(   t   __name__t
   __module__t   __doc__RH   R#   RM   (    (    (    s6   /usr/lib/python2.7/dist-packages/PIL/EpsImagePlugin.pyRE       s   	c         C   s    |  d  d k p t  |  ƒ d k S(   Ni   s   %!PSIÅÐÓÆ    (   t   i32(   t   prefix(    (    s6   /usr/lib/python2.7/dist-packages/PIL/EpsImagePlugin.pyt   _accept½   s    t   EpsImageFilec           B   s\   e  Z d  Z d Z d Z i d d 6d d 6d d 6Z d	 „  Z d
 „  Z d d „ Z d „  Z	 RS(   s.   EPS File Parser for the Python Imaging Libraryt   EPSs   Encapsulated Postscriptt   Li   t   LABi   t   RGBi   c         C   s’  |  j  |  j ƒ \ } } yC t t k r? t |  j j d ƒ } n t |  j j d d d ƒ} Wn t |  j ƒ } n X| j | ƒ d  } d |  _	 d |  _
 | j ƒ  j d ƒ } xÙ| r‰t | ƒ d k rØ t d ƒ ‚ n  y t j | ƒ } Wn" t j k
 r} t d ƒ ‚ n X| rÒ| j d d	 ƒ \ } } | |  j | <| d
 k r]y{ g  | j ƒ  D] } t t | ƒ ƒ ^ qW} | d	 | d | d | d f |  _
 d d |  j
 | | | f f g |  _ WqÏqÏXq]n‹ t j | ƒ } | r>| j d ƒ } | d k rPn  | d  d k r.| d |  j | d  <q]d |  j | <n | d d k rQn t d ƒ ‚ | j ƒ  j d ƒ } | d d k r± Pq± q± Wxì | d d k rxt | ƒ d k r¾t d ƒ ‚ n  | d  d k rV| d j d  d ƒ \ }	 }
 } } } } } } t | ƒ d k rPn  y |  j t | ƒ |  _	 Wn Pn Xt |	 ƒ t |
 ƒ f |  _
 d  S| j ƒ  j d ƒ } | sPqqW| sŽt d ƒ ‚ n  d  S(   Nt   Urt   encodings   latin-1RX   i   s   
iÿ   s   not an EPS filei   t   BoundingBoxi    i   t   epst   EndCommentsi   s   PS-Adobei	   RJ   t   %s   bad EPS headeri   s   %ImageData:i   s!   cannot determine EPS bounding box(   i   i   (   i    i    (   t   _find_offsetR0   t   bytest   strR"   R   RE   R#   R   t   modeR/   RM   t   stripR&   t   SyntaxErrort   splitt   matcht   ret   errort   groupt   infoR   R   R.   t   fieldR*   t   mode_map(   RG   R5   R3   R0   t   boxR@   t   mt   vt   kt   xt   yt   bit   mot   z3t   z4t   ent   id(    (    s6   /usr/lib/python2.7/dist-packages/PIL/EpsImagePlugin.pyt   _openÍ   s|    			+'
.c         C   sœ   | j  d ƒ } | d  d k rD | j d d ƒ | j ƒ  } d } nN t | d d !ƒ d k r† t | d d !ƒ } t | d d !ƒ } n t d	 ƒ ‚ | | f S(
   Ni    i   s   %!PSi    i   IÅÐÓÆ    i   i   s   not an EPS file(   R   R#   R$   RQ   Rd   (   RG   R0   R@   R5   R3   (    (    s6   /usr/lib/python2.7/dist-packages/PIL/EpsImagePlugin.pyR_   6  s    	c         C   sY   |  j  s d  St |  j  |  j |  j | ƒ |  _ |  j j |  _ |  j j |  _ g  |  _  d  S(   N(   R.   RD   R/   R0   RC   Rb   (   RG   R1   (    (    s6   /usr/lib/python2.7/dist-packages/PIL/EpsImagePlugin.pyt   loadL  s    	!c         O   s   d  S(   N(    (   RG   t   argst   kwargs(    (    s6   /usr/lib/python2.7/dist-packages/PIL/EpsImagePlugin.pyt	   load_seekU  s    (
   RN   RO   RP   t   formatt   format_descriptionRl   Ry   R_   Rz   R}   (    (    (    s6   /usr/lib/python2.7/dist-packages/PIL/EpsImagePlugin.pyRT   Å   s   	i		c         C   s?  |  j  ƒ  |  j d k r" d& } n< |  j d k r: d' } n$ |  j d k rR d( } n t d ƒ ‚ d d) d „  ƒ  Y} | } | | ƒ } t j d d k r® t j | d d ƒ} n  | r1| j d ƒ | j d ƒ | j d |  j ƒ | j d ƒ | j d ƒ | j d ƒ | j d |  j ƒ | j d | ƒ n  | j d ƒ | j d ƒ | j d |  j d | d ƒ | j d |  j ƒ | j d |  j ƒ | j d |  j d |  j d |  j d f ƒ | j d  ƒ | j | d d! ƒ | j	 ƒ  t
 j |  | d" d* |  j d d% f g ƒ | j d# ƒ | j d$ ƒ | j	 ƒ  d% S(+   s*   EPS Writer for the Python Imaging Library.RV   i   i   t   imageRX   i   s   false 3 colorimaget   CMYKi   s   false 4 colorimages   image mode is not supportedt   NoCloseStreamc           B   s#   e  Z d  „  Z d „  Z d „  Z RS(   c         S   s   | |  _  d  S(   N(   R0   (   RG   R0   (    (    s6   /usr/lib/python2.7/dist-packages/PIL/EpsImagePlugin.pyRH   q  s    c         S   s   t  |  j | ƒ S(   N(   t   getattrR0   (   RG   R   (    (    s6   /usr/lib/python2.7/dist-packages/PIL/EpsImagePlugin.pyt   __getattr__t  s    c         S   s   d  S(   N(    (   RG   (    (    s6   /usr/lib/python2.7/dist-packages/PIL/EpsImagePlugin.pyR   w  s    (   RN   RO   RH   R„   R   (    (    (    s6   /usr/lib/python2.7/dist-packages/PIL/EpsImagePlugin.pyR‚   p  s   		i    i   RZ   s   latin-1s   %!PS-Adobe-3.0 EPSF-3.0
s   %%Creator: PIL 0.1 EpsEncode
s   %%%%BoundingBox: 0 0 %d %d
s   %%Pages: 1
s   %%EndComments
s   %%Page: 1 1
s   %%ImageData: %d %d s   %d %d 0 1 1 "%s"
s   gsave
s   10 dict begin
s   /buf %d string def
s   %d %d scale
s   %d %d 8
s   [%d 0 0 -%d 0 %d]
s+   { currentfile buf readhexstring pop } bind
s   
R\   s   
%%%%EndBinary
s   grestore end
N(   i   i   R€   (   i   i   s   false 3 colorimage(   i   i   s   false 4 colorimage(    (   i    i    (   Rz   Rb   t
   ValueErrorR   t   version_infot   iot   TextIOWrapperR'   R/   t   flushR   t   _saveR   (   RC   R0   t   filenameR\   t   operatorR‚   t   base_fp(    (    s6   /usr/lib/python2.7/dist-packages/PIL/EpsImagePlugin.pyRŠ   ^  sF    
			
 /
)s   .pss   .epss   application/postscript(   R   R   s   gs(    ('   t   __version__Rg   R‡   t   PILR    R   R   t   i32leRQ   t   o32let   o32t   compileRe   Rk   R   R	   R   R   R   t   shutilR   R   t   distutils.spawnt	   distutilst   spawnt   find_executablet   binaryR   R   RD   RE   RS   RT   RŠ   t   register_openR~   t   register_savet   register_extensiont   register_mime(    (    (    s6   /usr/lib/python2.7/dist-packages/PIL/EpsImagePlugin.pyt   <module>   s>   				Y	™C