Ñò
ÝT~Kc           @   s(   d  d k  Z  d „  Z d h  d „ Z d S(   iÿÿÿÿNc         C   s¬   t  |  ƒ t j o |  i d ƒ }  n | i d ƒ o |  i d d ƒ n |  i d ƒ d j  o d |  d S|  i d ƒ d j  o d |  d Sd |  i d | ƒ d Sd S(   s8    quote a string so that it can be passed as a parameter s   utf-8s   \s   \\t   'i    t   "N(   t   typet   unicodet   encodet
   startswitht   replacet   find(   t   stringt   apos(    (    s#   /net/bzr/venus/planet/shell/xslt.pyt   quote   s     c         C   sî  y1 d d k  } d d k } | i | ƒ } d } Wn d } n Xd } | o¦ | i |  ƒ }	 | i |	 ƒ }
 x. | i ƒ  D]  } t | | d d ƒ| | <qy W|
 i | | ƒ } | o |
 i	 | | d ƒ n | i
 d ƒ } |
 i ƒ  | i ƒ  nâ| od d k } t | d ƒ o | i d t ƒ n t i ƒ  } t | d	 ƒ } | i | ƒ | i ƒ  g  } xl | i ƒ  D]^ \ } } | i d
 ƒ d j o | i d ƒ d j o qpn | d | t | d d ƒg 7} qpWt i d d i | ƒ |  | | f ƒ t i | ƒ nÍ d d k } d d k l } l } t g  } | i ƒ  D] \ } } | d | | g q?~ g  ƒ } | d g | |  d g d | d | d | ƒ} | i  | ƒ \ } } | o  d d k! } | i" i# | ƒ n | o | i ƒ  n | S(   s    process an XSLT stylesheet iÿÿÿÿNR	   s   â€™i    s   utf-8t   simplefiltert   ignoret   wR    R   s   --stringparams   \'s   xsltproc %s %s %s > %st    (   t   Popent   PIPEt   xsltproct   -t   stdint   stdoutt   stderr($   t   libxml2t   libxsltt   parseDoct   Nonet	   parseFilet   parseStylesheetDoct   keysR
   t   applyStylesheett   saveResultToFilenamet	   serializet   freeStylesheett   freeDoct   warningst   hasattrR   t   RuntimeWarningt   ost   tmpnamt   opent   writet   closet   itemsR   t   systemt   joint   unlinkt   syst
   subprocessR   R   t   sumt   communicatet   planett   loggert   error(   t   scriptt   doct   output_filet   optionsR   R   t   domt   docfilet   resultt   styledoct   stylet   keyt   outputR"   t   filet   cmdoptst   valueR.   R   R   t   _[1]t   procR   R2   (    (    s#   /net/bzr/venus/planet/shell/xslt.pyt   run   sd    

 

 , #	
5 (   R%   R
   R   RE   (    (    (    s#   /net/bzr/venus/planet/shell/xslt.pyt   <module>   s   	
