o
    iZ                     @   s   d Z ddlZeeZddlZddlm  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mZ ddlmZ ed	Ze	je Zd
ZdZdd ZG dd deZdS )zThe ``spyne.interface.wsdl.wsdl11`` module contains an implementation of a
subset of the Wsdl 1.1 document standard and its helper methods.
    N)six)etree)E)
SubElement)WSDL11XSDNS_WSAPLINK)	XmlSchemaz	[.?]wsdl$InHeaderMsgOutHeaderMsgc              
   C   s   t | jdkr|jd u rtd|j |jd ur#t | jdkr#tdz|jd ur3| j|j}W d S W d S  tyE } ztdd }~ww )Nr   z
            A port must be declared in the RPC decorator if the service
            class declares a list of ports

            Method: %r
            z
            The rpc decorator has declared a port while the service class
            has not.  Remove the port declaration from the rpc decorator
            or add a list of ports to the service class
            z
            The port specified in the rpc decorator does not match any of
            the ports defined by the service class
            )len__port_types__	port_type
ValueErrornameindex)servicemethodr   e r   [/var/www/html/LicenciasMIG/venv/lib/python3.10/site-packages/spyne/interface/wsdl/wsdl11.pycheck_method_port/   s   
r   c                       s   e Zd ZdZ		d# fdd	Zdd Zd	d
 Zdd Zdd Zdd Z	dd Z
dd Zdd Zdd Zdd Zdd Zdd Zdd  Zd!d" Z  ZS )$Wsdl11a  The implementation of the Wsdl 1.1 interface definition document
    standard which is avaible here: http://www.w3.org/TR/wsdl

    :param app: The parent application.
    :param _with_partnerlink: Include the partnerLink tag in the wsdl.

    Supported events:
        * document_built:
            Called right after the document is built. The handler gets the
            ``Wsdl11`` instance as the only argument. Also called by XmlSchema
            class.

        * wsdl_document_built:
            Called right after the document is built. The handler gets the
            ``Wsdl11`` instance as the only argument. Only called from this
            class.
    NF	qualifiedc                    sH   t t| j||d || _|| _i | _i | _d | _d | _d | _	d | _
d S )N)element_form_default)superr   __init___with_plinkxsl_hrefport_type_dictservice_elt_dictroot_eltservice_elt_Wsdl11__wsdlvalidation_schema)self	interfacer   _with_partnerlinkr   	__class__r   r   r   _   s   

zWsdl11.__init__c                 C   s   |S Nr   )r&   port_type_namer   r   r   _get_binding_namep   s   zWsdl11._get_binding_namec                 C   F   d}|| j vrt| jtd}|d| || j |< |S | j | }|S )z Creates a wsdl:portType element.NportTyper   )r    r   r"   r   set)r&   pt_nameptr   r   r   _get_or_create_port_types   s   


zWsdl11._get_or_create_port_typec                 C   r.   )zBuilds a wsdl:service element.Nr   r   )r!   r   r"   r   r0   )r&   service_nameserr   r   r   _get_or_create_service_node   s   


z"Wsdl11._get_or_create_service_nodec                 C   s   | j S r+   )r$   )r&   r   r   r   get_interface_document   s   zWsdl11.get_interface_documentc                 C   s  |    td|| _| j }tjtd| jj	d | _
}| jdurItjtdtd| jddd	d
dd dd }td|}| j
| | | _|d| jj |d| t|td}| j D ]}|| qht }| jjD ]	}| ||| qw| jrt|td}	|	d| | ||	 | jjD ]}| s| |  | q| jjD ]}| s| !||||| j qd}
| jjD ]}| s| "||||
}
q| jj#j$du rt%d| j&'d|  | j&'d|  tj| jddd| _(dS )z#Build the wsdl for the application. definitions)nsmapNdummyztext/xsl)typehrefunicode)encoding    zxml-stylesheettargetNamespacer   typespartnerLinkTypezJYou must set the 'transport' property of the parent 'Application' instancedocument_builtwsdl_document_builtTzUTF-8)xml_declarationr?   ))build_schema_nodes
REGEX_WSDLsuburlr'   get_namer   Elementr   r:   r"   r   tostringdictsplitProcessingInstructionaddpreviousgetroottree	root_treer0   tnsr   schema_dictvaluesappendservicesadd_messages_for_methodsr   r	   _Wsdl11__add_partner_linkis_auxiliaryr6   _get_applied_service_nameadd_port_typeadd_bindings_for_methodsapp	transport	Exceptionevent_manager
fire_eventr$   )r&   rM   r4   rootpitextpirE   smessagesplink
cb_bindingr   r   r   build_interface_document   sj   






