ó
h€
\c           @   sð   d  Z  d d l 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 m Z d d
 l m Z d d g Z d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d S(   s:   
    zeep.wsdl.messages.soap
    ~~~~~~~~~~~~~~~~~~~~~~~

iÿÿÿÿN(   t   OrderedDict(   t   etree(   t   ElementMaker(   t
   exceptionst   xsd(   t   as_qname(   t   XmlParserContext(   t   ConcreteMessaget   SerializedMessage(   t   process_multireft   DocumentMessaget
   RpcMessaget   SoapMessagec           B   sž   e  Z d  Z d „  Z d „  Z d „  Z e d „ Z e d „  ƒ Z	 e d „  ƒ Z
 e d „  ƒ Z e d „  ƒ Z d	 „  Z d
 „  Z d „  Z d „  Z d „  Z RS(   sˆ  Base class for the SOAP Document and RPC messages

    :param wsdl: The main wsdl document
    :type wsdl: zeep.wsdl.Document
    :param name:
    :param operation: The operation to which this message belongs
    :type operation: zeep.wsdl.bindings.soap.SoapOperation
    :param type: 'input' or 'output'
    :type type: str
    :param nsmap: The namespace mapping
    :type nsmap: dict

    c         C   sV   t  t |  ƒ j | | | ƒ | |  _ d  |  _ | |  _ d  |  _ d  |  _ d  |  _	 d  S(   N(
   t   superR   t   __init__t   nsmapt   Nonet   abstractt   typet   bodyt   headert   envelope(   t   selft   wsdlt   namet	   operationR   R   (    (    sL   /data/av2000/b2b/venv/lib/python2.7/site-packages/zeep/wsdl/messages/soap.pyR   &   s    					c         O   s  i |  j  d d 6} | j |  j j j ƒ t d |  j  d d | ƒ } | j d d
 ƒ } |  j | | ƒ } | j	 ƒ  } |  j
 r§ |  j
 | | Ž  } |  j
 j | | ƒ n  | j ƒ  }	 | d
 k	 rÏ |	 j | ƒ n  |	 j | ƒ i d |  j j d 6}
 t d d
 d |
 d	 |	 ƒ S(   s+   Create a SerializedMessage for this messages   soap-envt	   namespaceR   t   _soapheaderss   "%s"t
   SOAPActiont   patht   headerst   contentN(   R   t   updateR   t   typest   _prefix_map_customR   t   popR   t   _serialize_headert   BodyR   t   rendert   Envelopet   appendR   t
   soapactionR   (   R   t   argst   kwargsR   t   soapt   headers_valueR   R   t
   body_valueR   R   (    (    sL   /data/av2000/b2b/venv/lib/python2.7/site-packages/zeep/wsdl/messages/soap.pyt	   serialize0   s$    	c         C   sd  |  j  s d S| j d d |  j ƒ} |  j | ƒ } | j d d |  j ƒ} |  j | ƒ } | } | j | ƒ |  j  |   } |  j j j	 r | S| j
 } | d k s· t | ƒ d k r» d St | ƒ d k rÑ | St t | j j ƒ  ƒ ƒ } t | t j ƒ r`| j j } | j j }	 t | ƒ d k r`t |	 ƒ d k r`| d \ }
 } t | |
 ƒ } | Sn  | S(   s[   Deserialize the SOAP:Envelope and return a CompoundValue with the
        result.

        s   soap-env:Bodyt
   namespacess   soap-env:Headeri    i   N(   R   R   t   findR   t   _deserialize_bodyt   _deserialize_headersR    R   R   t   _elementR   t   lent   nextt   itert
   __values__t   valuest
   isinstanceR   t   CompoundValuet	   _xsd_typet   elementst
   attributest   getattr(   R   R   R   t   body_resultR   t   headers_resultR+   t   resultt   childrenR>   t	   item_namet   item_elementt   retval(    (    sL   /data/av2000/b2b/venv/lib/python2.7/site-packages/zeep/wsdl/messages/soap.pyt   deserializeR   s2    		$c         C   sE  |  j  s d  S| r´ t |  j  j t j ƒ r’ yO t |  j  j j ƒ d k ry |  j  j j d d j j d |  j	 j
 d t ƒ SWq’ t k
 rŽ d  SXn  |  j  j j d |  j	 j
 d t ƒ S|  j rç |  j j j d |  j	 j
 d t ƒ g } n g  } |  j j j r.| j d |  j j j d |  j	 j
 d t ƒ ƒ n  d j d „  | Dƒ ƒ S(   Ni   i    t   schemat
   standalones   _soapheaders={%s}s   , c         s   s   |  ] } | r | Vq d  S(   N(    (   t   .0t   part(    (    sL   /data/av2000/b2b/venv/lib/python2.7/site-packages/zeep/wsdl/messages/soap.pys	   <genexpr>   s    (   R   R   R:   R   R   t   ComplexTypeR5   R=   t	   signatureR   R!   t   Falset   AttributeErrorR   R   R4   R(   t   join(   R   t	   as_outputt   parts(    (    sL   /data/av2000/b2b/venv/lib/python2.7/site-packages/zeep/wsdl/messages/soap.pyRM   z   s$    	"	*c         C   sÃ   | j  d ƒ } |  | j | | d | d | ƒ} d	 } d	 }	 | j d d | j j ƒ}
 |
 d	 k	 ru |  j |
 ƒ } n  | j d d | j j ƒ} |  j | | j	 | ƒ }	 i | d 6|	 d 6| _
 | S(
   s»  Parse a wsdl:binding/wsdl:operation/wsdl:operation for the SOAP
        implementation.

        Each wsdl:operation can contain three child nodes:
         - input
         - output
         - fault

        Definition for input/output::

          <input>
            <soap:body parts="nmtokens"? use="literal|encoded"
                       encodingStyle="uri-list"? namespace="uri"?>

            <soap:header message="qname" part="nmtoken" use="literal|encoded"
                         encodingStyle="uri-list"? namespace="uri"?>*
              <soap:headerfault message="qname" part="nmtoken"
                                use="literal|encoded"
                                encodingStyle="uri-list"? namespace="uri"?/>*
            </soap:header>
          </input>

        And the definition for fault::

           <soap:fault name="nmtoken" use="literal|encoded"
                       encodingStyle="uri-list"? namespace="uri"?>

        R   R   R   s	   soap:bodyR0   s   soap:headerR   R   N(   t   getR   R   R1   t   bindingR   t   _parse_bodyt   findallt   _parse_headert   target_namespacet   _resolve_info(   t   clst   definitionst
   xmlelementR   R   R   R   t   objt	   body_datat   header_dataR   R=   (    (    sL   /data/av2000/b2b/venv/lib/python2.7/site-packages/zeep/wsdl/messages/soap.pyt   parse‘   s    !c         C   sG   i | j  d ƒ d 6| j  d d ƒ d 6| j  d ƒ d 6| j  d ƒ d 6S(   sÈ   Parse soap:body and return a dict with data to resolve it.

            <soap:body parts="nmtokens"? use="literal|encoded"?
                       encodingStyle="uri-list"? namespace="uri"?>

        RK   t   uset   literalt   encodingStyleR   (   RS   (   RZ   R\   (    (    sL   /data/av2000/b2b/venv/lib/python2.7/site-packages/zeep/wsdl/messages/soap.pyRU   Ç   s
    c   
      C   s“   g  } x† | D]~ } |  j  | | ƒ } g  | d <| j d d | j j ƒ} x1 | D]) } |  j  | | ƒ }	 | d j |	 ƒ qQ W| j | ƒ q W| S(   sF  Parse the soap:header and optionally included soap:headerfault elements

          <soap:header
            message="qname"
            part="nmtoken"
            use="literal|encoded"
            encodingStyle="uri-list"?
            namespace="uri"?
          />*

        The header can optionally contain one ore more soap:headerfault
        elements which can contain the same attributes as the soap:header::

           <soap:headerfault message="qname" part="nmtoken" use="literal|encoded"
                             encodingStyle="uri-list"? namespace="uri"?/>*

        t   faultss   soap:headerfaultR0   (   t   _parse_header_elementRV   RT   R   R(   (
   RZ   t   xmlelementst   tnsR   RB   R\   t   datat   fault_elementst   fault_elementt
   fault_data(    (    sL   /data/av2000/b2b/venv/lib/python2.7/site-packages/zeep/wsdl/messages/soap.pyRW   Ö   s    
c         C   sŽ   | j  } t | d | j | ƒ } yE i | d 6| d d 6| d d 6| j d ƒ d 6| j d ƒ d 6SWn  t k
 r‰ t j d ƒ ‚ n Xd  S(   Nt   messageRK   Ra   Rc   R   s   Invalid soap:header(fault)(   t   attribR   R   RS   t   KeyErrorR   t   WsdlSyntaxError(   RZ   R\   Rg   R>   t   message_qname(    (    sL   /data/av2000/b2b/venv/lib/python2.7/site-packages/zeep/wsdl/messages/soap.pyRe   ø   s    	c         C   s’   |  j  } |  `  | j r, |  j d k r, d S| |  _ t |  j j ƒ } |  j | d | | ƒ |  _ |  j | d | | ƒ |  _ |  j	 ƒ  |  _
 d S(   s   Resolve the data in the self._resolve_info dict (set via parse())

        This creates three xsd.Element objects:

            - self.header
            - self.body
            - self.envelope (combination of headers and body)

        XXX headerfaults are not implemented yet.

        t   inputNR   R   (   RY   RR   R   R   R    t   _resolve_headerR   t   _resolve_bodyR   t   _create_envelope_elementR   (   R   R[   t   abstract_messaget   infoRR   (    (    sL   /data/av2000/b2b/venv/lib/python2.7/site-packages/zeep/wsdl/messages/soap.pyt   resolve	  s    		c         C   s¨   t  j g  ƒ } |  j j j rK | j t  j d |  j d |  j j ƒ ƒ n  | j t  j d |  j d |  j rz |  j j n d ƒ ƒ t  j d |  j d t  j
 | ƒ ƒ S(   sx   Create combined `envelope` complexType which contains both the
        elements from the body and the headers.

        s
   {%s}headers   soap-envs   {%s}bodys   {%s}envelopeN(   R   t   SequenceR   R   R4   R(   t   ElementR   R   R   RL   (   R   t   all_elements(    (    sL   /data/av2000/b2b/venv/lib/python2.7/site-packages/zeep/wsdl/messages/soap.pyRt   $  s    'c         C   s  | s
 d  St  j | ƒ } t d |  j d d | ƒ } | j ƒ  } t | t ƒ rÜ x*| D]~ } t | d ƒ r‚ | j j	 | | ƒ qW t | d ƒ r§ | j
 j	 | | ƒ qW t | t j ƒ rÉ | j | ƒ qW t d ƒ ‚ qW Wn¡ t | t ƒ rq|  j st d ƒ ‚ n  |  j |   } xh |  j j j D]H \ } } | | k r"| | d  k	 r"| j	 | | | d | g ƒ q"q"Wn t d ƒ ‚ | S(	   NR   s   soap-envR   t   _xsd_elmR<   s#   Invalid value given to _soapheaderssG   _soapheaders only accepts a dictionary if the wsdl defines the headers.R   (   t   copyt   deepcopyR   R   t   HeaderR:   t   listt   hasattrR{   R&   R<   R   t   _ElementR(   t
   ValueErrort   dictR   R   R=   R   (   R   R-   R   R,   R   t   header_valueR   t   elm(    (    sL   /data/av2000/b2b/venv/lib/python2.7/site-packages/zeep/wsdl/messages/soap.pyR$   6  s0    	'c         C   sk   |  j  s | d k r i  St d |  j j ƒ } |  j  j | |  j j d | ƒ} | d k	 rg i | d 6Si  S(   s1   Deserialize the values in the SOAP:Header elementt   settingst   contextR   N(   R   R   R   R   R†   R`   R!   (   R   R\   R‡   RB   (    (    sL   /data/av2000/b2b/venv/lib/python2.7/site-packages/zeep/wsdl/messages/soap.pyR3   X  s    !c         C   s  t  j |  j d d ƒ } t j d t ƒ } | sJ t j | t j | ƒ ƒ Sx¯ | D]§ } | d j } | d } | j	 d | ƒ }	 |	 |  j
 k r¥ | | k r¥ | | =n  |	 j | }
 |
 j rÖ |
 j j ƒ  } | | _ n t j | |
 j ƒ } | j | ƒ qQ Wt j | t j | ƒ ƒ S(   Ns   soap-envR~   t   consume_otherRl   RK   t   messages(   R   t   QNameR   R   t   Allt   TrueRy   RL   t   textRS   R   RR   t   elementt   clonet	   attr_nameR   R(   (   R   Rv   R[   RR   R   t	   containert   itemt   message_namet	   part_nameRl   RK   RŽ   (    (    sL   /data/av2000/b2b/venv/lib/python2.7/site-packages/zeep/wsdl/messages/soap.pyRr   c  s"    

	(   t   __name__t
   __module__t   __doc__R   R/   RG   RN   RM   t   classmethodR`   RU   RW   Re   Rw   Rt   R$   R3   Rr   (    (    (    sL   /data/av2000/b2b/venv/lib/python2.7/site-packages/zeep/wsdl/messages/soap.pyR      s   	
	"	(6"			"	c           B   s)   e  Z d  Z d „  Z d „  Z d „  Z RS(   s/  In the document message there are no additional wrappers, and the
    message parts appear directly under the SOAP Body element.

    .. inheritance-diagram:: zeep.wsdl.messages.soap.DocumentMessage
       :parts: 1

    :param wsdl: The main wsdl document
    :type wsdl: zeep.wsdl.Document
    :param name:
    :param operation: The operation to which this message belongs
    :type operation: zeep.wsdl.bindings.soap.SoapOperation
    :param type: 'input' or 'output'
    :type type: str
    :param nsmap: The namespace mapping
    :type nsmap: dict


    c         O   s&   t  t |  ƒ j | | Ž  t |  _ d  S(   N(   R   R
   R   RN   t   _is_body_wrapped(   R   R*   R+   (    (    sL   /data/av2000/b2b/venv/lib/python2.7/site-packages/zeep/wsdl/messages/soap.pyR     s    c         C   s]   |  j  s t | ƒ d } n  t d |  j j ƒ } |  j j | |  j j d | ƒ} i | d 6S(   Ni    R†   R‡   R   (   R™   R   R   R   R†   R   R`   R!   (   R   R\   R‡   RB   (    (    sL   /data/av2000/b2b/venv/lib/python2.7/site-packages/zeep/wsdl/messages/soap.pyR2   ”  s
    	!c   	      C   sõ   t  j |  j d d ƒ } | s' | r+ d  S| d rR | d } | | j g } nQ g  } xH | j ƒ  D]: \ } } | j j ƒ  } | pŒ | j | _ | j	 | ƒ qe Wt
 | ƒ d k rà t |  _ t j | t j t j | ƒ ƒ ƒ St |  _ | d Sd  S(   Ns   soap-envR%   RK   i   i    (   R   RŠ   R   R   RŽ   t   itemsR   R   R   R(   R5   RŒ   R™   R   Ry   RL   R‹   RN   (	   R   Rv   R[   RR   R   R”   t   sub_elementsRK   RŽ   (    (    sL   /data/av2000/b2b/venv/lib/python2.7/site-packages/zeep/wsdl/messages/soap.pyRs      s     

	"	(   R•   R–   R—   R   R2   Rs   (    (    (    sL   /data/av2000/b2b/venv/lib/python2.7/site-packages/zeep/wsdl/messages/soap.pyR
   |  s   		c           B   s    e  Z d  Z d „  Z d „  Z RS(   sŠ  In RPC messages each part is a parameter or a return value and appears
    inside a wrapper element within the body.

    The wrapper element is named identically to the operation name and its
    namespace is the value of the namespace attribute.  Each message part
    (parameter) appears under the wrapper, represented by an accessor named
    identically to the corresponding parameter of the call.  Parts are arranged
    in the same order as the parameters of the call.

    .. inheritance-diagram:: zeep.wsdl.messages.soap.DocumentMessage
       :parts: 1


    :param wsdl: The main wsdl document
    :type wsdl: zeep.wsdl.Document
    :param name:
    :param operation: The operation to which this message belongs
    :type operation: zeep.wsdl.bindings.soap.SoapOperation
    :param type: 'input' or 'output'
    :type type: str
    :param nsmap: The namespace mapping
    :type nsmap: dict

    c   	      C   sÖ   | s
 d S| d } |  j d k r> t j | |  j j ƒ } n t j | |  j j j ƒ } g  } xR | j ƒ  D]D \ } } | j	 r” | j
 | j	 ƒ ql | j
 t j | | j ƒ ƒ ql Wt j | t j t j | ƒ ƒ ƒ S(   s  Return an XSD element for the SOAP:Body.

        Each part is a parameter or a return value and appears inside a
        wrapper element within the body named identically to the operation
        name and its namespace is the value of the namespace attribute.

        R   Rq   N(   R   R   R   RŠ   R   R   R   t	   localnameRš   RŽ   R(   R   Ry   RL   Rx   (	   R   Rv   R[   RR   R   t   tag_nameR=   R   t   msg(    (    sL   /data/av2000/b2b/venv/lib/python2.7/site-packages/zeep/wsdl/messages/soap.pyRs   Ô  s    
	 c         C   sl   t  | ƒ t | ƒ d } |  j ra t |  j j ƒ } |  j j | |  j j d | ƒ} i | d 6Si d d 6S(   sò   The name of the wrapper element is not defined. The WS-I defines
        that it should be the operation name with the 'Response' string as
        suffix. But lets just do it really stupid for now and use the first
        element.

        i    R‡   R   N(	   R	   R   R   R   R   R†   R`   R!   R   (   R   t   body_elementt   response_elementR‡   RB   (    (    sL   /data/av2000/b2b/venv/lib/python2.7/site-packages/zeep/wsdl/messages/soap.pyR2   ï  s    
		(   R•   R–   R—   Rs   R2   (    (    (    sL   /data/av2000/b2b/venv/lib/python2.7/site-packages/zeep/wsdl/messages/soap.pyR   º  s   	(   R—   R|   t   collectionsR    t   lxmlR   t   lxml.builderR   t   zeepR   R   t
   zeep.utilsR   t   zeep.xsd.contextR   t   zeep.wsdl.messages.baseR   R   t   zeep.wsdl.messages.multirefR	   t   __all__R   R
   R   (    (    (    sL   /data/av2000/b2b/venv/lib/python2.7/site-packages/zeep/wsdl/messages/soap.pyt   <module>   s   	ÿ e>