o
    j                     @   s`   d Z ddlmZ ddlm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 )z5Contains the ClientBase class and its helper objects.    )MethodContext)string_encodingc                   @      e Zd Zdd Zdd ZdS )Factoryc                 C   s
   || _ d S N)_Factory__app)selfapp r
   R/var/www/html/LicenciasMiG/venv/lib/python3.10/site-packages/spyne/client/_base.py__init__   s   
zFactory.__init__c                 C   s   | j j|S r   )r   	interfaceget_class_instance)r   object_namer
   r
   r   create      zFactory.createN)__name__
__module____qualname__r   r   r
   r
   r
   r   r      s    r   c                   @   r   )RemoteServicec                 O   s(   || _ || _d | _|| _|| _|| _d S r   )_RemoteService__app_RemoteService__url
out_header	rpc_classargskwargs)r   r   urlr	   r   r   r
   r
   r   r   #   s   
zRemoteService.__init__c                 C   s(   | j | j| j|| jg| jR i | jS r   )r   r   r   r   r   r   )r   keyr
   r
   r   __getattr__+   s
   zRemoteService.__getattr__N)r   r   r   r   r   r
   r
   r
   r   r   "   s    r   c                   @   s:   e Zd ZdZdddZdd Zdd Zd	d
 Zdd ZdS )RemoteProcedureBasea  Abstract base class that handles all (de)serialization.

    Child classes must implement the client transport in the __call__ method
    using the following method signature: ::

        def __call__(self, *args, **kwargs):

    :param url:  The url for the server endpoint.
    :param app:  The application instance the client belongs to.
    :param name: The string identifier for the remote method.
    :param out_header: The header that's going to be sent with the remote call.
    Nc                 C   s6   || _ || _t| tj}||_||_|j|| _d S r   )	r   r	   r   CLIENTmethod_request_stringr   out_protocolgenerate_method_contextscontexts)r   r   r	   namer   initial_ctxr
   r
   r   r   >   s   
zRemoteProcedureBase.__init__c                 O   s   t  )zdSerializes its arguments, sends them, receives and deserializes the
        response and returns it.)NotImplementedError)r   r   r   r
   r
   r   __call__I   s   zRemoteProcedureBase.__call__c           	      C   s   |j du sJ |jj}|j}| }tt|D ]}|t|k r,t|| | ||  qt|| | d q|D ]}||v rGt||||  q9t||_ dS )zSerializes the method arguments to output document.

        :param args: Sequential arguments.
        :param kwargs: Name-based arguments.
        N)	
out_object
descriptor
in_message
_type_inforangelensetattrkeyslist)	r   ctxr   r   request_raw_classrequest_type_inforequest_rawikr
   r
   r   get_out_objectO   s   z"RemoteProcedureBase.get_out_objectc                 C   s   |j du sJ |jdu sJ |j||jj |jdu r"|d n|d |j|t |jdu r9|d n|d |jdu rIdg|_dS dS )z/Serializes the output document to a bytestream.Nmethod_return_documentmethod_exception_documentmethod_return_stringmethod_exception_string )	out_document
out_stringr"   	serializeREQUEST	out_error
fire_eventcreate_out_stringr   )r   r2   r
   r
   r   get_out_stringh   s   




z"RemoteProcedureBase.get_out_stringc                 C   s   |j dusJ |jdu sJ | jj| |d | jjj|| jjjd | jjj|| jjjd |j	j
j}t|j	j
jdkrP| d }t|j|d|_dS dS )zmDeserializes the response bytestream first as a document and then
        as a native python object.
        Nmethod_accept_document)message   r   )	in_stringin_documentr	   in_protocolcreate_in_documentrC   decompose_incoming_envelopeRESPONSEdeserializer*   out_messager,   r.   r0   getattr	in_object)r   r2   	type_infowrapper_attributer
   r
   r   get_in_object   s   



z!RemoteProcedureBase.get_in_objectr   )	r   r   r   __doc__r   r(   r8   rE   rU   r
   r
   r
   r   r   0   s    
r   c                   @   s    e Zd ZdZdd Zdd ZdS )
ClientBasezThe base class for all client applications. ``self.service`` attribute
    should be initialized in the constructor of the child class.
    c                 C   s   t || _d S r   )r   factory)r   r   r	   r
   r
   r   r      r   zClientBase.__init__c                 K   sL   d|v rd|v rt d|dd| j_| jjdu r$|dd| j_dS dS )zSets call options.

        :param out_header:  Sets the header object that's going to be sent with
                            the remote procedure call.
        :param soapheaders: A suds-compatible alias for out_header.
        soapheadersr   zOyou should specify only one of "soapheaders" or "out_header" keyword arguments.N)
ValueErrorgetservicer   )r   r   r
   r
   r   set_options   s   zClientBase.set_optionsN)r   r   r   rV   r   r]   r
   r
   r
   r   rW      s    rW   N)
rV   spyne.contextr   spyne.model.primitiver   objectr   r   r   rW   r
   r
   r
   r   <module>   s   j