o
    j\                     @   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	 dd	lm
Z
 dd
lmZ ddlmZ ddlmZmZmZ ddlmZmZmZ ddlm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S )a  The ``spyne.decorator`` module contains the the @srpc decorator and its
helper methods. The @srpc decorator is responsible for tagging methods as remote
procedure calls extracting method's input and output types.

It's possible to create custom decorators that wrap the @srpc decorator in order
to have a more elegant way of passing frequently-used parameter values. The @rpc
decorator is a simple example of this.
    N)copy)isclass)MethodDescriptor)
LogicError)BODY_STYLE_EMPTY)BODY_STYLE_WRAPPED)BODY_STYLE_BARE)BODY_STYLE_OUT_BARE)BODY_STYLE_EMPTY_OUT_BARE)	ModelBaseComplexModelComplexModelBase)TypeInforecust_selfrefSelfReference)add_request_suffixc
              	   C   sH  d}
|du r
|
d7 }
|du r|
d7 }
|d u rVz| j j}| j j|
| }W n ty/   tdw |du r?| g| }d| }t|t|krUtd| jt|t|f nt	|}t|t|krptd| jt|t|f t
 }ddlm} t||D ]0\}}zt||}W n ty   d}Y nw |r|du rtd	t||}|||}|||< q~tjjj}|d
r|dd  d\}}}d }|dkrt|dkrtdt|dkrtj|||d}n4| \}|j||d}t|tr|jstd|jtju r|||d|  ntj|||d}||_ |	r"|j|	d}|S )Nr   F   zIt's not possible to instrospect builtins. You must pass a sequence of argument names as the '_args' argument to the rpc decorator to manually denote the arguments that this function accepts.)selfz8%r function has %d argument(s) but its decorator has %d.z=%r function has %d argument(s) but the _args argument has %d.r   #SelfReference can't be used in @rpc{}barez;body_style='bare' can handle at most one function argument.	type_name	namespacememberssub_namesub_nsz5body_style='bare' does not allow empty model as paramz%s_arg0wsdl_part_name)!__code__co_argcountco_varnamesAttributeError	TypeErrornovalidate_freqlenr   __name__r   r   spyner   zip
issubclassr   getconstxml
DEFAULT_NS
startswith	partitionr   producevalues	customizer   
_type_info__type_name__r   Empty_fill_empty_type_name__namespace__)fparamsin_message_namein_variable_namesno_ctxno_selfargnamesbody_style_strself_ref_clsin_wsdl_part_name	arg_startargcount	in_paramsr   kvis_self_refns_message rN   O/var/www/html/LicenciasMiG/venv/lib/python3.10/site-packages/spyne/decorator.py_produce_input_message3   s   





rP   c                 C   s~   |  dd }|  dd }d}|d u rd}n"||vr td|f |dkr'd}n|dkr.d}n	|d u r3ntd	|dv s=J |S )
N_body_style_soap_body_style)wrappedr   out_barerS   zbody_style must be one of %rdocumentrpcr   z2soap_body_style must be one of ('rpc', 'document'))pop
ValueError)kparamsrQ   rR   allowed_body_stylesrN   rN   rO   _validate_body_style   s$   r[   c                    s  | dd}zt|t}W n ty   d}Y nw |r(|du r#tdt||}d|v}| dd tjjf }|du rJ|dksB|rJd|	 |f }| d	d}	t
 }
|r|dkrt|ttfr fd
dtt|D }| d|}t|t|ks}J t||}t
|}
n| dd tjjf }||
|< tjjj}|dr|dd d}|d }|d }|dr|dur|j||d}|jtju r||_ntj|||
d}d|j_||_|	r|j|	d}|S )zxGenerate an output message for "rpc"-style API methods.

    This message is a wrapper to the declared return type.
    _returnsNFr   _out_message_namez%s%srS   %s.%s_wsdl_part_namec                    s   g | ]}d  t jj|f qS )z%s%s%d)r*   r.   RESULT_SUFFIX).0i	func_namerN   rO   
