o
    g                     @   s   d 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mZ ddlmZ g d	ZG d
d deZG dd deZG dd deZG dd deZdS )z:
    zeep.wsdl.messages.mime
    ~~~~~~~~~~~~~~~~~~~~~~~

    )	urlencode)etree)
fromstring)nsxsd)serialize_object)ConcreteMessageSerializedMessage)etree_to_string)MimeContentMimeXMLMimeMultipartc                       s.   e Zd ZdejiZ fddZdd Z  ZS )MimeMessagemimec                    s   t  ||| || _d S N)super__init__	part_name)selfwsdlname	operationr   	__class__ P/home/ubuntu/webapp/venv/lib/python3.10/site-packages/zeep/wsdl/messages/mime.pyr      s   
zMimeMessage.__init__c                 C   s  || _ | jrV| j jrV| j| j jv r| j j| j }nt| j jdkr,t| j j d }ntd| j |jr<|j| _dS t	
| j|j}t	
| jjt	t	|g| _dS g }| j j D ]\}}|jrl|j|}nt	
||j}|| q^t	
| jjt	t	|| _dS )a7  Resolve the body element

        The specs are (again) not really clear how to handle the message
        parts in relation the message element vs type. The following strategy
        is chosen, which seem to work:

         - If the message part has a name and it maches then set it as body
         - If the message part has a name but it doesn't match but there are no
           other message parts, then just use that one.
         - If the message part has no name then handle it like an rpc call,
           in other words, each part is an argument.

           r   z:Multiple parts for message %r while no matching part foundN)abstractr   partslenlistvalues
ValueErrorelementbodyr   Elementtyper   r   ComplexTypeSequenceitemscloneappend)r   definitionsabstract_messagemessageelmchildrenr   r   r   r   resolve   s4   

zMimeMessage.resolve)	__name__
__module____qualname__r   MIME_nsmapr   r1   __classcell__r   r   r   r   r      s    
r   c                       s<   e Zd ZdZ fddZdd Zdd Zedd	 Z  Z	S )
r   a  WSDL includes a way to bind abstract types to concrete messages in some
    MIME format.

    Bindings for the following MIME types are defined:

    - multipart/related
    - text/xml
    - application/x-www-form-urlencoded
    - Others (by specifying the MIME type string)

    The set of defined MIME types is both large and evolving, so it is not a
    goal for WSDL to exhaustively define XML grammar for each MIME type.

    :param wsdl: The main wsdl document
    :type wsdl: zeep.wsdl.wsdl.Document
    :param name:
    :param operation: The operation to which this message belongs
    :type operation: zeep.wsdl.bindings.soap.SoapOperation
    :param part_name:
    :type type: str

    c                    s   t  |||| || _d S r   )r   r   content_type)r   r   r   r   r8   r   r   r   r   r   a   s   
zMimeContent.__init__c                 O   s~   | j |i |}d| ji}d}| jdkrt|}t|}n| jdkr6td}| j || tt|d }t	| j
j||dS )NzContent-Type z!application/x-www-form-urlencodedztext/xmlrootr   )pathheaderscontent)r$   r8   r   r   r   r%   renderr
   r    r	   r   location)r   argskwargsvaluer<   datar)   documentr   r   r   	serializee   s   





zMimeContent.serializec                 C   s(   t |}t| jj d }|j|S )Nr   )r   r    r   r   r!   r&   parse_xmlelementr   nodepartr   r   r   deserializev   s   zMimeContent.deserializec           	      C   sT   | d}d  }}|jd| jd}|d ur| d}| d}| |j||||}|S )Nr   zmime:content
namespacesr&   rI   getfindr6   r   )	clsr,   
xmlelementr   r   r   r8   content_nodeobjr   r   r   parse{   s   


zMimeContent.parse)
r2   r3   r4   __doc__r   rE   rJ   classmethodrT   r7   r   r   r   r   r   I   s    r   c                   @   s,   e Zd ZdZdd Zdd Zedd ZdS )	r   a  To specify XML payloads that are not SOAP compliant (do not have a SOAP
    Envelope), but do have a particular schema, the mime:mimeXml element may be
    used to specify that concrete schema.

    The part attribute refers to a message part defining the concrete schema of
    the root XML element. The part attribute MAY be omitted if the message has
    only a single part. The part references a concrete schema using the element
    attribute for simple parts or type attribute for composite parts

    :param wsdl: The main wsdl document
    :type wsdl: zeep.wsdl.wsdl.Document
    :param name:
    :param operation: The operation to which this message belongs
    :type operation: zeep.wsdl.bindings.soap.SoapOperation
    :param part_name:
    :type type: str

    c                 O   s   t  r   )NotImplementedError)r   r@   rA   r   r   r   rE      s   zMimeXML.serializec                 C   s0   t |}tt| jj d }|j|| jj	S r   )
r   nextiterr   r   r!   r#   rT   r   typesrG   r   r   r   rJ      s   zMimeXML.deserializec                 C   sD   | d}d }|jd| jd}|d ur| d}| |j|||}|S )Nr   zmime:mimeXmlrK   rI   rM   )rP   r,   rQ   r   r   r   rR   rS   r   r   r   rT      s   

zMimeXML.parseN)r2   r3   r4   rU   rE   rJ   rV   rT   r   r   r   r   r      s    r   c                   @   s   e Zd ZdZdS )r   a  The multipart/related MIME type aggregates an arbitrary set of MIME
    formatted parts into one message using the MIME type "multipart/related".

    The mime:multipartRelated element describes the concrete format of such a
    message::

        <mime:multipartRelated>
            <mime:part> *
                <-- mime element -->
            </mime:part>
        </mime:multipartRelated>

    The mime:part element describes each part of a multipart/related message.
    MIME elements appear within mime:part to specify the concrete MIME type for
    the part. If more than one MIME element appears inside a mime:part, they
    are alternatives.

    :param wsdl: The main wsdl document
    :type wsdl: zeep.wsdl.wsdl.Document
    :param name:
    :param operation: The operation to which this message belongs
    :type operation: zeep.wsdl.bindings.soap.SoapOperation
    :param part_name:
    :type type: str

    N)r2   r3   r4   rU   r   r   r   r   r      s    r   N)rU   urllib.parser   lxmlr   
lxml.etreer   zeepr   r   zeep.helpersr   zeep.wsdl.messages.baser   r	   zeep.wsdl.utilsr
   __all__r   r   r   r   r   r   r   r   <module>   s    5@(