ó
ó÷Kc           @   sa  d  Z  d d l m Z d d l Td d l m Z d d l m Z d d l m	 Z	 d d l
 m Z d d l m Z m Z d d	 l m Z d d
 l m Z d d l m Z d d l m Z d d l m Z d d l m Z m Z d d l m Z  d d l! m" Z" d d l# m$ Z$ d d l% m& Z& e e' ƒ Z( d d f Z) d f  d „  ƒ  YZ* d e  f d „  ƒ  YZ+ d S(   s*   
Provides classes for (WS) SOAP bindings.
iÿÿÿÿ(   t	   getLogger(   t   *(   t	   Namespace(   t   Parser(   t   Document(   t   Element(   t   Factoryt   Object(   t   Content(   t   Literal(   t   Basic(   t   Typed(   t   MultiRef(   t	   TypeQueryt   ElementQuery(   t   Options(   t   PluginContainer(   t   deepcopys   SOAP-ENVs)   http://schemas.xmlsoap.org/soap/envelope/t   Bindingc           B   sï   e  Z d  Z d „  Z d „  Z d „  Z d „  Z e d „ Z d „  Z	 d „  Z
 d „  Z d	 „  Z d
 „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z e d „ Z e d „ Z d „  Z RS(   sÀ  
    The soap binding class used to process outgoing and imcoming
    soap messages per the WSDL port binding.
    @cvar replyfilter: The reply filter function.
    @type replyfilter: (lambda s,r: r)
    @ivar wsdl: The wsdl.
    @type wsdl: L{suds.wsdl.Definitions}
    @ivar schema: The collective schema contained within the wsdl.
    @type schema: L{xsd.schema.Schema}
    @ivar options: A dictionary options.
    @type options: L{Options}
    c         C   s   | S(   N(    (   t   st   r(    (    sO   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/bindings/binding.pyt   <lambda>:   s    c         C   s   | |  _  t ƒ  |  _ d S(   sN   
        @param wsdl: A wsdl.
        @type wsdl: L{wsdl.Definitions}
        N(   t   wsdlR   t   multiref(   t   selfR   (    (    sO   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/bindings/binding.pyt   __init__<   s    	c         C   s
   |  j  j S(   N(   R   t   schema(   R   (    (    sO   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/bindings/binding.pyR   D   s    c         C   s
   |  j  j S(   N(   R   t   options(   R   (    (    sO   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/bindings/binding.pyR   G   s    c         C   s!   | r t  |  j ƒ  ƒ St ƒ  Sd S(   s†   
        Get the appropriate XML decoder.
        @return: Either the (basic|typed) unmarshaller.
        @rtype: L{UmxTyped}
        N(   t   UmxTypedR   t   UmxBasic(   R   t   typed(    (    sO   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/bindings/binding.pyt   unmarshallerJ   s    c         C   s   t  |  j ƒ  |  j ƒ  j ƒ S(   s|   
        Get the appropriate XML encoder.
        @return: An L{MxLiteral} marshaller.
        @rtype: L{MxLiteral}
        (   t	   MxLiteralR   R   t   xstq(   R   (    (    sO   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/bindings/binding.pyt
   marshallerU   s    c         C   s   t  d ‚ d S(   s  
        Get parameter definitions.  
        Each I{pdef} is a tuple (I{name}, L{xsd.sxbase.SchemaObject})
        @param method: A servic emethod.
        @type method: I{service.Method}
        @return: A collection of parameter definitions
        @rtype: [I{pdef},..]
        s   not implementedN(   t	   Exception(   R   t   method(    (    sO   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/bindings/binding.pyt
   param_defs]   s    	c         C   sŽ   |  j  | ƒ } |  j | ƒ } |  j | | | ƒ } |  j | ƒ } |  j | | ƒ } |  j ƒ  j rz | j ƒ  | j ƒ  n
 | j	 ƒ  t
 | ƒ S(   së  
        Get the soap message for the specified method, args and soapheaders.
        This is the entry point for creating the outbound soap message.
        @param method: The method being invoked.
        @type method: I{service.Method}
        @param args: A list of args for the method invoked.
        @type args: list
        @param kwargs: Named (keyword) args for the method invoked.
        @type kwargs: dict
        @return: The soap envelope.
        @rtype: L{Document}
        (   t   headercontentt   headert   bodycontentt   bodyt   envelopeR   t   prefixest   normalizePrefixest   promotePrefixest   refitPrefixesR   (   R   R$   t   argst   kwargst   contentR'   R)   t   env(    (    sO   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/bindings/binding.pyt   get_messageh   s    

c         C   s…  |  j  | ƒ } t ƒ  } | j d | ƒ } t |  j ƒ  j ƒ } | j j d | ƒ | j d ƒ } | j	 ƒ  | j d ƒ } |  j
 | ƒ |  j j | ƒ } |  j | | ƒ } |  j | ƒ }	 t |	 ƒ d k rè |  j |	 | ƒ }
 | |
 f St |	 ƒ d k r{|	 d j ƒ  r*|  j |	 d | ƒ }
 | |
 f St | ƒ r{|  j ƒ  } |	 d j d t ƒ } | j | d | ƒ }
 | |
 f Sn  | d f S(	   s>  
        Process the I{reply} for the specified I{method} by sax parsing the I{reply}
        and then unmarshalling into python object(s).
        @param method: The name of the invoked method.
        @type method: str
        @param reply: The reply XML received after invoking the specified method.
        @type reply: str
        @return: The unmarshalled reply.  The returned value is an L{Object} for a
            I{list} depending on whether the service returns a single object or a 
            collection.
        @rtype: tuple ( L{Element}, L{Object} )
        t   stringt   replyt   Envelopet   Bodyi   i    t	   nobuiltinN(   t   replyfilterR   t   parseR   R   t   pluginst   messaget   parsedt   getChildR-   t   detect_faultR   t   processt   replycontentt   returned_typest   lent   replycompositet	   unboundedt	   replylistR   t   resolvet   Truet   None(   R   R$   R5   t   saxt	   replyrootR;   t   soapenvt   soapbodyt   nodest   rtypest   resultR   t   resolved(    (    sO   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/bindings/binding.pyt	   get_reply‚   s2    	


c         C   se   | j  d t ƒ } | d k r" d S|  j t ƒ } | j | ƒ } |  j ƒ  j ra t | | ƒ ‚ n  |  S(   s»   
        Detect I{hidden} soapenv:Fault element in the soap body.
        @param body: The soap envelope body.
        @type body: L{Element}
        @raise WebFault: When found.
        t   FaultN(	   R>   t   envnsRI   R   t   FalseR@   R   t   faultst   WebFault(   R   R)   t   faultR   t   p(    (    sO   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/bindings/binding.pyR?   ©   s    c         C   sX   g  } | j  d t ƒ } |  j ƒ  } x- | D]% } | j | | ƒ } | j | ƒ q+ W| S(   s‚  
        Construct a I{list} reply.  This mehod is called when it has been detected
        that the reply is a list.
        @param rt: The return I{type}.
        @type rt: L{suds.xsd.sxbase.SchemaObject}
        @param nodes: A collection of XML nodes.
        @type nodes: [L{Element},...]
        @return: A list of I{unmarshalled} objects.
        @rtype: [L{Object},...]
        R8   (   RG   RH   R   R@   t   append(   R   t   rtRN   RP   RQ   R   t   nodet   sobject(    (    sO   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/bindings/binding.pyRF   º   s    c         C   sh  i  } x | D] } | | | j  <q W|  j ƒ  } t j d ƒ } x"| D]} | j  } | j | d ƒ } | d k r¡ | j d ƒ d k rF t d | ƒ ‚ q¡ qF n  | j d t ƒ }	 | j	 | |	 ƒ }
 t
 | | d ƒ } | d k r(| j ƒ  rg  } t | | | ƒ | j |
 ƒ q`t | | |
 ƒ qF t | t ƒ sS| g } t | | | ƒ n  | j |
 ƒ qF W| S(   s²  
        Construct a I{composite} reply.  This method is called when it has been
        detected that the reply has multiple root nodes.
        @param rtypes: A list of known return I{types}.
        @type rtypes: [L{suds.xsd.sxbase.SchemaObject},...]
        @param nodes: A collection of XML nodes.
        @type nodes: [L{Element},...]
        @return: The I{unmarshalled} composite object.
        @rtype: L{Object},...
        R5   t   ids    <%s/> not mapped to message partR8   N(   t   nameR   R   t   objectt   getRI   R#   RG   RH   R@   t   getattrRE   t   setattrRZ   t
   isinstancet   list(   R   RO   RN   t
   dictionaryR[   R   t	   compositeR\   t   tagRQ   R]   t   value(    (    sO   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/bindings/binding.pyRD   Í   s4    		c   	      C   s£   |  j  | ƒ } t ƒ  } | j d | ƒ } | j d ƒ } | j d ƒ } | j d ƒ } |  j t ƒ } | j | ƒ } |  j ƒ  j r– t	 | | ƒ ‚ n  | | j
 f S(   s’  
        Extract the fault from the specified soap reply.  If I{faults} is True, an
        exception is raised.  Otherwise, the I{unmarshalled} fault L{Object} is
        returned.  This method is called when the server raises a I{web fault}.
        @param reply: A soap reply message.
        @type reply: str
        @return: A fault object.
        @rtype: tuple ( L{Element}, L{Object} )
        R4   R6   R7   RS   (   R9   R   R:   R>   R   RU   R@   R   RV   RW   t   detail(	   R   R5   RJ   t	   faultrootRL   RM   RX   R   RY   (    (    sO   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/bindings/binding.pyt	   get_faultö   s    
	c      
   C   sL   |  j  ƒ  } t d | d d | d | d d | d j ƒ  ƒ } | j | ƒ S(   sÈ  
        Builds a parameter for the specified I{method} using the parameter
        definition (pdef) and the specified value (object).
        @param method: A method name.
        @type method: str
        @param pdef: A parameter definition.
        @type pdef: tuple: (I{name}, L{xsd.sxbase.SchemaObject})
        @param object: The parameter value.
        @type object: any
        @return: The parameter fragment.
        @rtype: L{Element}
        Rh   i    Ri   t   typei   t   real(   R"   R   RG   R@   (   R   R$   t   pdefR`   R"   R1   (    (    sO   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/bindings/binding.pyt   mkparam  s    
c         C   sˆ   |  j  ƒ  } t | t t f ƒ rX g  } x* | D]" } | j |  j | | | ƒ ƒ q. W| St d | d d | d | d ƒ } | j | ƒ S(   sÀ  
        Builds a soapheader for the specified I{method} using the header
        definition (hdef) and the specified value (object).
        @param method: A method name.
        @type method: str
        @param hdef: A header definition.
        @type hdef: tuple: (I{name}, L{xsd.sxbase.SchemaObject})
        @param object: The header value.
        @type object: any
        @return: The parameter fragment.
        @rtype: L{Element}
        Rh   i    Ri   Rm   i   (   R"   Rd   Re   t   tupleRZ   t   mkheaderR   R@   (   R   R$   t   hdefR`   R"   t   tagst   itemR1   (    (    sO   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/bindings/binding.pyRr   !  s     #c         C   sN   t  d d t ƒ} | j t j d t j d ƒ | j | ƒ | j | ƒ | S(   sH  
        Build the B{<Envelope/>} for an soap outbound message.
        @param header: The soap message B{header}.
        @type header: L{Element}
        @param body: The soap message B{body}.
        @type body: L{Element}
        @return: The soap envelope containing the body and header.
        @rtype: L{Element}
        R6   t   nsi    i   (   R   RT   t	   addPrefixR   t   xsinsRZ   (   R   R'   R)   R2   (    (    sO   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/bindings/binding.pyR*   7  s
    
c         C   s#   t  d d t ƒ} | j | ƒ | S(   sÖ   
        Build the B{<Body/>} for an soap outbound message.
        @param content: The header content.
        @type content: L{Element}
        @return: the soap body fragment.
        @rtype: L{Element}
        t   HeaderRv   (   R   RT   RZ   (   R   R1   R'   (    (    sO   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/bindings/binding.pyR'   G  s    c         C   s   t  d ‚ d S(   sƒ  
        Get the content for the soap I{body} node.
        @param method: A service method.
        @type method: I{service.Method}
        @param args: method parameter values
        @type args: list
        @param kwargs: Named (keyword) args for the method invoked.
        @type kwargs: dict
        @return: The xml content for the <body/>
        @rtype: [L{Element},..]
        s   not implementedN(   R#   (   R   R$   R/   R0   (    (    sO   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/bindings/binding.pyR(   S  s    c         C   sâ  d } g  } |  j  ƒ  j } | d k	 r= | j | j ƒ  ƒ n  |  j  ƒ  j } t | t t t	 f ƒ sp | f } n  t
 | ƒ d k r† | S|  j | ƒ } t | t t f ƒ r[x1| D]£ } t | t ƒ rß | j t | ƒ ƒ q± n  t
 | ƒ | k rõ Pn  |  j | | | | ƒ } | | d j d ƒ }	 | j |	 d |	 d ƒ | j | ƒ | d 7} q± Wnƒ x€ | D]x }
 | j |
 d ƒ } | d k r�qbn  |  j | |
 | ƒ } |
 d j d ƒ }	 | j |	 d |	 d ƒ | j | ƒ qbW| S(   sà   
        Get the content for the soap I{Header} node.
        @param method: A service method.
        @type method: I{service.Method}
        @return: The xml content for the <body/>
        @rtype: [L{Element},..]
        i    i   t   ns0N(   R   t   wsseRI   RZ   t   xmlt   soapheadersRd   Rq   Re   t   dictRC   t   headpart_typesR   R   Rr   t	   namespacet	   setPrefixRa   (   R   R$   t   nR1   R{   t   headerst   ptsR'   t   hRv   t   pt(    (    sO   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/bindings/binding.pyR&   a  s@     c         C   s   t  d ‚ d S(   s  
        Get the reply body content.
        @param method: A service method.
        @type method: I{service.Method}
        @param body: The soap body
        @type body: L{Element}
        @return: the body content
        @rtype: [L{Element},...]
        s   not implementedN(   R#   (   R   R$   R)   (    (    sO   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/bindings/binding.pyRA   Š  s    
c         C   s#   t  d d t ƒ} | j | ƒ | S(   sÔ   
        Build the B{<Body/>} for an soap outbound message.
        @param content: The body content.
        @type content: L{Element}
        @return: the soap body fragment.
        @rtype: L{Element}
        R7   Rv   (   R   RT   RZ   (   R   R1   R)   (    (    sO   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/bindings/binding.pyR)   –  s    c         C   s#  g  } | r! | j  j j j } n | j  j j j } xé | D]á } | j d k	 ra t | j ƒ } n t | j	 ƒ } | j
 |  j ƒ  ƒ } | d k r£ t | j ƒ ‚ n  | j	 d k	 rÇ t | j | ƒ } n  | r| j d k rõ | j | j | f ƒ q| j | j | f ƒ q: | j | ƒ q: W| S(   s–  
        Get a list of I{parameter definitions} (pdef) defined for the specified method.
        Each I{pdef} is a tuple (I{name}, L{xsd.sxbase.SchemaObject})
        @param method: A service method.
        @type method: I{service.Method}
        @param input: Defines input/output message.
        @type input: boolean
        @return:  A list of parameter definitions
        @rtype: [I{pdef},]
        N(   t   soapt   inputR)   t   partst   outputt   elementRI   R   R   Rm   t   executeR   t   TypeNotFoundt   reft   PartElementR_   RZ   (   R   R$   Rˆ   RP   R‰   RY   t   queryR†   (    (    sO   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/bindings/binding.pyt   bodypart_types¢  s&    c   	      C   s&  g  } | r | j  j j } n | j  j j } xò | D]ê } | j } | j d k	 rd t | j ƒ } n t | j	 ƒ } | j
 |  j ƒ  ƒ } | d k r¦ t | j ƒ ‚ n  | j	 d k	 rÊ t | j | ƒ } n  | r| j d k rø | j | j | f ƒ q| j | j | f ƒ q4 | j | ƒ q4 W| S(   s–  
        Get a list of I{parameter definitions} (pdef) defined for the specified method.
        Each I{pdef} is a tuple (I{name}, L{xsd.sxbase.SchemaObject})
        @param method: A service method.
        @type method: I{service.Method}
        @param input: Defines input/output message.
        @type input: boolean
        @return:  A list of parameter definitions
        @rtype: [I{pdef},]
        N(   R‡   Rˆ   Rƒ   RŠ   t   partR‹   RI   R   R   Rm   RŒ   R   R�   RŽ   R�   R_   RZ   (	   R   R$   Rˆ   RP   Rƒ   R'   R’   R�   R†   (    (    sO   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/bindings/binding.pyR   Å  s(    	c         C   s7   g  } x* |  j  | d t ƒD] } | j | ƒ q W| S(   sú   
        Get the L{xsd.sxbase.SchemaObject} returned by the I{method}.
        @param method: A service method.
        @type method: I{service.Method}
        @return: The name of the type return by the method.
        @rtype: [I{rtype},..]
        Rˆ   (   R‘   RU   RZ   (   R   R$   RP   R[   (    (    sO   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/bindings/binding.pyRB   é  s    (   t   __name__t
   __module__t   __doc__R9   R   R   R   RH   R   R"   R%   R3   RR   R?   RF   RD   Rl   Rp   Rr   R*   R'   R(   R&   RA   R)   R‘   R   RB   (    (    (    sO   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/bindings/binding.pyR   ,   s2   								'			)							)		#$R�   c           B   sA   e  Z d  Z d „  Z d „  Z d „  Z d d „ Z e d „ Z	 RS(   sÖ   
    A part used to represent a message part when the part
    references a schema type and thus assumes to be an element.
    @ivar resolved: The part type.
    @type resolved: L{suds.xsd.sxbase.SchemaObject}
    c         C   sJ   t  d d t j ƒ} t j |  | j | ƒ | |  _ | |  _ t |  _	 d S(   s¥   
        @param name: The part name.
        @type name: str
        @param resolved: The part type.
        @type resolved: L{suds.xsd.sxbase.SchemaObject}
        R‹   Rv   N(
   R   R   t   xsdnst   SchemaElementR   R   t   _PartElement__resolvedR_   RU   t   form_qualified(   R   R_   RQ   t   root(    (    sO   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/bindings/binding.pyR   ÿ  s
    		c         C   s   |  S(   N(    (   R   (    (    sO   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/bindings/binding.pyt   implany  s    c         C   s   t  S(   N(   RH   (   R   (    (    sO   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/bindings/binding.pyt   optional  s    c         C   s   t  j S(   N(   R   t   default(   R   t   prefix(    (    sO   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/bindings/binding.pyR€     s    c         C   s$   | r |  j  j ƒ  r |  S|  j  Sd  S(   N(   R˜   t   builtin(   R   R8   (    (    sO   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/bindings/binding.pyRG     s    N(
   R“   R”   R•   R   R›   Rœ   RI   R€   RU   RG   (    (    (    sO   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/bindings/binding.pyR�   ÷  s   			N(,   R•   t   loggingR    t   sudst   suds.saxR   t   suds.sax.parserR   t   suds.sax.documentR   t   suds.sax.elementR   t   suds.sudsobjectR   R   t   suds.mxR   t   suds.mx.literalR	   R    t   suds.umx.basicR
   R   t   suds.umx.typedR   R   t   suds.bindings.multirefR   t   suds.xsd.queryR   R   t   suds.xsd.sxbasicR—   t   suds.optionsR   t   suds.pluginR   t   copyR   R“   t   logRT   R   R�   (    (    (    sO   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/bindings/binding.pyt   <module>   s,   
ÿ Ì