o
    jc=                     @   s   d dl Z d dlZedZd dlmZ d dlmZ d dlmZmZ d dl	m
Z
 daG dd	 d	e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G dd deZdS )    Nspyne)time)copy)dequedefaultdict)constg        c                   @   s   e Zd ZdZdd ZdS )AuxMethodContextzCGeneric object that holds information specific to auxiliary methodsc                 C   s   || _ 	 || _d S N)parenterror)selfr
   r    r   M/var/www/html/LicenciasMiG/venv/lib/python3.10/site-packages/spyne/context.py__init__#   s   zAuxMethodContext.__init__N__name__
__module____qualname____doc__r   r   r   r   r   r   !   s    r   c                   @   "   e Zd ZdZdddZdd ZdS )TransportContextz@Generic object that holds transport-specific context informationNc                 C   s:   || _ 	 || _	 || _	 |j| _d | _	 d | _	 d| _d S )N )r
   itselftypeapprequest_encodingremote_addrsessidr   r
   	transportr   r   r   r   r   -   s   zTransportContext.__init__c                 C   s   dS )zRReturns None when not applicable, otherwise returns
        :class:`spyne.Address`Nr   r   r   r   r   get_peerC   s   zTransportContext.get_peerr	   )r   r   r   r   r   r!   r   r   r   r   r   +   s    
r   c                   @   r   )ProtocolContextz?Generic object that holds protocol-specific context informationNc                    s4    _ 	 _	 _	 t fdd_d S )Nc                      s     S r	   )	__class__r   r
   r   r   r   r   r   <lambda>X   s    z*ProtocolContext.__init__.<locals>.<lambda>)r
   r   r   r   _subctxr   r   r$   r   r   L   s   
zProtocolContext.__init__c                 C   s
   | j | S r	   )r&   )r   itemr   r   r   __getitem__Z   s   
