mò
	Zí>c           @   sû   d  Z  d d d !Z d d d !Z d d d !Z d k 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 f  d „  ƒ  YZ d k l Z e Z y e ƒ  Z e i e ƒ Wn d Ge i Gd GHn Xd S(   s3  
$RCSfile: SabPythProcessor.py,v $

This class encapsulates an XSLT Processor for use by ZopeXMLMethod.
This is the SabPyth 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   XSLparameterst   SabPythProcessorc           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
    ZopeXMLMethod.  This is the SabPyth version, including support for
    XSLT parameters.  It does not yet include support for URN
    resolution.
    s   Sab-Pyth-0.52c         C   s   d |  _ d S(   s-   Initialize a new instance of SabPythProcessori    N(   t   selft
   debugLevel(   R   (    (    t   processors/SabPythProcessor.pyt   __init__2   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 h  } x- | i ƒ  D] \ } } |  i	 | | | ƒ qX Wh  }
 | d j	 o |  i | ƒ }
 n |  i d j o d G|
 GHn t i ƒ  } | i ƒ  }	 | i t i t |
 | ƒ ƒ | i t i t ƒ  ƒ | i d d d	 |	 d
 | f d | f g ƒ t | i d ƒ d ƒ } | i d ƒ } | 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 Sablotron specific exceptions and raises an Exception

        i    s   params:i   s   xsltContents:s   xmlContents:s   namespaces:s	   arg:sheets	   arg:inputs
   arg:outputt   inputt   sheett   outputt   utf8s
   ISO-8859-1N(   R   R   t   paramst   xsltContentst   xmlContentst
   xsltParamst   itemst   keyt   valuet   addParamt   namespaceMapt   transformObjectt   Nonet   retrieveNamespacest   Sablott   CreateProcessort   spt	   paramListt
   regHandlert
   HLR_SCHEMEt   UrnSchemeHandlert   REQUESTt   HLR_MESSAGEt   MessageHandlert   runt   unicodet   getResultArgt   textt   encodet   result(   R   R   t   xmlURLR   t   xsltURLR   R   R    R   R   R   R   R   R(   R&   R   (    (    R   t	   transformI   s8     	 
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   %sN(   R   t   paramMapt   name(   R   R,   R-   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   callablet   str(   R   R   R   R1   R0   R(   (    (    R   R   ‘   s      (   t   __name__t
   __module__t   __doc__t   IXSLTProcessort   __implements__R-   R   R   R   R+   R   R   (    (    (    R   R   '   s    		8	R"   c           B   s)   t  Z d  Z d „  Z d „  Z d „  Z RS(   sv   

    MessageHandlers are called by Sablotron to receive error reports,
    display them, keep a log, trace etc.

    c         C   s   d S(   sÒ   
    
        makes the 'external' error code to report with log() or
        error() call with facility = module id; severity = 1 iff
        critical. 'code' is the error code internal to Sablotron.

        N(    (   R   t   severityt   facilityt   code(    (    R   t   makeCode±   s    c         C   s   d S(   sÁ   

        pass code created by makeCode, level as necessary. fields is a
        list of strings in form "field:contents". distinguished fields
        include: msg, file, line, token

        N(    (   R   R;   R   t   fields(    (    R   t   log¼   s    c         C   s   d i  | ƒ } t | ƒ ‚ d S(   s+   for reporting errors, meaning as with log()t    N(   t   joinR=   t   errorMessaget	   Exception(   R   R;   R   R=   RA   (    (    R   t   errorÇ   s     (   R4   R5   R6   R<   R>   RC   (    (    (    R   R"   ©   s    		R   c           B   s_   t  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 d	 „  Z RS(
   s  
    
    SchemeHandlers are used by Sablotron to resolve URLs that use
    other schemes than the builtin file: and arg: (eg. http: or
    ftp:). An example scheme handler that uses the standard python
    module urllib.py is provided in the file urlhandler.py.
    
    c         C   s   h  |  _ | |  _ | |  _ d  S(   N(   R   t   handlesR   R    t   req(   R   R   R    (    (    R   R   ×   s    		c   
      C   s”   |  i | | ƒ o\ | i d ƒ } | d d } | d } |  i i	 | d ƒ }	 |  i |	 | |  i ƒ } | Sn" | d | } t i | ƒ i ƒ  Sd S(   s™   

        open the URI and return the whole string
        scheme = URI scheme (e.g. "http")
        rest = the rest of the URI (without colon)

        t   :i    i   N(   R   t   isRecognizedURNt   schemet   restt   splitt   uriPartst   nidt   nssR   t   getR   t   baset   acquireObjectContentsRE   t   stt   urlt   urllibt   urlopent   read(
   R   RH   RI   t	   bytecountRK   RM   RR   RL   RQ   RO   (    (    R   t   getAllÜ   s     
c   	      C   s¦   |  i ƒ  } |  i | | ƒ o_ | i d ƒ } | d d } | d } |  i
 i | d ƒ } |  i | | |  i ƒ |  i | <n% | d | } t i | ƒ |  i | <| S(   sÍ   

        open: open the URI and return a handle
        scheme = URI scheme (e.g. "http")
        rest = the rest of the URI (without colon)
        the resulting handle is returned in '*handle'

        RF   i    i   N(   R   t	   gethandlet   handleRG   RH   RI   RJ   RK   RL   RM   R   RN   R   RO   RP   RE   RD   RR   RS   RT   (	   R   RH   RI   RK   RM   RY   RR   RL   RO   (    (    R   t   open÷   s     
#c         C   s   |  i | i | ƒ S(   sß   

        get: retrieve data from the URI
        handle = the handle assigned on open
        buffer = pointer to the data
        *byteCount = number of bytes to read (the number actually read is returned here) 

        N(   R   RD   RY   RU   RV   (   R   RY   RV   (    (    R   RN     s     c         C   s   d S(   sò   
        
        put: save data to the URI (if possible)
        handle = the handle assigned on open
        buffer = pointer to the data
        *byteCount = number of bytes to write (the number actually written is returned here)

        N(    (   R   RY   RV   (    (    R   t   put   s    c         C   s   d |  i | <d S(   sj   
        close: close the URI with the given handle
        handle = the handle assigned on open 
        N(   R   R   RD   RY   (   R   RY   (    (    R   t   close,  s     c         C   s$   d t  |  i ƒ } d |  i | <| S(   s   get next available handles   %st    N(   t   lenR   RD   t   next(   R   R_   (    (    R   RX   4  s     c         C   s`   | } | 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(
   RO   t   zObjectt
   contextURLRJ   t   contextListt   contextR.   R   R    t   contents(   R   RO   Rb   R    Rc   Rd   Ra   Re   (    (    R   RP   :  s      c         C   s,   | i d ƒ } | d j o t | ƒ d j S(   s3   Return true if this uri is of a format we recognizeRF   t   urni   N(   t   uriRJ   RK   RH   R^   (   R   RH   Rg   RK   (    (    R   RG   R  s     (   R4   R5   R6   R   RW   RZ   RN   R[   R\   RX   RP   RG   (    (    (    R   R   Í   s    								(   s   ProcessorRegistryt	   Processors)   not available for use with ZopeXMLMethods(   R6   t
   __cvstag__t   __date__t   __version__R   t   AcquisitionR.   t   os.patht   ost   sysRS   t
   interfacesR7   R/   t   parametersPropertyNameR   R"   R   t   ProcessorRegistryt   klasst   proct   registerR-   (   R7   Rj   R/   R   R.   Rt   Rq   RS   Ri   Ro   Rs   Rr   R   Rk   Rn   R   R"   (    (    R   t   ?
   s&   	‚$Ž	