o
    iI                     @   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	 ddl
mZ ddlmZmZmZ eeZeed	 ZG d
d deZdS )z
The ``spyne.protoco.soap.soap12`` module contains the implementation of a
subset of the Soap 1.2 standard.

This modules is EXPERIMENTAL.
More info can be found at: https://www.w3.org/TR/soap12-part1/
    N)E)Soap11)_append)string_types)root_dict_to_etree)NS_SOAP12_ENVNS_XMLPREFMAPz.invalidc                   @   sx   e Zd ZdZdZee ZeZe	e
jZed ed dddZdd	 Zd
d Zdd Zdd Zdd Zdd ZdS )Soap12z
    The base implementation of a subset of the Soap 1.2 standard. The
    document is available here: http://www.w3.org/TR/soap12/
    z#application/soap+xml; charset=utf-8soap11)soapsoap12Nc                 C   s6   t d| j }|t d| j | |r|| |S )Nz{%s}Subcode	{%s}Value)r   ns_soap_envappend)selfvaluesubcodesubcode_node r   Z/var/www/html/LicenciasMIG/venv/lib/python3.10/site-packages/spyne/protocol/soap/soap12.pygenerate_subcode8   s
   
zSoap12.generate_subcodec                 C   sV   | d}|d}|dkrd| j }||fS |dkr$d| j }||fS tdt|)N.r   Clientz	%s:SenderServerz%s:ReceiverzWrong fault code, got)splitpopsoap_env	TypeErrortype)r   faultstringfaultstringsr   r   r   r   gen_fault_codes?   s   



zSoap12.gen_fault_codesc                 C   sl   |j }g }||jd|dj |jd|d}|d ur1||jd|dj |jd|d}|d usd|S )Nzsoap:Code/soap:Value
namespaceszsoap:Code/soap:Subcodez
soap:Valuezsoap:Subcoder   )nsmapr   findtextjoin)r   elementr%   	faultcoder   r   r   r   generate_faultcodeK   s   
zSoap12.generate_faultcodec           	      K   sd   t d| j }|t d| j |jfi dt |ji d |t d| j |jg}| ||||||S )N
{%s}Reasonz{%s}Textz{%s}lang{%s}Role)r   r   r   r    r   lang
faultactor_fault_to_parent_impl)	r   ctxclsinstparentns_reasonsubeltsr   r   r   fault_to_parentV   s   zSoap12.fault_to_parentc              	   K   s  t |tsJ d| j }t |jtrS| |j\}	}
td| j }|td| j |	 d}|
d d d D ]}	|r@| |	|}q5| |	}q5|dkrO|| ||d< t |j	t
rht|td| j t|j	 n|j	d u rnntdt|j	| j||||||dd	S )
Nz	{%s}Faultz{%s}Coder   Fr   z
{%s}DetailzFault detail Must be dict, got)add_type)
isinstancelistr   r*   r   r"   r   r   r   detaildictr   r   r   r   gen_members_parent)r   r1   r2   r3   r4   r5   r8   r6   tag_namer   
faultcodescodechild_subcoder   r   r   r0   c   s0   


zSoap12._fault_to_parent_implc                 K   s8   t d| j |jt d| j |jg}| ||||||S )Nr,   r-   )r   r   r    r/   r0   )r   r1   r2   r3   r4   r5   r6   r8   r   r   r   !schema_validation_error_to_parent   s   z(Soap12.schema_validation_error_to_parentc                 C   s   |j }| |}|jd|dj }|jd|d}|jd|d}|jd|d}	d}
|d ur4|
|j 7 }
|d ur?|
|j 7 }
||||
|	dS )Nzsoap:Reason/soap:Textr#   z	soap:Rolez	soap:Nodezsoap:Detail )r*   r    r/   r>   )r%   r+   r&   r'   strip)r   r1   r2   r)   r%   rC   r7   rolenoder>   r/   r   r   r   fault_from_element   s   
zSoap12.fault_from_element)N)__name__
__module____qualname____doc__	mime_typer	   r   r   r   setr   r   discardupdater   r"   r+   r9   r0   rE   rJ   r   r   r   r   r
   *   s    



$r
   )rN   logginglxml.builderr   spyne.protocol.soap.soap11r   spyne.protocol.xmlr   spyne.util.sixr   spyne.util.etreeconvr   spyne.const.xmlr   r   r	   	getLoggerrK   loggerlogger_invalidr
   r   r   r   r   <module>   s   
