;
0sDc           @   s	  d  Z  d Z d k Z d k l Z d k l Z l Z l Z l	 Z	 d k
 l Z l Z d Z g  d d  Z h  d	 d	 <d
 d
 <d d <Z e d  Z d e d  Z d   Z d   Z y d k l Z l Z e Z Wn#e j
 oy d k l Z l Z e Z Wqe j
 o e Z e i d j o h  Z x e d d  D] Z e d j  p
 e d j o d e e e e  <q?e e  d  e  d  e  d  f j o d e e  e e e  <q?e e  e e e  <q?W[ d   Z qd   Z qXn Xe d  Z! d   Z" d   Z# n o d!   Z$ d"   Z% n y d# k l& Z& Wn@ e j
 o4 y d# k l& Z& Wqe j
 o e$ Z& qXn Xy d$ k l' Z' Wn@ e j
 o4 y d$ k l' Z' Wqe j
 o e% Z' qXn Xd d%  Z( d&   Z) d' f  d(     YZ* d S()   s7    $Id: pdfutils.py 2765 2006-02-02 18:48:12Z rgbecker $ s    N(   s	   rl_config(   s   joins   replaces   strips   split(   s   getStringIOs   ImageReaders   
i<   c         C   sC   x8 t  d t |   |  D] } | i |  | | | ! q W| Sd  S(   Ni    (   s   xranges   lens   srcs	   chunkSizes   is   dsts   append(   s   srcs   dsts	   chunkSizes   i(    (    sD   /home/packages/reportlab/reportlab_2_0/reportlab/pdfbase/pdfutils.pys   _chunker   s     s   RGBs   CMYKs   Ls   Gc         C   s   d  k  } t |   } | t j	 o | i |  n | i   \ } }	 | i
   } g  } | i }
 |
 d  |
 d | |	 t | i f  |
 d  t |  | |	 j d f p t  | i |  } t |  } t | |  |
 d  | Sd  S(   Ns   BIs(   /W %s /H %s /BPC 8 /CS /%s /F [/A85 /Fl]s   IDs   Wrong amount of data for images   EI(   s   zlibs   ImageReaders   filenames   imgs   IMGs   Nones   appends   getSizes   imgwidths	   imgheights
   getRGBDatas   raws   codes   _mode2css   modes   lens   AssertionErrors   compresss
   compresseds   _AsciiBase85Encodes   encodeds   _chunker(   s   filenames   IMGs   imgwidths   imgs   raws   zlibs   codes
   compresseds   encodeds	   imgheights   append(    (    sD   /home/packages/reportlab/reportlab_2_0/reportlab/pdfbase/pdfutils.pys   makeA85Image   s"    	 	

$
i    c         C   s   t  i i |   d d } |  | j oW t |   o9 d k l } | o! t	 | |  i
   t  d  Sqz q t d |   ni t |  |  } | o | Sn t | d  } | i t | t  t  | i   t i o d | GHn d S(	   sH   Processes image as if for encoding, saves to a file with .a85 extension.i    s   .a85(   s   open_for_readis   No such cached image %ss   wbs   cached image as %sN(   s   oss   paths   splitexts   filenames
   cachednames   cachedImageExistss   reportlab.lib.utilss   open_for_reads   returnInMemorys   splits   reads   LINEENDs   IOErrors   makeA85Images   IMGs   codes   opens   fs   writes   joins   closes	   rl_configs   verbose(   s   filenames   returnInMemorys   IMGs   open_for_reads   codes   fs
   cachedname(    (    sD   /home/packages/reportlab/reportlab_2_0/reportlab/pdfbase/pdfutils.pys   cacheImageFile7   s       % 

c         C   s   d k  } d k } t |   | i j o | i |   } n |  } x@ | D]8 } t |  o t i	 o d | GHq qH t
 |  qH Wd S(   s   Preprocesses one or more image files.

    Accepts either a filespec ('C:\mydir\*.jpg') or a list
    of image filenames, crunches them all to save time.  Run this
    to save huge amounts of time when repeatedly building image
    documents.Ns#   cached version of %s already exists(   s   typess   globs   types   specs
   StringTypes   filelists   filenames   cachedImageExistss	   rl_configs   verboses   cacheImageFile(   s   specs   globs   filelists   filenames   types(    (    sD   /home/packages/reportlab/reportlab_2_0/reportlab/pdfbase/pdfutils.pys   preProcessImagesM   s      
c         C   sx   t  i i |   d d } t  i i |  oC t  i |   d } t  i |  d } | | j o d Sqt d Sn d Sd S(   s   Determines if a cached image already exists for a given file.

    Determines if a cached image exists which has the same name
    and equal or newer date to the given file.i    s   .a85i   i   N(	   s   oss   paths   splitexts   filenames
   cachednames   isfiles   stats   original_dates   cached_date(   s   filenames
   cachednames   cached_dates   original_date(    (    sD   /home/packages/reportlab/reportlab_2_0/reportlab/pdfbase/pdfutils.pys   cachedImageExistsd   s     (   s	   escapePDFs   _instanceEscapePDFs   2.1i   i    i   s   \%03os   \s   (s   )c         C   s    t  t t d  |   d  Sd  S(   Nc         C   s   | |  S(   N(   s   ds   c(   s   cs   d(    (    sD   /home/packages/reportlab/reportlab_2_0/reportlab/pdfbase/pdfutils.pys   <lambda>   s    s    (   s   joins   maps   _ESCAPEDICTs   s(   s   s(    (    sD   /home/packages/reportlab/reportlab_2_0/reportlab/pdfbase/pdfutils.pys   _escape   s    c         C   s?   t  |   d d !}  t |  d d  }  t |  d d  }  |  Sd S(   s   Escapes some PDF symbols (in fact, parenthesis).
                PDF escapes are almost like Python ones, but brackets
                need slashes before them too. Uses Python's repr function
                and chops off the quotes first.i   is   (s   \(s   )s   \)N(   s   reprs   ss   replace(   s   s(    (    sD   /home/packages/reportlab/reportlab_2_0/reportlab/pdfbase/pdfutils.pys   _escape   s
     c         C   sV   d } t |  d |  }  t |  d |  }  t |  d |  }  t |  | |  }  |  Sd S(   sz   Normalizes different line end character(s).

    Ensures all instances of CR, LF and CRLF end up as
    the specified one.s    s   
s   s   
N(   s   unlikelys   replaces   texts   desired(   s   texts   desireds   unlikely(    (    sD   /home/packages/reportlab/reportlab_2_0/reportlab/pdfbase/pdfutils.pys   _normalizeLineEnds   s     c         C   sL   t    } x% |  D] } | i d t |   q W| i d  | i   Sd S(   s   Encodes input using ASCII-Hex coding.

    This is a verbose encoding used for binary data within
    a PDF file.  One byte binary becomes two bytes of ASCII.
    Helper function used by images.s   %02xs   >N(   s   getStringIOs   outputs   inputs   chars   writes   ords   getvalue(   s   inputs   chars   output(    (    sD   /home/packages/reportlab/reportlab_2_0/reportlab/pdfbase/pdfutils.pys   _AsciiHexEncode   s     	 c         C   s   t  t |   d  } | d d j p
 t d  | d  } t |  d d j p
 t d  d } t   } xP | t |  j  o< | | | d !} | i
 t t d |    | d } qm W| i   Sd	 S(
   se   Decodes input using ASCII-Hex coding.

    Not used except to provide a test of the inverse function.s    is   >s'   Invalid terminator for Ascii Hex Streami   i    s(   Ascii Hex stream has odd number of bytess   0xN(   s   joins   splits   inputs   strippeds   AssertionErrors   lens   is   getStringIOs   outputs   twobytess   writes   chrs   evals   getvalue(   s   inputs   is   strippeds   outputs   twobytes(    (    sD   /home/packages/reportlab/reportlab_2_0/reportlab/pdfbase/pdfutils.pys   _AsciiHexDecode   s     
!	 i   c         C   s  t    }	 t t |   d  \ } } d | } |  d | !|  | f \ } }
 xt
 |  D]} | d } t | |  } t | | d  } t | | d  } t | | d  } | d j  o" | d >| Bd >| Bd >| B} n d | d	 | d
 | | } | d j o |	 i d  qX t | d  \ } } t | d  \ } } t | d  \ } } t | d  \ } } d d | d d | d d | d | | | j p
 t d  |	 i t | d   |	 i t | d   |	 i t | d   |	 i t | d   |	 i t | d   qX W| d j o;x" t |
  d j  o |
 d }
 q=Wt |
 d  } t |
 d  } t |
 d  } t |
 d  } d | d	 | d
 | | } t | d  \ } } t | d  \ } } t | d  \ } } t | d  \ } } t | d  t | d  t | d  t | d  t | d  } |	 i | d | d ! n |	 i d  |	 i   Sd S(   s   Encodes input using ASCII-Base85 coding.

        This is a compact encoding used for binary data within
        a PDF file.  Four bytes of binary data become five bytes of
        ASCII.  This is the default method used for encoding images.i   i    i   i   i   i   i   l      i   i   s   ziU   s   dodgy code!i!   s    s   ~>N(   s   getStringIOs	   outstreams   divmods   lens   inputs   whole_word_counts   remainder_sizes   cuts   bodys   lastbits   ranges   is   offsets   ords   b1s   b2s   b3s   b4s   nums   writes   temps   c5s   c4s   c3s   c1s   c2s   AssertionErrors   chrs   lastwords   getvalue(   s   inputs   b4s   c3s   nums   b1s   b2s   b3s   c1s   cuts	   outstreams   lastbits   bodys   lastwords   offsets   whole_word_counts   c2s   c5s   c4s   temps   is   remainder_size(    (    sD   /home/packages/reportlab/reportlab_2_0/reportlab/pdfbase/pdfutils.pys   _AsciiBase85EncodePYTHON   sX     	
 
"C Hc         C   s  t    } t t |   d  } | d d j p
 t d  | d  } t | d d  } t t	 |  d  \ } } d | } | d | !| | f \ }
 }	 x~t |  D]p} | d } t |
 |  d	 } t |
 | d
  d	 } t |
 | d  d	 } t |
 | d  d	 } t |
 | d  d	 } d d | d d | d d | d | | } t | d  \ } } t | d  \ } } t | d  \ } } | d | d | d | | j p
 t d  | i t |   | i t |   | i t |   | i t |   q W| d j ox" t	 |	  d j  o |	 d }	 q(Wt |	 d  d	 } t |	 d
  d	 } t |	 d  d	 } t |	 d  d	 } t |	 d  d	 } d | | d | d | d | d d d d d f | } t | d  \ } } t | d  \ } } t | d  \ } } | d | d | d | | j p
 t d  | d j o t |  } n_ | d j o t |  t |  } n8 | d j o$ t |  t |  t |  } n d } | i |  n | i!   Sd S(   s   Decodes input using ASCII-Base85 coding.

        This is not used - Acrobat Reader decodes for you
        - but a round trip is essential for testing.s    is   ~>s+   Invalid terminator for Ascii Base 85 Streams   zs   !!!!!i   i    i!   i   i   i   i   l   U iU   i   i   i   s   dodgy code!s   !i i  i   N("   s   getStringIOs	   outstreams   joins   splits   inputs   strippeds   AssertionErrors   replaces   divmods   lens   whole_word_counts   remainder_sizes   cuts   bodys   lastbits   ranges   is   offsets   ords   c1s   c2s   c3s   c4s   c5s   nums   temps   b4s   b3s   b1s   b2s   writes   chrs   lastwords   getvalue(   s   inputs   strippeds   b4s   whole_word_counts   nums   b2s   b3s   cuts	   outstreams   lastbits   bodys   lastwords   offsets   c3s   c2s   c1s   c5s   c4s   temps   is   remainder_sizes   b1(    (    sD   /home/packages/reportlab/reportlab_2_0/reportlab/pdfbase/pdfutils.pys   _AsciiBase85DecodePYTHON  sb     	

 
2/ =/$(   s   _AsciiBase85Encode(   s   _AsciiBase85Decodec         C   st   g  } t |   } d } | | } x> | | j  o0 | i |  | | | ! | d } | | } q% Wt | t	  Sd S(   sC   Wraps input at a given column size by inserting LINEEND characters.i    i   N(
   s   outputs   lens   inputs   lengths   is   columnss   poss   appends   joins   LINEEND(   s   inputs   columnss   is   poss   lengths   output(    (    sD   /home/packages/reportlab/reportlab_2_0/reportlab/pdfbase/pdfutils.pys   _wrapn  s     
 
c         C   sM  d k  } d k l } d d d g } d d d d	 d
 d d d d d g
 } d d d d d d d d d d d g } d } x| o| i d |  i	 d   }
 |
 d d j o| i d |  i	 d   }
 |
 d | j o |  i d d  | i d |  i	 d   }
 |
 d d j o | d    n | i d! |  i	 d   }	 |	 d d >|	 d } | i d! |  i	 d   }	 |	 d d >|	 d } | i d |  i	 d   }	 |	 d } | | | f Sd } qD|
 d | j o | d" |
 d   qD|
 d | j oC | i d! |  i	 d   }
 |  i |
 d d >|
 d d d  qDqy qy Wd S(#   s@   Read width, height and number of components from open JPEG file.N(   s   PDFErrori   i   i   i   i   i   i   i   i   i   i   i   i   i   i   i   i   i   i   i   i   i   i   i   i    s   Bi   i   i   s#   JPEG must have 8 bits per components   BBs#   JPEG Unsupported JPEG marker: %0.2x(   s   structs   pdfdocs   PDFErrors   validMarkerss   noParamMarkerss   unsupportedMarkerss   dones   unpacks   images   reads   xs   seeks   ys   heights   widths   color(   s   images   structs   validMarkerss   colors   unsupportedMarkerss   heights   PDFErrors   widths   dones   ys   xs   noParamMarkers(    (    sD   /home/packages/reportlab/reportlab_2_0/reportlab/pdfbase/pdfutils.pys   readJPEGInfo  s<     	$' 

s   _fuscc           B   s5   t  Z d   Z d   Z d   Z d   Z d   Z RS(   Nc         C   sC   | p
 t d  | |  _ t |  |  _ t |  p d |  _ d  S(   Ns'   Argument k should be a non empty stringi   (	   s   ks   AssertionErrors   selfs   _ks   lens   _klens   ints   ns   _n(   s   selfs   ks   n(    (    sD   /home/packages/reportlab/reportlab_2_0/reportlab/pdfbase/pdfutils.pys   __init__  s    	c      	   C   sA   |  i t d i t t |  i t t |      |  i	  Sd  S(   Ns    (
   s   selfs   _fusc__rotates   _AsciiBase85Encodes   joins   maps   chrs   _fusc__fuscs   ords   ss   _n(   s   selfs   s(    (    sD   /home/packages/reportlab/reportlab_2_0/reportlab/pdfbase/pdfutils.pys   encrypt  s    c      
   C   sB   d i  t t |  i t t t |  i | |  i	       Sd  S(   Ns    (
   s   joins   maps   chrs   selfs   _fusc__fuscs   ords   _AsciiBase85Decodes   _fusc__rotates   ss   _n(   s   selfs   s(    (    sD   /home/packages/reportlab/reportlab_2_0/reportlab/pdfbase/pdfutils.pys   decrypt  s    c         C   sZ   t  |  } | d j  o | | } n | | ;} | o | Sn | | | | |  Sd  S(   Ni    (   s   lens   ss   ls   n(   s   selfs   ss   ns   l(    (    sD   /home/packages/reportlab/reportlab_2_0/reportlab/pdfbase/pdfutils.pys   __rotate  s     
 c         C   sH   t  |  } t d   | t t t | |  i  d |  i |    Sd  S(   Nc         C   s   |  | AS(   N(   s   xs   y(   s   xs   y(    (    sD   /home/packages/reportlab/reportlab_2_0/reportlab/pdfbase/pdfutils.pys   <lambda>  s    i   (	   s   lens   ss   slens   maps   ords   ints   selfs   _klens   _k(   s   selfs   ss   slen(    (    sD   /home/packages/reportlab/reportlab_2_0/reportlab/pdfbase/pdfutils.pys   __fusc  s    (   s   __name__s
   __module__s   __init__s   encrypts   decrypts   _fusc__rotates   _fusc__fusc(    (    (    sD   /home/packages/reportlab/reportlab_2_0/reportlab/pdfbase/pdfutils.pys   _fusc  s
   				(+   s   __version__s   __doc__s   oss	   reportlabs	   rl_configs   strings   joins   replaces   strips   splits   reportlab.lib.utilss   getStringIOs   ImageReaders   LINEENDs   _chunkers   _mode2css   Nones   makeA85Images   cacheImageFiles   preProcessImagess   cachedImageExistss	   _rl_accels	   escapePDFs   _instanceEscapePDFs   _escapes   ImportErrors   reportlab.lib._rl_accels   sys_versions   _ESCAPEDICTs   ranges   cs   chrs   ords   _normalizeLineEndss   _AsciiHexEncodes   _AsciiHexDecodes   _AsciiBase85EncodePYTHONs   _AsciiBase85DecodePYTHONs   _AsciiBase85Encodes   _AsciiBase85Decodes   _wraps   readJPEGInfos   _fusc(    s   _wraps   replaces   readJPEGInfos   strips   getStringIOs   _AsciiBase85DecodePYTHONs	   rl_configs   _AsciiBase85Decodes   splits   _AsciiBase85EncodePYTHONs   __version__s   __doc__s   _chunkers	   escapePDFs   _AsciiHexDecodes   _ESCAPEDICTs   _AsciiHexEncodes   _AsciiBase85Encodes   makeA85Images   _mode2css   _fuscs   _escapes   preProcessImagess   cs   joins   cacheImageFiles   _normalizeLineEndss   _instanceEscapePDFs   ImageReaders   cachedImageExistss   LINEENDs   os(    (    sD   /home/packages/reportlab/reportlab_2_0/reportlab/pdfbase/pdfutils.pys   ?   sp   	!		

 (
			GK	/