zProtocolContext.__getitem__r	   )r   r   r   r   r   r(   r   r   r   r   r"   J   s    
r"   c                   @   s   e Zd ZdZdddZdS )EventContextz<Generic object that holds event-specific context informationNc                 C   s   || _ || _d S r	   )r
   event_id)r   r
   r*   r   r   r   r   `   s   
zEventContext.__init__r	   r   r   r   r   r   r)   ^   s    r)   c                   @   s   e Zd ZdZedefi Zedefi ZeZdZ	dd Z
dd Zed	d
 Zdd Zdd Zdd ZeeeZ	 edd Zdd Zdd Zdd Zdd Zdd ZeeeZdd Zdd  ZeeeZd!S )"MethodContextzThe base class for all RPC Contexts. Holds all information about the
    current state of execution of a remote procedure call.
    SERVERCLIENTFc                 C   sf   t | }|jd ur||j_|jd ur||j_|jd ur||j_|jd ur(||j_|jd ur1||j_|S r	   )r   r   r
   
inprot_ctxoutprot_ctxeventaux)r   retvalr   r   r   r   p   s   




zMethodContext.copyc                 O   sZ   | j jj|| g|R i | | j}|d ur)|jD ]}|j|| g|R i | qd S d S r	   )r   event_manager
fire_event
descriptorevent_managers)r   r0   argskwargsdescevmgrr   r   r   r4      s   
zMethodContext.fire_eventc                 C   s   | j du rdS | j jS )z\The public name of the method the ``method_request_string`` was
        matched to.
        N)r5   namer    r   r   r   method_name   s   
zMethodContext.method_namec                 C   s  t  | _	 d | _	 d| _	 |j| _	 d | _	 d | _	 | jd ur&| | || _d | _	 | jj	d ur9| jj	
| || _d | _	 | jjd urL| jj
| || _d | _	 |tju rZ| j| _n|tju rd| j| _nt|t| | _	 d | _	 d | _	 g | _	 d| _	 d | _d | _	 d | _	 d | _	 d | _	 d | _	 d | _	 d | _	 d | _ 	 d | _!	 d | _"	 d | _#	 d | _$	 d | _%	 d | _&	 d | _'	 d | _(	 d | _)	 |jj| _*	 |jj	| _+	 g | _,	 d| _-	 | .d d S )NFTmethod_context_created)/r   
call_startcall_end	is_closedr   udcr   r   r/   out_protocolget_contextr.   in_protocolprotocolr+   r,   r-   
ValueErrorr)   r0   r1   method_request_stringfilesactive_MethodContext__descriptor	in_stringin_documentin_header_docin_body_docin_error	in_header	in_object
out_object
out_header	out_errorout_body_docout_header_docout_document
out_string
out_streamfunctionlocale_in_protocol_out_protocolpusher_stackfrozenr4   )r   r   wayr   r   r   r      s   







zMethodContext.__init__c                 C      | j S r	   )rJ   r    r   r   r   get_descriptorS     zMethodContext.get_descriptorc                 C   s   || _ |j| _d S r	   )rJ   rZ   )r   r5   r   r   r   set_descriptorV  s   zMethodContext.set_descriptorc                 C   s   | j d ur	| j jS d S r	   )r5   service_classr    r   r   r   re   b  s   
zMethodContext.service_classc                 C   s2   | j r|| jv s|dv rt| || d S td)N)r5   rB   zCuse the udc member for storing arbitrary data in the method context)r_   __dict__object__setattr__rF   )r   kvr   r   r   rh   g  s
   zMethodContext.__setattr__c                 C   s   t  }| j D ]?\}}t|tr>t dg}t| D ]\}}|d||f  q|d d|}|d||f  q|d||f  q|d d| jj	d	d
|dfS )N{z			%r: %r,z	}
z
	%s=%sz
	%s=%rz
)r   (z, ))
r   rf   items
isinstancedictsortedappendjoinr#   r   )r   r2   ri   rj   retk2v2r   r   r   __repr__o  s   




zMethodContext.__repr__c                 C   sz   t  | _| jjd|  | jD ]}|  qd| _t  }|t t	j
kr;t  t  | }|atdt|dd  d S d S )Nmethod_context_closedTzgc.collect() took around %dms.   i  )r   r?   r   r3   r4   rH   closer@   _LAST_GC_RUNr   MIN_GC_INTERVALgccollectloggerdebuground)r   ftdtr   r   r   r{     s   


zMethodContext.closec                 C   s(   || _ | j jd u r| j | j d S d S r	   )r]   r   set_appr   whatr   r   r   set_out_protocol  s   zMethodContext.set_out_protocolc                 C   ra   r	   )r]   r    r   r   r   get_out_protocol  rc   zMethodContext.get_out_protocolc                 C   s   || _ | j| j _d S r	   )r\   r   r   r   r   r   set_in_protocol  s   zMethodContext.set_in_protocolc                 C   ra   r	   )r\   r    r   r   r   get_in_protocol  rc   zMethodContext.get_in_protocolN)r   r   r   r   r   rg   r,   r-   r   r_   r   r4   propertyr<   r   rb   rd   r5   re   rh   rx   r{   r   r   rB   r   r   rD   r   r   r   r   r+   e   s6    

 A


r+   c                   @   s   e Zd Z				dddZdS )FakeContextNc                 C   s   || _ || _|| _|| _|| _|| _|| _|	| _|| _|
| _	|| _
|| _|| _| jd ur5| j| d | _n	tdtfi  | _ddlm} | jd urR| j| d | _n|| d | _| j| _tdtfi  | _d S )Nr"   r   )HtmlClothProtocolContext)r   r5   rP   rQ   rO   rL   rK   rT   rR   rW   rX   rD   rB   rC   r.   r   rg   spyne.protocol.html._baser   r/   rE   r   )r   r   r5   rP   rQ   rO   rL   rK   rR   rT   rW   rX   rD   rB   r   r   r   r   r     s,   

zFakeContext.__init__)NNNNNNNNNNNNN)r   r   r   r   r   r   r   r   r     s    r   )r~   logging	getLoggerr   r   r   collectionsr   r   r   r   r|   rg   r   r   r"   r)   r+   r   r   r   r   r   <module>   s   

  I