mò
	Zí>c           @   s_  d  Z  d d d !Z d d d !Z d d d !Z d k l Z d k l Z d	 k l	 Z	 d
 k
 l Z d k l Z d k l Z d k l Z d k Z d k Z d k Z d k l Z d Z d Z d f  d „  ƒ  YZ d f  d „  ƒ  YZ d e e f d „  ƒ  YZ d e e 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: FourSuite11Processor.py,v $

This class encapsulates an XSLT Processor for use by ZopeXMLMethods.
This is the 4Suite 0.11 version, including support for XSLT parameters
and URL/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
   (   s   xpath(   s	   Processor(   s   XsltException(   s   StylesheetReader(   s   PyExpatReader(   s   aq_get(   s   StringION(   s   IXSLTProcessort   URNnamespacest   XSLparameterst   FourSuite11Processorc           B   sP   t  Z d  Z e Z d Z d „  Z d „  Z e h  e d „ Z	 d „  Z
 d „  Z RS(   s°   
    This class encapsulates an XSLT Processor for use by
    ZopeXMLMethods This is the 4Suite 0.11 version, including support
    for XSLT parameters and URN resolution.
    s   4Suite-0.11.1c         C   s   d |  _ d S(   s1   Initialize a new instance of FourSuite11Processori    N(   t   selft
   debugLevel(   R   (    (    t"   processors/FourSuite11Processor.pyt   __init__6   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   setDebugLevel>   s     c         C   s•  |  i d j o d G| GHn |  i d j o d GH| GHd GH| GHn t | ƒ t d ƒ j o | i d ƒ } n t | ƒ t d ƒ j o | i d ƒ } n h  } x- | i ƒ  D] \ } } |  i | | | ƒ q° Wh  } | d j	 o |  i | ƒ } n |  i d j o d G| GHn |  i d j oI d k l } l }
 | i ƒ  } |  i d	 j o d | _ d | _ qxn
 t ƒ  } y„ | i t | | | g ƒ ƒ | i t | | ƒ ƒ | i | | ƒ | i | d
 | d | ƒ}	 |  i d j o d GH|	 GHd GHn Wn’ t! j
 o } t# t$ | ƒ ƒ ‚ nm t% i& t% i' f j
 oT } t( | d ƒ o) d | i) t$ | ƒ f } t# | ƒ ‚ q‘t# t$ | ƒ ƒ ‚ n X|	 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 4Suite specific exceptions and raises an Exception.

        i   s   params:s   xsltContents:s   xmlContents:u    t   utf8s   namespaces:(   s   ExtendedProcessingElementss   StylesheetReaderi   t   topLevelParamst   baseUris   ===Result===s   ============t   stylesheetUris   While processing %s
%sN(+   R   R   t   paramst   xsltContentst   xmlContentst   typet   encodet
   xsltParamst   itemst   keyt   valuet   addParamt   namespaceMapt   transformObjectt   Nonet   retrieveNamespacest   xml.xsltt   ExtendedProcessingElementst   StylesheetReadert   ExtendedProcessort	   processort   _4xslt_debugt   _4xslt_tracet	   Processort   setStylesheetReadert   StylesheetURIResolvert   REQUESTt   xsltURLt   setDocumentReadert   DocumentURIResolvert   appendStylesheetStringt	   runStringt   resultt   XsltExceptiont   et	   Exceptiont   strt   xpatht   RuntimeExceptiont   CompiletimeExceptiont   hasattrR   t   message(   R   R   t   xmlURLR   R&   R   R   R%   R   R+   R   R4   R   R   R-   R   R   R   (    (    R   t	   transformM   s^     	 			c         C   s   | | d | f <| 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.
        
        t    N(   R   t   paramMapt   name(   R   R8   R9   R   (    (    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   namespacesPropertyNameR   t   NIDsR+   t   nR   t   callableR/   (   R   R   R   R=   R<   R+   (    (    R   R   «   s      (   t   __name__t
   __module__t   __doc__t   IXSLTProcessort   __implements__R9   R   R   R   R6   R   R   (    (    (    R   R   ,   s    		O	t   URIResolverc           B   s)   t  Z d  Z d „  Z d „  Z d „  Z RS(   s9   Base class for both document and stylesheet URI resolversc         C   s   | |  _  d  S(   N(   R   R   (   R   R   (    (    R   R   Æ   s    c         C   sZ   | } | i d ƒ } x5 | D]- } t | | d ƒ } | d j o d Sq q W| | | ƒ S(   s   

        Obtain the contents of the Zope object indicated by the passed
        in context, starting from the passed in base object.

        t   /N(	   t   baset   zObjectt
   contextURLt   splitt   contextListt   contextR:   R   R%   (   R   RF   RH   R%   RJ   RK   RG   (    (    R   t   acquireObjectContentsÉ   s      c         C   s0   | i d ƒ } | d d j o t | ƒ d j S(   s3   Return true if this uri is of a format we recognizet   :i    t   urni   N(   t   uriRI   t   uriPartst   len(   R   RO   RP   (    (    R   t   isRecognizedURNß   s     (   R?   R@   RA   R   RL   RR   (    (    (    R   RD   Ã   s    		R$   c           B   s8   t  Z d  Z d „  Z d „  Z d e e d d d „ Z RS(   sJ   
    A wrapper for the 4suite stylesheet reader that understands URNs
    c         C   s9   t  i |  | ƒ t i |  d | ƒ| |  _ | |  _ d  S(   Nt   stylesheetIncPaths(   RD   R   R   R   R   RS   R%   t   req(   R   R   R%   RS   (    (    R   R   í   s    	c         C   s   |  i |  i |  i f S(   s”   
        Needed by BaseReader from PyExpat.  They clone the stylesheet
        reader for some reason and need to know how to call __init__
        N(   R   R   RT   RS   (   R   (    (    R   t   __getinitargs__ó   s     R7   i    c         C   s`  |  i | ƒ o-| i d ƒ } | d } | d } |  i i | d ƒ }	 |	 d j o# t i |  | | | | | | ƒ Sq\t |	 ƒ t i j o8 t i i |	 | ƒ } t i |  | | | | | | ƒ Sq\|  i |	 | |  i ƒ } | d j o# t i |  | | | | | | ƒ Sq\t | ƒ }
 t i |  |
 | | | | | ƒ Sn  t i |  | | | | | | ƒ Sd S(   s(    resolve URI for import or include call RM   i   i   N(   R   RR   RO   RI   RP   t   nidt   nssR   t   getR   RF   R   t   fromUriR   t   ownerDoct   stripElementst   importIndext   importDepthR   t   typest
   StringTypet   ost   patht   joint   resolvedURLRL   RT   t   stt   StringIOt   myStreamt
   fromStream(   R   RO   R   RZ   R[   R\   R]   RP   RV   RF   Rf   Rd   Rc   RW   (    (    R   RY   ú   s6     

(   R?   R@   RA   R   RU   R   RY   (    (    (    R   R$   è   s    		R(   c           B   s)   t  Z d  Z d „  Z d e e d „ Z RS(   sA   
    A wrapper for the document reader that understands URNs
    c         C   s*   t  i |  | ƒ t i |  ƒ | |  _ d  S(   N(   RD   R   R   R   t   PyExpatReaderR%   RT   (   R   R   R%   (    (    R   R   6  s    R7   c         C   s<  |  i | ƒ o| i d ƒ } | d } | d } |  i i | d ƒ } | d j o t i |  | | | | ƒ Sq8t | ƒ t i j o2 t i i | | ƒ }	 t i |  |	 | | | ƒ Sq8|  i | | |  i ƒ } | o) t | ƒ }
 t i |  |
 | | | ƒ Sq8t i |  | | | | ƒ Sn t i |  | | | | ƒ Sd S(   s!    resolve URI for document() call RM   i   i   N(   R   RR   RO   RI   RP   RV   RW   R   RX   R   RF   Rh   RY   R   RZ   R[   R   R^   R_   R`   Ra   Rb   Rc   RL   RT   Rd   Re   Rf   Rg   (   R   RO   R   RZ   R[   RP   RV   Rd   RF   Rc   Rf   RW   (    (    R   RY   ;  s,     

(   R?   R@   RA   R   R   RY   (    (    (    R   R(   1  s    	(   s   ProcessorRegistryR"   s)   not available for use with ZopeXMLMethods(#   RA   t
   __cvstag__t   __date__t   __version__t   xmlR0   t   xml.xslt.ProcessorR"   R   R,   t   xml.xslt.StylesheetReaderR   t   Ft.Lib.pDomletteReaderRh   t   AcquisitionR:   t	   cStringIORe   t   os.pathR`   t   sysR^   t
   interfacesRB   R;   t   parametersPropertyNameR   RD   R$   R(   t   ProcessorRegistryt   klasst   proct   registerR9   (   R   Ru   Rh   R   R:   R,   R;   Rv   Rk   Rx   R$   R0   RD   Rs   R"   R^   RB   Re   Rj   Ri   Rw   R`   R(   (    (    R   t   ?
   s2   —%I;	