zWsdl11.build_interface_documentc                 C   s   | j j}| j |}t|td}|d| t|td}|dd||f  |  rNt|td}|dd|  t|td}|dd||f  dS dS )z)Add the partnerLinkType node to the wsdl.roler   r/   %s:%s
%sCallbackz%s:%sCallbackN)r'   rW   get_namespace_prefixr   r	   r0   _has_callbacks)r&   r4   rl   ns_tnspref_tnsro   plink_port_typer   r   r   __add_partner_link   s   
zWsdl11.__add_partner_linkc                 C   sl   | j | j j}t|td}|d| |dd||f  t|t| j jj	j
d}|d| j dS )z- Builds a wsdl:port for a service and bindingportr   bindingrp   addresslocationN)r'   rr   rW   r   r   r0   nsget_binding_nsrb   in_protocolr<   rM   )r&   r   	port_namebinding_nameru   	wsdl_portaddrr   r   r   _add_port_to_service   s   zWsdl11._add_port_to_servicec                 C   s    | j jD ]	}| r dS qdS )NTF)r'   r[   rs   )r&   rj   r   r   r   rs      s
   zWsdl11._has_callbacksc                 C   s@   |  d u rt| jjdkr|  }|S | }|S |  }|S )NrA   )get_service_namer   r'   r[   rN   get_service_class_name)r&   r   retvalr   r   r   r_     s   z Wsdl11._get_applied_service_namec              	   C   s  |  |||||}| |}g }| }	t|	dkr7|	D ]}
| |
}|d|
 | |
}||
|f qn| |}|d| | |}|||f |j	 D ]}t
|| |jret|td}nt|td}|d|j |jd ur|ttd|j |d|j  t|td}|d|j  |d|j| j |js|jst|td}|d|j  |d|j| j |jd ur|jD ]!}t|td	}|d|  |dd
|| j| f  qqS| j| }|D ]\}}| ||| qd S )Nr   r   	operationdocumentationparameterOrderinputmessageoutputfaultrp   )_add_callbacksr_   get_port_typesr   r3   r0   r-   rZ   public_methodsrY   r   is_callbackr   r   operation_namedocr   
in_messageget_element_nameget_element_name_nsr'   is_asyncout_messagefaultsget_type_namerr   r!   r   )r&   r   rg   r4   rE   rM   cb_port_typeapplied_service_nameport_binding_namesport_type_listr,   r   r   r   r   op_input	op_outputfr   r5   r   r   r   r   r`     sd   












zWsdl11.add_port_typec                 C   s   |d urE||vrG| | t|td}|d| t|ttfr$|}n|f}|D ]}t|td}|d|  |d|| j	 q)d S d S d S )Nr   r   partelement)
addr   r   r0   
isinstancelisttupleget_wsdl_part_namer   r'   )r&   rg   rk   objmessage_namer   objsr   r   r   r   _add_message_for_objectM  s   
zWsdl11._add_message_for_objectc              	   C   s   |j  D ]t}| |||j|j  | |||j|j  |jd urDt|jdkr4d|j	t
f}n|jd  }| |||j| |jd urit|jdkrYd|j	tf}n|jd  }| |||j| |jD ]}| ||||  qlqd S )NrA   r8   r   )r   rY   r   r   r   r   	in_headerr   joinr   _in_header_msg_suffixr   
out_header_out_header_msg_suffixr   )r&   r   rg   rk   r   in_header_message_nameout_header_message_namer   r   r   r   r\   ^  s>   



