ó
†ãñJc           @   sY   d  Z  d d l m Z d d l Td d l m Z e e ƒ Z d	 Z	 d d
 d „  ƒ  YZ
 d S(   s/   
Provides classes for handling soap multirefs.
iÿÿÿÿ(   t	   getLogger(   t   *(   t   Elements)   http://schemas.xmlsoap.org/soap/encoding/t   MultiRefc           B   sD   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(   sÁ   
    Resolves and replaces multirefs.
    @ivar nodes: A list of non-multiref nodes.
    @type nodes: list
    @ivar catalog: A dictionary of multiref nodes by id.
    @type catalog: dict 
    c         C   s   g  |  _  i  |  _ d  S(   N(   t   nodest   catalog(   t   self(    (    sP   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/bindings/multiref.pyt   __init__&   s    	c         C   s<   g  |  _  i  |  _ |  j | ƒ |  j | ƒ |  j  | _ | S(   s%  
        Process the specified soap envelope body and replace I{multiref} node
        references with the contents of the referenced node.
        @param body: A soap envelope body node.
        @type body: L{Element}
        @return: The processed I{body}
        @rtype: L{Element}
        (   R   R   t   build_catalogt   updatet   children(   R   t   body(    (    sP   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/bindings/multiref.pyt   process*   s    			c         C   s2   |  j  | ƒ x | j D] } |  j | ƒ q W| S(   s-  
        Update the specified I{node} by replacing the I{multiref} references with
        the contents of the referenced nodes and remove the I{href} attribute.
        @param node: A node to update.
        @type node: L{Element}
        @return: The updated node
        @rtype: L{Element}
        (   t   replace_referencesR
   R	   (   R   t   nodet   c(    (    sP   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/bindings/multiref.pyR	   :   s    	c         C   sÄ   | j  d ƒ } | d k r d S| j ƒ  } |  j j | ƒ } | d k r] t j d | ƒ d S| j | j ƒ | j	 | j
 ƒ  ƒ x0 | j D]% } | j d k rŠ | j | ƒ qŠ qŠ W| j | ƒ d S(   s  
        Replacing the I{multiref} references with the contents of the 
        referenced nodes and remove the I{href} attribute.  Warning:  since
        the I{ref} is not cloned, 
        @param node: A node to update.
        @type node: L{Element}
        t   hrefNs   soap multiref: %s, not-resolvedt   id(   t   getAttributet   Nonet   getValueR   t   gett   logt   errort   appendR
   t   setTextt   getTextt
   attributest   namet   remove(   R   R   R   R   t   reft   a(    (    sP   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/bindings/multiref.pyR   H   s    c         C   sr   xk | j  D]` } |  j | ƒ r2 |  j j | ƒ n  | j d ƒ } | d k rS q
 n  d | } | |  j | <q
 Wd S(   sº   
        Create the I{catalog} of multiref nodes by id and the list of
        non-multiref nodes.
        @param body: A soap envelope body node.
        @type body: L{Element}
        R   s   #%sN(   R
   t   soaprootR   R   R   R   R   (   R   R   t   childR   t   key(    (    sP   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/bindings/multiref.pyR   _   s     
c         C   s6   | j  d d t ƒ} | d k r% t S| j d k Sd S(   sj  
        Get whether the specified I{node} is a soap encoded root.
        This is determined by examining @soapenc:root='1'.
        The node is considered to be a root when the attribute
        is not specified.
        @param node: A node to evaluate.
        @type node: L{Element}
        @return: True if a soap encoded root.
        @rtype: bool
        t   roott   nst   1N(   R   t   soapencR   t   Truet   value(   R   R   R#   (    (    sP   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/bindings/multiref.pyR    n   s    (	   t   __name__t
   __module__t   __doc__R   R   R	   R   R   R    (    (    (    sP   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/bindings/multiref.pyR      s   					N(   Ns)   http://schemas.xmlsoap.org/soap/encoding/(    (   R+   t   loggingR    t   sudst   suds.sax.elementR   R)   R   R   R&   R   (    (    (    sP   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/bindings/multiref.pyt   <module>   s   