<listcomp>   s    z+_produce_output_message.<locals>.<listcomp>_out_variable_names_out_variable_namer   r   r   r      r   r   r   Tr    ) rW   r,   r   r&   r   r   r*   r.   RESPONSE_SUFFIXget_type_namer   
isinstancelisttupleranger(   r+   r`   r/   r0   r1   r2   endswithr5   r7   r   r8   r   r3   
Attributes_wrapperr:   )rd   rB   rC   r@   rY   r\   rJ   _is_out_message_name_overriddenr]   _out_wsdl_part_name
out_paramsdefault_namesrf   var_pairrg   rK   _out_message_name_partsrM   rN   rc   rO   _produce_output_message   sl   








rx   c                 C   s   ddl m} t| D ]\}}t|r%t||r%|rtdt||| |< q
|| |< q
| D ]\}}t|rIt||rI|rAtdt||||< q.|||< q.d S )Nr   r   r   )spyne.modelr   	enumerater   r,   r   r   items)r<   rY   self_ref_replacement_no_selfr   rb   rI   rH   rN   rN   rO   _substitute_self_reference   s   

r~   c                 C   s   |  dd }|  dd }|d ur|d urtd|d ur|g}|  dd }|  dd }|d ur7|d ur7td|d ur>|g}|d urJ|d urJtd|d urP|}|d urV|S g S )N_evmgr_evmgrsz*Pass one of _evmgr or _evmgrs but not both_event_manager_event_managersz:Pass one of _event_manager or _event_managers but not bothzKYou must pass at most one of _evmgr* arguments or _event_manager* arguments)rW   r   )rY   r   r   r   r   rN   rN   rO   _get_event_managers  s"   r   c                     s   t  fdd}|S )a  Method decorator to tag a method as a remote procedure call in a
    :class:`spyne.service.Service` subclass.

    You should use the :class:`spyne.server.null.NullServer` transport if you
    want to call the methods directly. You can also use the 'function' attribute
    of the returned object to call the function itself.

    ``_operation_name`` vs ``_in_message_name``:
    Soap clients(SoapUI, Savon, suds) will use the operation name as the
    function name. The name of the input message(_in_message_name) is irrelevant
    when interfacing in this manner; this is because the clients mostly wrap
    around it. However, the soap xml request only uses the input message when
    posting with the soap server; the other protocols only use the input message
    as well. ``_operation_name`` cannot be used with ``_in_message_name``.

    :param _returns: Denotes The return type of the function. It can be a
        type or a sequence of types for functions that have multiple return
        values.
    :param _in_header: A type or an iterable of types that that this method
        accepts as incoming header.
    :param _out_header: A type or an iterable of types that that this method
        sends as outgoing header.
    :param _operation_name: The function's soap operation name. The operation
        and SoapAction names will be equal to the value of ``_operation_name``.
        Default is the function name.
    :param _in_message_name: The public name of the function's input message.
        Default is: ``_operation_name + REQUEST_SUFFIX``.
    :param _out_message_name: The public name of the function's output message.
        Default is: ``_operation_name + RESPONSE_SUFFIX``.
    :param _in_arg_names: The public names of the function arguments. It's
        a dict that maps argument names in the code to public ones.
    :param _in_variable_names: **DEPRECATED** Same as _in_arg_names, kept for
        backwards compatibility.
    :param _out_variable_name: The public name of the function response object.
        It's a string. Ignored when ``_body_style != 'wrapped'`` or ``_returns``
        is a sequence.
    :param _out_variable_names: The public name of the function response object.
        It's a sequence of strings. Ignored when ``_body_style != 'wrapped'`` or
        or ``_returns`` is not a sequence. Must be the same length as
        ``_returns``.
    :param _body_style: One of ``('bare', 'wrapped')``. Default: ``'wrapped'``.
        In wrapped mode, wraps response objects in an additional class.
    :param _soap_body_style: One of ('rpc', 'document'). Default ``'document'``.
        ``_soap_body_style='document'`` is an alias for
        ``_body_style='wrapped'``. ``_soap_body_style='rpc'`` is an alias for
        ``_body_style='bare'``.
    :param _port_type: Soap port type string.
    :param _no_ctx: Don't pass implicit ctx object to the user method.
    :param _no_self: This method does not get an implicit 'self' argument
        (before any other argument, including ctx).
    :param _udd: Short for User Defined Data, you can use this to mark the
        method with arbitrary metadata.
    :param _udp: **DEPRECATED** synonym of ``_udd``.
    :param _aux: The auxiliary backend to run this method. ``None`` if primary.
    :param _throws: A sequence of exceptions that this function can throw. This
        has no real functionality besides publishing this information in
        interface documents.
    :param _args: the name of the arguments to expose.
    :param _event_managers: An iterable of :class:`spyne.EventManager`
        instances. This is useful for adding additional event handlers to
        individual functions.
    :param _event_manager: An instance of :class:`spyne.EventManager` class.
    :param _logged: May be the string '...' to denote that the rpc arguments
        will not be logged.
    :param _evmgrs: Same as ``_event_managers``.
    :param _evmgr: Same as ``_event_manager``.
    :param _service_class: A :class:`Service` subclass. It's generally not a
        good idea to override it for ``@rpc`` methods. It could be necessary to
        override it for ``@mrpc`` methods to add events and other goodies.
    :param _service: Same as ``_service``.
    :param _wsdl_part_name: Overrides the part name attribute within wsdl
        input/output messages eg "parameters"
    c                    s"    fdd} j |_ d|_|S )Nc            )         s  | d }|  dd }d } dd} dd} dd} dd } dd } d	d }	 d
d}
 dd } dd } dg } dd } dd } dd } dd } dd } dd} dd}dv r~dv r~tddv r d}dv r d} dd}t}|  dd } dd}t|| d }dv rdv rtddv rň d}n	dv rΈ d}dv} d|}|du r|rd | |f } d!|}||kr||krtd"||krt|}d#v rd$v rtd%d#v r d#}nd$v r% d$}ni }d&v r5d'v r5td(d&v r@ d&}nd'v rK d'}ni }d)d }t}t	} | 
d*ri| d+krgt}nt}t |||
||| ||
}!t|| ||}"|dkr||!j_||"j_t d,}#|d ur|g krtd-|d ur|g}| 
d*rd.d/lm}$ |!}%|"}&t|%|$rt|%jd.krt|&|$rt|&jd.krt}nt}|d u st|tsJ t |!|"|#fi d0|d1|d2|d3|d4|d5|d6|d7|	d8|
d9|d:|d;|d<|d=|d>|d?|d@|dA|dB|dC|dD|dE|dF|dG|dH|dI|}'|d urN|rN|D ]}(|(|' qEtd.krZtdJ|'S )KN_default_function_name_service_class_is_callbackF	_is_async_mtom
_in_header_out_header
_port_type_no_ctx_aux_pattern	_patterns_args_translations_when_static_when_href_loggedT_internal_key_suffix _servicez7Please pass only one of '_service' and '_service_class'r}   _self_ref_replacement_default_on_null_faults_throwszOonly one of '_throws ' or '_faults' argumentsmust be given -- they're synonyms._in_message_namer^   _operation_namezNonly one of '_operation_name' and '_in_message_name' arguments should be given_in_arg_names_in_variable_namesz=Use either '_in_arg_names' or '_in_variable_names', not both._udd_udpz&Use either '_udd' or '_udp', not both.r_   r   rT   __doc__z@only one of '_pattern' and '_patterns' arguments should be givenr   )r   is_callbackis_asyncmtom	in_header
out_headerfaultsparent_class	port_typer?   udd	class_keyauxpatterns
body_styleargsoperation_namer@   translationswhenstatic_whenservice_classhrefinternal_key_suffixdefault_on_nullevent_managersloggedzUnknown kwarg(s) %r passed.)rW   r   r   r~   rX   rj   r   r-   r   r[   ro   r	   r   rP   rx   rp   r   getattrry   r   r,   r(   r6   r
   r   rk   rm   r   hello))kwargsfunction_namer   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r}   r   r   r   _is_in_message_name_overriddenr   r   r   r   r_   r   rB   
in_messageout_messagedocr   titoretvalp)r;   rY   r<   rN   rO   explain_method{  sD  












	


z,rpc.<locals>.explain.<locals>.explain_methodT)r   _is_rpc)r;   r   rY   r<   )r;   rO   explainz  s
    *zrpc.<locals>.explain)rl   )r<   rY   r   rN   r   rO   rV   -  s   K 0rV   c                  O      d|d< t | i |S )a  Method decorator to tag a method as a remote procedure call. See
    :func:`spyne.decorator.rpc` for detailed information.

    The initial "s" stands for "static". In Spyne terms, that means no implicit
    first argument is passed to the user callable, which really means the
    method is "stateless" rather than static. It's meant to be used for
    existing functions that can't be changed.
    Tr   rV   r<   rY   rN   rN   rO   srpc,  s   
r   c                  O   r   )NFr}   r   r   rN   rN   rO   mrpc:  s   r   )r   spyne.const.xmlr*   r   inspectr   r   r   r   r   r   r	   r
   ry   r   r   r   spyne.model.complexr   r   r   spyne.constr   rP   r[   rx   r~   r   rV   r   r   rN   rN   rN   rO   <module>   s0   	`L  