zWsdl11.add_messages_for_methodsc                    sr  j j  tj jjjtj jjj fdd}	 }t
|dkry|D ]D}t|td}|d| |dd|f  t|d}	|	dd	 |	d
j jj j D ]}
|
j|kru||
| qiq2 S  d u rt|td  d|  dd|f  t d}	|	dd	 |	d
j jj j D ]}
||
  q S )Nc                    sZ  t td}|d| j t|d}|d| j |dd t|td}|d| j  t|d}|dd	 | j}|d u rIj	}|d urt
|ttfrW|}n|f}t|d
krid| jtf}n|d  }|D ]%}	t|d}
|
dd	 |
dd|	j|f  |
d|	  qq| jsF| jsFt|td}|d| j  t|d}|dd	 | j}|d u rƈj}|d urt
|ttfr|}n|f}t|d
krd| jtf}n|d  }|D ]%}	t|d}
|
dd	 |
dd|	j|f  |
d|	  q| jd urF| jD ]'}t|td}|d|  t|d}|d|  |dd	 q| jrlt|d}|dd  |dd |dd	  | d S | jrt|d}|dd  |dd |dd	 t|d}|dd  |dd |dd	 || d S )Nr   r   
soapActionstyledocumentr   bodyuseliteralrA   r8   r   headerr   rp   r   r   r   z%s:RelatesToHeader	RelatesToz%s:ReplyToHeaderReplyToz%s:MessageIDHeader	MessageID)r   rO   r   r0   r   r   r   r   r   __in_header__r   r   r   r   r   r   r   r   rr   r'   r   r   r   r   __out_header__r   r   rZ   )r   ry   r   soap_operationr   	soap_bodyr   
in_headersr   r   soap_headerr   r   out_headersr   r   
wsdl_fault
soap_fault
relates_to	rt_header
mid_headerrm   input_binding_nsoutput_binding_nsru   r&   r   r   r   inner  s   



z.Wsdl11.add_bindings_for_methods.<locals>.innerr   ry   r   r<   rp   r   r   rc   )r'   rr   get_tnsr|   r}   rb   r~   r<   out_protocolr   r   r   r   r0   r-   rc   r   rY   r   )r&   r   rg   r4   rm   r   r   r,   ry   rc   mr   r   r   ra   {  s:   h

zWsdl11.add_bindings_for_methodsc                 C   s  | j  }d}t| j jjj}d }	| rt|t	d}
|

dd|  |

dd t|
t	d}|
dt |
d	t t|td
}|
dd t|td}|
dd |
ddt  t|td
}|
dd t|td}|
dd |
ddt  t|td
}|
dd t|td}|
dd |
ddt  t|td}	|	
dd|  d| }t|td}|
d| t|td}|
d| |
dd||f  t||d}|
d| |	S )NrW   schemarD   rq   elementFormDefaultr   import	namespaceschemaLocationr   r   RelatesToHeaderr   r   r   z%s:RelatesToReplyToHeaderr   z
%s:ReplyToMessageIDHeaderr   z%s:MessageIDr/   r   rx   ry   rp   rz   r{   )r'   r   r|   r}   rb   r~   r<   rs   r   r   r0   r   r   PREF_WSA)r&   r   rg   rE   r4   rM   rt   ru   r   r   
wsa_schemaimport_relt_message	relt_partreply_message
reply_part	id_headerid_partcb_service_name
cb_servicecb_wsdl_port
cb_addressr   r   r   r     sJ   
zWsdl11._add_callbacks)NNFr   )__name__
__module____qualname____doc__r   r-   r3   r6   r7   rn   r]   r   rs   r_   r`   r   r\   ra   r   __classcell__r   r   r)   r   r   I   s(    G= r   ) r   logging	getLoggerr   loggerrespyne.const.xmlconstxmlr|   
spyne.utilr   lxmlr   lxml.builderr   
lxml.etreer   r   r   r   r	   spyne.interface.xml_schemar
   compilerK   PREFMAPr   r   r   r   r   r   r   r   r   <module>   s"   


