mò
	Zí>c           @   sÌ   d  Z  d d d !Z d d d !Z d d d !Z d k Z d k Z d k l Z d k Z d	 k	 l
 Z
 d
 Z d Z d f  d „  ƒ  YZ d k l Z e Z y e ƒ  Z e i e ƒ Wn d Ge i Gd GHn Xd S(   s:  
$RCSfile: LibXsltProcessor.py,v $

This class encapsulates an XSLT Processor for use by ZopeXMLMethods.
This is the GNOME libxslt version, including support for XSLT
parameters.  It does not yet include support for URN resolution.

Author: <a href="mailto:cstrong@arielpartners.com">Craeg Strong</a>
Release: 1.0
s	   $Name:  $i   iþÿÿÿs   $Date: 2003/06/16 05:47:53 $s   $Revision: 1.3 $i
   N(   s   aq_get(   s   IXSLTProcessort   URNnamespacest
   XMLcatalogt   LibXsltProcessorc           B   sY   t  Z d  Z e Z d Z d „  Z d „  Z e h  e d „ Z	 d „  Z
 d „  Z d „  Z RS(   sÛ   
    
    This class encapsulates an XSLT Processor for use by ZopeXMLMethods.
    This is the GNOME libxslt version, including support for XSLT
    parameters.  It does not yet include support for URN resolution.

    s   libxslt 1.0.27c         C   sM   d |  _ t i |  i d ƒ t i |  i d ƒ t i d ƒ t i d ƒ d S(   s-   Initialize a new instance of LibXsltProcessori    t    i   N(   t   selft
   debugLevelt   libxml2t   registerErrorHandlert   errorHandlert   libxsltt   lineNumbersDefaultt   substituteEntitiesDefault(   R   (    (    t   processors/LibXsltProcessor.pyt   __init__4   s     	c         C   s   | |  _ d S(   s‹   

        Set debug level from 0 to 3.
        0 = silent
        3 = extra verbose
        Debug messages go to Zope server log.

        N(   t   levelR   R   (   R   R   (    (    R   t   setDebugLevelB   s     c         C   s  |  i d j o d G| GHn |  i d j o d GH| GHd GH| GHn h  } x- | i ƒ  D] \ } } |  i	 | | | ƒ qX Wy  t
 i | ƒ }
 |
 i | ƒ Wn: t
 i j
 o+ } d | t | ƒ f }	 t |	 ƒ ‚ n Xt i |
 ƒ } y  t
 i | ƒ } | i | ƒ Wn4 t
 i j
 o% } d t | ƒ }	 t |	 ƒ ‚ n X| i | | ƒ } | i | ƒ } | i ƒ  | i ƒ  | i ƒ  | S(   sº  

        Transforms the passed in XML into the required output (usually
        HTML) using the passed in XSLT.  Both the XML and XSLT strings
        should be well-formed.  Returns the output as a string.
        transformObject and REQUEST params may be used to acquire Zope
        content such as XSLT parameters and URN namespaces, if
        required.

        Catches any libxslt specific exceptions and raises an Exception

        i   s   params:s   xsltContents:s   xmlContents:s$   XML parse error for XSLT file %s: %ss$   XML parse error for XML document: %sN(   R   R   t   paramst   xsltContentst   xmlContentst
   xsltParamst   itemst   keyt   valuet   addParamR   t   parseDoct   styleDoct   setBaset   xsltURLt   parserErrort   et   strt   messaget	   ExceptionR	   t   parseStylesheetDoct   stylet   xmlDoct   xmlURLt   applyStylesheett	   resultDoct   saveResultToStringt   resultt   freeStylesheett   freeDoc(   R   R   R$   R   R   t   transformObjectR   t   REQUESTR(   R   R   R"   R&   R   R#   R   R   R   (    (    R   t	   transformQ   s>     	 


c         C   s   d | | | <| S(   sÃ   

        This is a convenience function for adding parameters in the
        correct format to the parameter map to be used for the
        'params' parameter in transformGuts.
        
        s   '%s'N(   R   t   paramMapt   name(   R   R.   R/   R   (    (    R   R   œ   s     c         C   s   t  | ƒ ‚ d S(   s™   
        
        The default error handler for libxml2 and libxslt prints out
        messages to stderr.  Throw an exception instead.
        
        N(   R    t   error(   R   t   ctxR0   (    (    R   R   Ä   s     c         C   s{   t  | t d ƒ } h  } | d j	 oR xO | D]C } t  | | d ƒ } t | ƒ o | | | <q, t	 | ƒ | | <q, Wn | S(   sC   

        retrieves Namespaces defined for URI Resolution

        N(
   t   aq_getR+   t   namespacesPropertyNamet   Nonet   NIDsR(   t   nR   t   callableR   (   R   R+   R   R6   R5   R(   (    (    R   t   retrieveNamespacesÑ   s      (   t   __name__t
   __module__t   __doc__t   IXSLTProcessort   __implements__R/   R   R   R4   R-   R   R   R8   (    (    (    R   R   (   s    		K	(	(   s   ProcessorRegistryt	   Processors)   not available for use with ZopeXMLMethods(   R;   t
   __cvstag__t   __date__t   __version__R   R	   t   AcquisitionR2   t   syst
   interfacesR<   R3   t   catalogPropertyNameR   t   ProcessorRegistryt   klasst   proct   registerR/   (   R<   R@   R3   R2   R   R   RE   R?   RC   RG   RF   R	   RA   RH   (    (    R   t   ?
   s$   			À	