
4ec           @   s  d  d l  Z  d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z d d l m	 Z	 y d  d l
 m
 Z
 Wn e k
 r e j
 Z
 n Xe	 r d   Z n	 d   Z d   Z i) d d	 6d
 d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d  d! 6d" d# 6d$ d% 6d& d' 6d( d) 6d* d+ 6d, d- 6d. d/ 6d0 d1 6d2 d3 6d4 d5 6d6 d7 6d8 d9 6d: d; 6d< d= 6d> d? 6d@ dA 6dB dC 6dD dE 6dF dG 6dH dI 6dJ dK 6dL dM 6dN dO 6dP dQ 6dR dS 6dT dU 6dV dW 6dX dY 6Z dZ   Z d[ e f d\     YZ d]   Z d^ e j d_ d` da g  f db     YZ dc e f dd     YZ de dt df     YZ dg du dh     YZ di e f dj     YZ dk e
 f dl     YZ dm dv dn     YZ do dw dp     YZ dq   Z dr dx ds     YZ d S(y   iNi   (   t   py3(   t   UserDictc         C   s   |  j  d  S(   Ns   us-ascii(   t   encode(   t   s(    (    s7   /usr/local/lib/python2.7/dist-packages/PIL/PdfParser.pyt
   make_bytes   s    c         C   s   |  S(   N(    (   R   (    (    s7   /usr/local/lib/python2.7/dist-packages/PIL/PdfParser.pyR      s    c         C   s   t  j |  j d  S(   Nt	   utf_16_be(   t   codecst   BOM_UTF16_BER   (   R   (    (    s7   /usr/local/lib/python2.7/dist-packages/PIL/PdfParser.pyt   encode_text    s    u   i   u   ˘i   u   ˇi   u   ˆi   u   ˙i   u   ˝i   u   ˛i   u   ˚i   u   ˜i   u   •i   u   †i   u   ‡i   u   …i   u   —i   u   –i   u   ƒi   u   ⁄i   u   ‹i   u   ›i   u   −i   u   ‰i   u   „i   u   “i   u   ”i   u   ‘i   u   ’i   u   ‚i   u   ™i   u   ﬁi   u   ﬂi   u   Łi   u   Œi   u   Ši   u   Ÿi   u   Ži   u   ıi   u   łi   u   œi   u   ši   u   ži   u   €i   c         C   sn   |  t  t j   t j k r6 |  t  t j  j d  St rS d j d   |  D  Sd j d   |  D  Sd  S(   NR   t    c         s   s'   |  ] } t  j | t |   Vq d  S(   N(   t   PDFDocEncodingt   gett   chr(   t   .0t   byte(    (    s7   /usr/local/lib/python2.7/dist-packages/PIL/PdfParser.pys	   <genexpr>U   s    u    c         s   s'   |  ] } t  j t |  |  Vq d  S(   N(   R
   R   t   ord(   R   R   (    (    s7   /usr/local/lib/python2.7/dist-packages/PIL/PdfParser.pys	   <genexpr>W   s    (   t   lenR   R   t   decodeR    t   join(   t   b(    (    s7   /usr/local/lib/python2.7/dist-packages/PIL/PdfParser.pyt   decode_textQ   s
    t   PdfFormatErrorc           B   s   e  Z d  Z RS(   s\   An error that probably indicates a syntactic or semantic error in the
    PDF file structure(   t   __name__t
   __module__t   __doc__(    (    (    s7   /usr/local/lib/python2.7/dist-packages/PIL/PdfParser.pyR   Z   s   c         C   s   |  s t  |   n  d  S(   N(   R   (   t	   conditiont   error_message(    (    s7   /usr/local/lib/python2.7/dist-packages/PIL/PdfParser.pyt   check_format_conditiona   s    t   IndirectReferencet   IndirectReferenceTuplet	   object_idt
   generationc           B   s5   e  Z d    Z d   Z d   Z d   Z d   Z RS(   c         C   s   d |  S(   Ns   %s %s R(    (   t   self(    (    s7   /usr/local/lib/python2.7/dist-packages/PIL/PdfParser.pyt   __str__i   s    c         C   s   |  j    j d  S(   Ns   us-ascii(   R!   R   (   R    (    (    s7   /usr/local/lib/python2.7/dist-packages/PIL/PdfParser.pyt	   __bytes__l   s    c         C   s4   | j  |  j  k o3 | j |  j k o3 | j |  j k S(   N(   t	   __class__R   R   (   R    t   other(    (    s7   /usr/local/lib/python2.7/dist-packages/PIL/PdfParser.pyt   __eq__o   s    c         C   s   |  | k S(   N(    (   R    R$   (    (    s7   /usr/local/lib/python2.7/dist-packages/PIL/PdfParser.pyt   __ne__v   s    c         C   s   t  |  j |  j f  S(   N(   t   hashR   R   (   R    (    (    s7   /usr/local/lib/python2.7/dist-packages/PIL/PdfParser.pyt   __hash__y   s    (   R   R   R!   R"   R%   R&   R(   (    (    (    s7   /usr/local/lib/python2.7/dist-packages/PIL/PdfParser.pyR   f   s
   				t   IndirectObjectDefc           B   s   e  Z d    Z RS(   c         C   s   d |  S(   Ns	   %s %s obj(    (   R    (    (    s7   /usr/local/lib/python2.7/dist-packages/PIL/PdfParser.pyR!   ~   s    (   R   R   R!   (    (    (    s7   /usr/local/lib/python2.7/dist-packages/PIL/PdfParser.pyR)   }   s   t	   XrefTablec           B   sP   e  Z d    Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z	 RS(   c         C   s/   i  |  _  i  |  _ i d d 6|  _ t |  _ d  S(   Ni   i    (   t   existing_entriest   new_entriest   deleted_entriest   Falset   reading_finished(   R    (    (    s7   /usr/local/lib/python2.7/dist-packages/PIL/PdfParser.pyt   __init__   s    		c         C   sF   |  j  r | |  j | <n | |  j | <| |  j k rB |  j | =n  d  S(   N(   R/   R,   R+   R-   (   R    t   keyt   value(    (    s7   /usr/local/lib/python2.7/dist-packages/PIL/PdfParser.pyt   __setitem__   s
    	c         C   s/   y |  j  | SWn t k
 r* |  j | SXd  S(   N(   R,   t   KeyErrorR+   (   R    R1   (    (    s7   /usr/local/lib/python2.7/dist-packages/PIL/PdfParser.pyt   __getitem__   s    c         C   s   | |  j  k r> |  j  | d d } |  j  | =| |  j | <nm | |  j k rr |  j | d d } | |  j | <n9 | |  j k r |  j | } n t d t |  d   d  S(   Ni   s
   object ID s+    cannot be deleted because it doesn't exist(   R,   R-   R+   t
   IndexErrort   str(   R    R1   R   (    (    s7   /usr/local/lib/python2.7/dist-packages/PIL/PdfParser.pyt   __delitem__   s    
c         C   s   | |  j  k p | |  j k S(   N(   R+   R,   (   R    R1   (    (    s7   /usr/local/lib/python2.7/dist-packages/PIL/PdfParser.pyt   __contains__   s    c         C   s?   t  t |  j j    t |  j j    Bt |  j j    B S(   N(   R   t   setR+   t   keysR,   R-   (   R    (    (    s7   /usr/local/lib/python2.7/dist-packages/PIL/PdfParser.pyt   __len__   s    c         C   s9   t  |  j j    t  |  j j    t  |  j j    BS(   N(   R:   R+   R;   R-   R,   (   R    (    (    s7   /usr/local/lib/python2.7/dist-packages/PIL/PdfParser.pyR;      s    %c         C   s  t  t |  j j    t |  j j    B } t  t |  j j     } | j   } | j d  xS| rd  } x` t |  D]F \ } } | d  k s | d | k r | } q~ | |  } | | } Pq~ W| } d  } | j t	 d | d t
 |  f   x | D] }	 |	 |  j k r8| j t	 d |  j |	   q| j d  }
 t |	 |
 k d |	 |
 f  y | d } Wn t k
 rd } n X| j t	 d | |  j |	 f   qWqe W| S(   Ns   xref
i   s   %d %d
i    s   %010d %05d n 
s>   expected the next deleted object ID to be %s, instead found %ss   %010d %05d f 
(   t   sortedR:   R,   R;   R-   t   tellt   writet   Nonet	   enumerateR   R   t   popR   R6   (   R    t   fR;   t   deleted_keyst	   startxreft   prevt   indexR1   t   contiguous_keysR   t   this_deleted_object_idt   next_in_linked_list(    (    s7   /usr/local/lib/python2.7/dist-packages/PIL/PdfParser.pyR?      s@    .		

'!	
 (
   R   R   R0   R3   R5   R8   R9   R<   R;   R?   (    (    (    s7   /usr/local/lib/python2.7/dist-packages/PIL/PdfParser.pyR*      s   							t   PdfNamec           B   s|   e  Z d    Z d   Z d   Z d   Z d   Z e d    Z e	 e
 d d   e	 d   d	 D  Z d
   Z e Z RS(   c         C   sO   t  | t  r | j |  _ n- t  | t  r9 | |  _ n | j d  |  _ d  S(   Ns   us-ascii(   t
   isinstanceRK   t   namet   bytesR   (   R    RM   (    (    s7   /usr/local/lib/python2.7/dist-packages/PIL/PdfParser.pyR0      s
    c         C   s   |  j  j d  S(   Ns   us-ascii(   RM   R   (   R    (    (    s7   /usr/local/lib/python2.7/dist-packages/PIL/PdfParser.pyt   name_as_str   s    c         C   s.   t  | t  r! | j |  j k p- | |  j k S(   N(   RL   RK   RM   (   R    R$   (    (    s7   /usr/local/lib/python2.7/dist-packages/PIL/PdfParser.pyR%      s    !c         C   s   t  |  j  S(   N(   R'   RM   (   R    (    (    s7   /usr/local/lib/python2.7/dist-packages/PIL/PdfParser.pyR(      s    c         C   s   d t  |  j  S(   Ns   PdfName(%s)(   t   reprRM   (   R    (    (    s7   /usr/local/lib/python2.7/dist-packages/PIL/PdfParser.pyt   __repr__   s    c         C   s   |  t  j |   S(   N(   t	   PdfParsert   interpret_name(   t   clst   data(    (    s7   /usr/local/lib/python2.7/dist-packages/PIL/PdfParser.pyt   from_pdf_stream   s    i!   i   c         c   s   |  ] } t  |  Vq d  S(   N(   R   (   R   t   c(    (    s7   /usr/local/lib/python2.7/dist-packages/PIL/PdfParser.pys	   <genexpr>   s    s   #%/()<>[]{}c         C   s   t  d  } x |  j D] } t r[ | |  j k rA | j |  q | j t d |   q t |  |  j k r | j |  q | j d t |   q Wt |  S(   Nt   /s   #%02X(	   t	   bytearrayRM   R    t   allowed_charst   appendt   extendR   R   RN   (   R    t   resultR   (    (    s7   /usr/local/lib/python2.7/dist-packages/PIL/PdfParser.pyR"      s    (   R   R   R0   RO   R%   R(   RQ   t   classmethodRV   R:   t   rangeRZ   R"   R!   (    (    (    s7   /usr/local/lib/python2.7/dist-packages/PIL/PdfParser.pyRK      s   					)	t   PdfArrayc           B   s   e  Z d    Z e Z RS(   c         C   s   d d j  d   |  D  d S(   Ns   [ t    c         s   s   |  ] } t  |  Vq d  S(   N(   t   pdf_repr(   R   t   x(    (    s7   /usr/local/lib/python2.7/dist-packages/PIL/PdfParser.pys	   <genexpr>  s    s    ](   R   (   R    (    (    s7   /usr/local/lib/python2.7/dist-packages/PIL/PdfParser.pyR"     s    (   R   R   R"   R!   (    (    (    s7   /usr/local/lib/python2.7/dist-packages/PIL/PdfParser.pyR`     s   	t   PdfDictc           B   s2   e  Z d    Z d   Z d   Z e s0 e Z n  RS(   c         C   sX   | d k rA t  t d  r1 t j |  | |  qT | |  j | <n | |  | j d  <d  S(   NRU   t   __setattr__s   us-ascii(   t   hasattrR   Re   t   __dict__R   (   R    R1   R2   (    (    s7   /usr/local/lib/python2.7/dist-packages/PIL/PdfParser.pyRe     s
    c         C   sq  y |  | j  d  } Wn t k
 r6 t |   n Xt | t  rU t |  } n  | j d  rm| j d  r | d } n  d } t |  d k r | d } t	 | d d ! d	 } t |  d
 k r | t	 | d d
 ! 7} q n  d t |  d  } t
 j | t |  d  |  } | d k rm| d	 9} | d k rK| d 9} n  t
 j t j |  |  } qmn  | S(   Ns   us-asciit   Dates   D:i   t   Zi   i   i   i<   i   i   s   %Y%m%d%H%M%St   +t   -i(   Rj   Rk   (   R   R4   t   AttributeErrorRL   RN   R   t   endswitht
   startswithR   t   intt   timet   strptimet   gmtimet   calendart   timegm(   R    R1   R2   t   relationshipt   offsett   format(    (    s7   /usr/local/lib/python2.7/dist-packages/PIL/PdfParser.pyt   __getattr__  s.    
 
"c         C   s   t  d  } xx |  j   D]j \ } } | d  k r7 q n  t |  } | j d  | j t t |    | j d  | j |  q W| j d  t |  S(   Ns   <<s   
Ra   s   
>>(   RY   t   itemsR@   Rb   R\   RN   RK   (   R    t   outR1   R2   (    (    s7   /usr/local/lib/python2.7/dist-packages/PIL/PdfParser.pyR"   :  s    (   R   R   Re   Rx   R"   R    R!   (    (    (    s7   /usr/local/lib/python2.7/dist-packages/PIL/PdfParser.pyRd     s
   				t	   PdfBinaryc           B   s,   e  Z d    Z e r! d   Z n	 d   Z RS(   c         C   s   | |  _  d  S(   N(   RU   (   R    RU   (    (    s7   /usr/local/lib/python2.7/dist-packages/PIL/PdfParser.pyR0   L  s    c         C   s$   t  d d j d   |  j D   S(   Ns   <%s>R	   c         s   s   |  ] } d  | Vq d S(   s   %02XN(    (   R   R   (    (    s7   /usr/local/lib/python2.7/dist-packages/PIL/PdfParser.pys	   <genexpr>R  s    (   R   R   RU   (   R    (    (    s7   /usr/local/lib/python2.7/dist-packages/PIL/PdfParser.pyR"   Q  s    c         C   s   d d j  d   |  j D  S(   Ns   <%s>R	   c         s   s   |  ] } d  t  |  Vq d S(   s   %02XN(   R   (   R   R   (    (    s7   /usr/local/lib/python2.7/dist-packages/PIL/PdfParser.pys	   <genexpr>W  s    (   R   RU   (   R    (    (    s7   /usr/local/lib/python2.7/dist-packages/PIL/PdfParser.pyR!   V  s    (   R   R   R0   R    R"   R!   (    (    (    s7   /usr/local/lib/python2.7/dist-packages/PIL/PdfParser.pyR{   K  s   	t	   PdfStreamc           B   s   e  Z d    Z d   Z RS(   c         C   s   | |  _  | |  _ d  S(   N(   t
   dictionaryt   buf(   R    R}   R~   (    (    s7   /usr/local/lib/python2.7/dist-packages/PIL/PdfParser.pyR0   [  s    	c         C   s   y |  j  j } Wn t k
 r' |  j SX| d k r y |  j  j } Wn t k
 rc |  j  j } n Xt j |  j d t |  St	 d t
 |  j  j    d  S(   Nt   FlateDecodet   bufsizes$   stream filter %s unknown/unsupported(   R}   t   FilterRl   R~   t   DLt   Lengtht   zlibt
   decompressRo   t   NotImplementedErrorRP   (   R    t   filtert   expected_length(    (    s7   /usr/local/lib/python2.7/dist-packages/PIL/PdfParser.pyR   _  s    (   R   R   R0   R   (    (    (    s7   /usr/local/lib/python2.7/dist-packages/PIL/PdfParser.pyR|   Z  s   	c         C   s  |  t  k r d S|  t k r  d S|  d  k r0 d St |  t t t t f  rU t |   St |  t	  rw t
 |   j d  St |  t j  r d t j d |   j d  d St |  t  r t t |    St |  t  r t t |    St r t |  t
  st r#t |  t  r#t t |    St |  t  rt|  j d d	  }  |  j d
 d  }  |  j d d  }  d
 |  d St |   Sd  S(   Nt   truet   falset   nulls   us-asciis   (D:s   %Y%m%d%H%M%SZt   )s   \s   \\t   (s   \(s   \)(   t   TrueR.   R@   RL   RK   Rd   R`   R{   RN   Ro   R7   R   Rp   t   struct_timet   strftimet   dictt   listR    t   unicodeRb   R   t   replace(   Rc   (    (    s7   /usr/local/lib/python2.7/dist-packages/PIL/PdfParser.pyRb   p  s2    
!RR   c           B   s  e  Z d  Z dS dS dS d d d  Z d   Z d   Z d   Z d   Z d   Z	 d	   Z
 d
   Z d   Z d   Z d   Z dS d  Z d   Z d   Z d   Z e d    Z d   Z dS d  Z d Z d Z d Z d Z e d Z e d Z d Z e e e Z e j  e d e d e d e d e d  e d! e j!  Z" e j  e d e d" e d e d e d  e e j!  Z# d#   Z$ d$   Z% e j  e  Z& e j  e d% e d&  Z' e j  e d'  Z( e j  e d( e  Z) e* d)    Z+ e j  d*  Z, e* e- d+   Z. e j  e d, e d&  Z/ e j  e d- e d&  Z0 e j  e d. e d&  Z1 e j  e d/ e d&  Z2 e j  e d0 e d&  Z3 e j  e d1  Z4 e j  e d2  Z5 e j  e d3 e d4  Z6 e j  e d5  Z7 e j  e d6 e d6 e d7 e d&  Z8 e j  e d6 e d6 e d8 e d&  Z9 e j  e d9 e d&  Z: e j  d: e d; e d<  Z; e j  e d=  Z< e j  e d> e d&  Z= e* dS d? d@   Z> e j  dA  Z? i dB dC 6dD dE 6dF dG 6dH dI 6dJ dK 6d: d: 6d& d& 6dL dL 6dB e@ dC  6dD e@ dE  6dF e@ dG  6dH e@ dI  6dJ e@ dK  6d: e@ d:  6d& e@ d&  6dL e@ dL  6ZA e* dM    ZB e j  e dN e  ZC e j  e d e d e e  ZD e j  dO  ZE dP   ZF d? dQ  ZG dS dR  ZH RS(T   s|   Based on
    https://www.adobe.com/content/dam/acom/en/devnet/acrobat/pdfs/PDF32000_2008.pdf
    Supports PDF up to 1.4
    i    t   rbc         C   s  | r | r t  d   n  | |  _ | |  _ | |  _ | |  _ t |  _ t |  _ | d  k	 r | d  k r t	 | |  |  _ } t
 |  _ n  | d  k	 r |  j |  |  _ } t
 |  _ | r t | d  r | j |  _ q n  i  |  _ | r |  j   n| d |  _ |  _ t   |  _ d  |  _ t   |  _ d  |  _ i  |  _ g  |  _ g  |  _ d  |  _ d  |  _ i  |  _ t   |  _ t
 |  j _ | r|  j    n  d  S(   Ns4   specify buf or f or filename, but not both buf and fRM   i    (!   t   RuntimeErrort   filenameR~   RC   t   start_offsetR.   t   should_close_buft   should_close_fileR@   t   openR   t   get_buf_from_fileRf   RM   t   cached_objectst   read_pdf_infot   file_size_totalt   file_size_thisRd   t   roott   root_reft   infot   info_reft   page_tree_roott   pagest
   orig_pagest	   pages_reft   last_xref_section_offsett   trailer_dictR*   t
   xref_tableR/   t   seek_end(   R    R   RC   R~   R   t   mode(    (    s7   /usr/local/lib/python2.7/dist-packages/PIL/PdfParser.pyR0     sD    																c         C   s   |  S(   N(    (   R    (    (    s7   /usr/local/lib/python2.7/dist-packages/PIL/PdfParser.pyt	   __enter__  s    c         C   s   |  j    t S(   N(   t   closeR.   (   R    t   exc_typet	   exc_valuet	   traceback(    (    s7   /usr/local/lib/python2.7/dist-packages/PIL/PdfParser.pyt   __exit__  s    
c         C   s   |  j    |  j   d  S(   N(   t	   close_bufR   (   R    (    (    s7   /usr/local/lib/python2.7/dist-packages/PIL/PdfParser.pyt   start_writing  s    
c         C   s2   y |  j  j   Wn t k
 r$ n Xd  |  _  d  S(   N(   R~   R   Rl   R@   (   R    (    (    s7   /usr/local/lib/python2.7/dist-packages/PIL/PdfParser.pyR     s
    c         C   sK   |  j  r |  j   n  |  j d  k	 rG |  j rG |  j j   d  |  _ n  d  S(   N(   R   R   RC   R@   R   R   (   R    (    (    s7   /usr/local/lib/python2.7/dist-packages/PIL/PdfParser.pyR     s
    	c         C   s   |  j  j d t j  d  S(   Ni    (   RC   t   seekt   ost   SEEK_END(   R    (    (    s7   /usr/local/lib/python2.7/dist-packages/PIL/PdfParser.pyR     s    c         C   s   |  j  j d  d  S(   Ns	   %PDF-1.4
(   RC   R?   (   R    (    (    s7   /usr/local/lib/python2.7/dist-packages/PIL/PdfParser.pyt   write_header  s    c         C   s$   |  j  j d | f j d   d  S(   Ns   %% %s
s   utf-8(   RC   R?   R   (   R    R   (    (    s7   /usr/local/lib/python2.7/dist-packages/PIL/PdfParser.pyt   write_comment  s    c         C   s   |  j    |  j |  j j    |  _ |  j d  |  _ |  j   |  j |  j d t d  d |  j |  j |  j d t d  d t	 |  j
  d |  j
 |  j S(   Ni    t   Typet   Catalogt   Pagest   Countt   Kids(   t   del_roott   next_object_idRC   R>   R   R   t   rewrite_pagest	   write_objRK   R   R   (   R    (    (    s7   /usr/local/lib/python2.7/dist-packages/PIL/PdfParser.pyt   write_catalog  s    

%	
c         C   sf  g  } x t  |  j  D] \ } } |  j | } |  j | j =| j | t d   | |  j k rh q n  i  } x* | j   D] \ } } | | | j	   <q{ W|  j
 | d <|  j d  |  } x9 t  |  j  D]( \ }	 }
 |
 | k r | |  j |	 <q q Wq Wx\ | D]T } xK | rT|  j | } | j |  j k r?|  j | j =n  | j d d   } q
WqWg  |  _ d  S(   Nt   Parent(   RA   R   R   R   R   R[   RK   R   Ry   RO   R   t
   write_pageR@   R   (   R    t   pages_tree_nodes_to_deletet   it   page_reft	   page_infot   stringified_page_infoR1   R2   t   new_page_reft   jt   cur_page_reft   pages_tree_node_reft   pages_tree_node(    (    s7   /usr/local/lib/python2.7/dist-packages/PIL/PdfParser.pyR     s,    	c         C   s   | r |  j    | |  _ n  |  j r@ |  j d  |  j  |  _ n  |  j j |  j  } t	 |  j  } i |  j d 6| d 6} |  j
 d  k	 r |  j
 | d <n  |  j r |  j | d <n  | |  _
 |  j j d t t |   t d |   d  S(   Nt   Roott   Sizet   Prevt   Infos   trailer
s   
startxref
%d
%%%%EOF(   R   R   R   R   R@   R   R   R?   RC   R   R   RN   Rd   R   (   R    t   new_root_reft
   start_xreft   num_entriesR   (    (    s7   /usr/local/lib/python2.7/dist-packages/PIL/PdfParser.pyt   write_xref_and_trailer  s    
				c         O   sm   t  | t  r |  j | } n  d | k r> t d  | d <n  d | k rZ |  j | d <n  |  j | | |  S(   NR   t   PageR   (   RL   Ro   R   RK   R   R   (   R    t   reft   objst   dict_obj(    (    s7   /usr/local/lib/python2.7/dist-packages/PIL/PdfParser.pyR     s    c         O   s  |  j  } | d  k r- |  j | j    } n | j   | j f |  j | j <| j t t	 |     | j
 d d   } | d  k	 r t |  | d <n  | r | j t |   n  x! | D] } | j t |   q W| d  k	 r| j d  | j |  | j d  n  | j d  | S(   Nt   streamR   s   stream
s   
endstream
s   endobj
(   RC   R@   R   R>   R   R   R   R?   RN   R)   RB   R   Rb   (   R    R   R   R   RC   R   t   obj(    (    s7   /usr/local/lib/python2.7/dist-packages/PIL/PdfParser.pyR   $  s$    	c         C   s;   |  j  d  k r d  S|  j |  j  j =|  j |  j d j =d  S(   NR   (   R   R@   R   R   R   (   R    (    (    s7   /usr/local/lib/python2.7/dist-packages/PIL/PdfParser.pyR   9  s    c         C   sn   t  |  d  r |  j   St  |  d  r2 |  j   Sy# t j |  j   d d t j SWn t k
 ri d SXd  S(   Nt	   getbuffert   getvaluei    t   accessR	   (   Rf   R   R   t   mmapt   filenot   ACCESS_READt
   ValueError(   RC   (    (    s7   /usr/local/lib/python2.7/dist-packages/PIL/PdfParser.pyR   ?  s    

#c         C   sY  t  |  j  |  _ |  j |  j |  _ |  j   |  j d |  _ |  j j d d   |  _
 t |  j |  j   |  _ |  j
 d  k r t   |  _ n t |  j |  j
   |  _ t d |  j k d  t |  j d d k d  t d |  j k d  t t |  j d t  d	  |  j d |  _ |  j |  j  |  _ |  j |  j  |  _ |  j |  _ d  S(
   NR   R   R   s   /Type missing in RootR   s   /Type in Root is not /CatalogR   s   /Pages missing in Roots+   /Pages in Root is not an indirect reference(   R   R~   R   R   R   t   read_trailerR   R   R   R@   R   Rd   t   read_indirectR   R   R   RL   R   R   R   t   linearize_page_treeR   R   (   R    (    (    s7   /usr/local/lib/python2.7/dist-packages/PIL/PdfParser.pyR   K  s(    
c         C   sr   y& t  t |  j j    d d  } Wn  t k
 rH t  d d  } n X| d  k	 rn | d f |  j | j <n  | S(   Ni   i    (   R   t   maxR   R;   R   R@   R   (   R    Rv   t	   reference(    (    s7   /usr/local/lib/python2.7/dist-packages/PIL/PdfParser.pyR   g  s    &s   [][()<>{}/%]s$   [][()<>{}/%\000\011\012\014\015\040]s   [\000\011\012\014\015\040]s#   [\000\011\012\014\015\0400-9a-fA-F]t   *Rj   s   [\r\n]+t   trailers   \<\<(.*\>\>)RE   s   ([0-9]+)s   %%EOFt   $s   \<\<(.*?\>\>)c         C   s  t  |  j  d } | |  j k  r. |  j } n  |  j j |  j |  } t | d  | } x2 | r | } |  j j |  j | j   d  } q\ W| s | } n  | j d  } t | j d   |  _	 |  j
 |  |  _ t   |  _ |  j d |  j	  d |  j k r|  j |  j d  n  d  S(   Ni @  s   trailer end not foundi   i   i   t   xref_section_offsetR   (   R   R~   R   t   re_trailer_endt   searchR   t   startt   groupRo   R   t   interpret_trailerR   R*   R   t   read_xref_tablet   read_prev_trailer(   R    t   search_start_offsett   mt
   last_matcht   trailer_data(    (    s7   /usr/local/lib/python2.7/dist-packages/PIL/PdfParser.pyR     s$    	&	c         C   s   |  j  d |  } |  j j |  j | | d ! } t | d  | j d  } t t | j d   | k d  |  j |  } d | k r |  j | d  n  d  S(   NR   i @  s   previous trailer not foundi   i   sG   xref section offset in previous trailer doesn't match what was expectedR   (	   R   t   re_trailer_prevR   R~   R   R   Ro   R   R   (   R    R   t   trailer_offsetR   R   R   (    (    s7   /usr/local/lib/python2.7/dist-packages/PIL/PdfParser.pyR     s    	s   /([!-$&'*-.0-;=?-Z\\^-z|~]+)(?=R   s   \<\<s   \>\>c         C   s  i  } d } x t  r |  j j | |  } | s| |  j j | |  } t | oc | j   t |  k d t | |   Pn  |  j | j	 d   } |  j
 | | j    \ } } | | | <q Wt d | k o t | d t  d  t d | k ot | d t  d  | S(   Ni    s+   name not found in trailer, remaining data: i   R   s&   /Size not in trailer or not an integerR   s1   /Root not in trailer or not an indirect reference(   R   t   re_namet   matcht   re_dict_endR   t   endR   RP   RS   R   t	   get_valueRL   Ro   R   (   RT   R   R   Rv   R   R1   R2   (    (    s7   /usr/local/lib/python2.7/dist-packages/PIL/PdfParser.pyR     s*    	s   ([^#]*)(#([0-9a-fA-F]{2}))?c         C   s   d } xq |  j  j |  D]] } | j d  rc | | j d  t j | j d  j d   7} q | | j d  7} q W| r | j d  St |  Sd  S(   NR	   i   i   s   us-asciis   utf-8(   t   re_hashes_in_namet   finditerR   RY   t   fromhexR   RN   (   RT   t   rawt   as_textRM   R   (    (    s7   /usr/local/lib/python2.7/dist-packages/PIL/PdfParser.pyRS     s    5s   null(?=s   true(?=s   false(?=s   ([-+]?[0-9]+)(?=s)   ([-+]?([0-9]+\.[0-9]*|[0-9]*\.[0-9]+))(?=s   \[t   ]s   \<(s   *)\>s   \(s   ([-+]?[0-9]+)s   R(?=s   obj(?=s	   endobj(?=R   s	   %[^\r\n]*s   )*s   stream\r?\ns   endstream(?=ic         C   s  | d k r d S|  j j | |  } | r: | j   } n  |  j j | |  } | rOt t | j d   d k d  t t | j d   d k d  t | d  k p | t t | j d   t | j d    k d  |  j	 | | j   d | d \ } } | d  k r| d  f S|  j
 j | |  } t | d  | | j   f St | d	  |  j j | |  } | rt t | j d   d k d
  t t | j d   d k d  t t | j d   t | j d    | j   f S|  j j | |  } | r| j   } i  } |  j j | |  } x | s|  j	 | | d | d \ } } | d  k rv| d  f S|  j	 | | d | d \ }	 } |	 | | <| d  k r| d  f S|  j j | |  } q8W| j   } |  j j | |  } | ry t | d  }
 Wn6 t t t f k
 rDt d | j d d     n X| | j   | j   |
 !} |  j j | | j   |
  } t | d  | j   } t t |  |  } n t |  } | | f S|  j j | |  } | r| j   } g  } |  j j | |  } xd | sp|  j	 | | d | d \ }	 } | j |	  | d  k rX| d  f S|  j j | |  } qW| | j   f S|  j j | |  } | rd  | j   f S|  j j | |  } | rt | j   f S|  j j | |  } | rt | j   f S|  j j | |  } | rEt  |  j! | j d    | j   f S|  j" j | |  } | rt | j d   | j   f S|  j# j | |  } | rt$ | j d   | j   f S|  j% j | |  } | rVt& g  | j d  D] } | d k r| ^ q } t' |  d d k r4| j t( d   n  t& j) | j* d   | j   f S|  j+ j | |  } | r|  j, | | j    St d t- | | | d !   d  S(   Ni    i   s<   indirect object definition: object ID must be greater than 0i   s;   indirect object definition: generation must be non-negatives2   indirect object definition different than expectedt   max_nestings(   indirect object definition end not founds$   indirect object definition not founds;   indirect object reference: object ID must be greater than 0s:   indirect object reference: generation must be non-negativeR   s)   bad or missing Length in stream dict (%r)s   stream end not foundt   0123456789abcdefABCDEFt   0s   us-asciis   unrecognized object: i    (   NN(.   R@   t
   re_commentR   R   t   re_indirect_def_startR   Ro   R   R   R   t   re_indirect_def_endt   re_indirect_referencet   re_dict_startR   t   re_stream_startt	   TypeErrorR4   R   R   R   t   re_stream_endR|   Rd   t   re_array_startt   re_array_endR[   t   re_nullt   re_trueR   t   re_falseR.   R   RK   RS   t   re_intt   re_realt   floatt   re_string_hexRY   R   R   R  R   t   re_string_litt   get_literal_stringRP   (   RT   RU   Rv   t   expect_indirectR  R   t   objectR]   R1   R2   t
   stream_lent   stream_dataR   t
   hex_string(    (    s7   /usr/local/lib/python2.7/dist-packages/PIL/PdfParser.pyR      s    -(
7	"
"


	"
(1"sF   (\\[nrtbf()\\])|(\\[0-9]{1,3})|(\\(\r\n|\r|\n))|(\r\n|\r|\n)|(\()|(\))s   
t   ns   t   rs   	t   ts   R   s   RC   s   \c         C   sr  d } t    } xP|  j j | |  D]9} | j | | | j   ! | j d  rx | j |  j | j d  d  n | j d  r | j t | j d  d d   n | j d  r n | j d  r | j d  nt | j d  r| j d	  | d 7} nK | j d
  rR| d k r8t	 |  | j
   f S| j d  | d 8} n  | j
   } q% Wt d   d  S(   Ni    i   i   i   i   i   s   
i   R   i   R   s   unfinished literal string(   RY   t   re_lit_str_tokenR  R\   R   R   t   escaped_charsR[   Ro   RN   R   R   (   RT   RU   Rv   t   nesting_depthR]   R   (    (    s7   /usr/local/lib/python2.7/dist-packages/PIL/PdfParser.pyR    s,    	$&t   xrefs+   ([0-9]{10}) ([0-9]{5}) ([fn])( \r| \n|\r\n)c         C   s  t  } |  j j |  j | |  j  } t | d  | j   } xHt r|  j j |  j |  } | sv t | d  Pn  t } | j   } t	 | j
 d   } t	 | j
 d   } x t | | |  D] } |  j j |  j |  } t | d  | j   } | j
 d  d k } t	 | j
 d   }	 | s t	 | j
 d   |	 f }
 t | |  j k pj|  j | |
 k d  |
 |  j | <q q WqA W| S(	   Ns   xref section start not founds   xref subsection start not foundi   i   s   xref entry not foundi   RC   s)   xref entry duplicated (and not identical)(   R.   t   re_xref_section_startR   R~   R   R   R   R   t   re_xref_subsection_startRo   R   R_   t   re_xref_entryR   (   R    R   t   subsection_foundR   Rv   t   first_objectt   num_objectsR   t   is_freeR   t	   new_entry(    (    s7   /usr/local/lib/python2.7/dist-packages/PIL/PdfParser.pyR     s8    		
c         C   s   |  j  | d \ } } t | | d k d | d | d | | f  |  j |  j | |  j d t |   d | d } | |  j | <| S(   Ni    i   sg   expected to find generation %s for object ID %s in xref table, instead found generation %s at offset %sR  R  (   R   R   R   R~   R   R   R   (   R    R   R  Rv   R   R2   (    (    s7   /usr/local/lib/python2.7/dist-packages/PIL/PdfParser.pyR     s    c         C   s   | d  k r |  j } n  t | d d k d  g  } xZ | d D]N } |  j |  } | d d k ru | j |  q@ | j |  j d |   q@ W| S(   NR   R   s%   /Type of page tree node is not /PagesR   R   t   node(   R@   R   R   R   R[   R\   R   (   R    R1  R   t   kidt
   kid_object(    (    s7   /usr/local/lib/python2.7/dist-packages/PIL/PdfParser.pyR     s    N(I   R   R   R   R@   R0   R   R   R   R   R   R   R   R   R   R   R   R   R   R   t   staticmethodR   R   R   t	   delimitert   delimiter_or_wst
   whitespacet   whitespace_or_hext   whitespace_optionalt   whitespace_mandatoryt   newline_onlyt   newlinet   ret   compilet   DOTALLR   R   R   R   t   re_whitespace_optionalR   R  R   R^   R   R  R.   RS   R  R  R  R  R  R  R  R  R  R  R  R  R
  R  R  R   R%  R   R&  R  R)  R*  R+  R   R   R   (    (    (    s7   /usr/local/lib/python2.7/dist-packages/PIL/PdfParser.pyRR     s   %															


/+		%%y		!(    (    (    (    (    (   Rs   R   t   collectionsR   R   R=  Rp   R   t   _utilR    R   t   ImportErrorR   R   R
   R   R   R   R   t
   namedtupleR   R)   R*   RK   R   R`   Rd   R{   R|   Rb   RR   (    (    (    s7   /usr/local/lib/python2.7/dist-packages/PIL/PdfParser.pyt   <module>   s   		
			%]/6	