o
    i-5                     @   s   d dl mZ d dlZeeZd dlmZ d dlmZ d dl	m
Z
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 edefi  ZG dd deZddgZdS )    )print_functionN)datetime)WeakKeyDictionary)ProtocolContextEventManager)DEFAULT_LOCALE)Array)ResourceNotFoundError)DefaultAttrDict)string_types_MISSINGc                   @   sD  e Zd ZdZedefi Zedefi Zedefi Ze	 Z	 dZ
	 dZ	 i Z	 		d8ddZdd	 Ze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edd Zedd Zd d! Zed"d# Zd$d% Zd&d' Z d(d) Z!d*d+ Z"d,d- Z#ed.d/ Z$ed0d1 Z%ed2d3 Z&ed4d5 Z'd9d6d7Z(dS ):ProtocolMixinzapplication/octet-streamSoftRequestResponseNc                 C   sr   d | _ | | || _t| | _|| _| jd u r| j| _|| _| jd u r(| j| _|d ur/|| _	t
 | _t
 | _d S N)_ProtocolMixin__appset_appignore_wrappersr   event_managerbinary_encodingdefault_binary_encodingstring_encodingdefault_string_encoding	mime_typer   
_attrcache
_sortcache)selfappr   r   r   r    r   T/var/www/html/LicenciasMIG/venv/lib/python3.10/site-packages/spyne/protocol/_base.py__init__:   s   



zProtocolMixin.__init__c                 C      |j d ur
| |S |S r   )parserr   	cls_attrsinstr   r   r    _castO      

zProtocolMixin._castc                 C   r"   r   )	sanitizerr$   r   r   r    	_sanitizeV   r(   zProtocolMixin._sanitizec                 C   *   zt |W S  ty   td|  w NInvalid value %rr   fromtimestamp	TypeErrorloggererrorr   clsvaluer   r   r    _datetime_from_sec[      z ProtocolMixin._datetime_from_secc                 C   r+   r,   r.   r3   r   r   r    _datetime_from_sec_floatb   r7   z&ProtocolMixin._datetime_from_sec_floatc                 C   s.   zt |d W S  ty   td|  w Ni  r-   r.   r3   r   r   r    _datetime_from_mseci      z!ProtocolMixin._datetime_from_msecc                 C   .   zt |d W S  ty   td|  w r9   r.   r3   r   r   r    _datetime_from_msec_floatp   r;   z'ProtocolMixin._datetime_from_msec_floatc                 C   r<   )Ng    .Ar-   r.   r3   r   r   r    _datetime_from_usecw   r;   z!ProtocolMixin._datetime_from_usecc                 C   sB   |j }|d u r
|j}|d u r|j}|d u r|j}|d u r|j}|S r   )datetime_format	dt_formatdate_format
out_formatformat)r   r%   r@   r   r   r    _get_datetime_format~   s   z"ProtocolMixin._get_datetime_formatc                 C      |j }|d u r
|j}|S r   )rA   rC   )r   r%   rA   r   r   r    _get_date_format      zProtocolMixin._get_date_formatc                 C   rE   r   )time_formatrC   )r   r%   rH   r   r   r    _get_time_format   rG   zProtocolMixin._get_time_formatc                 C   s   | j S r   r   )r   r   r   r    r      s   zProtocolMixin.appc                 C   sr   t | di }t|dkr5| jjr5| \}t| ts t ||d }| \} t | di }t|dkr5| jjs| |fS )N
_type_info   )getattrlen
Attributes_wrapperkeys
issubclassr   values)r4   r&   tikeyr   r   r    strip_wrappers   s   


	zProtocolMixin.strip_wrappersc                 C   s"   | j d u sJ d| j  || _ d S )Nz\One protocol instance should belong to one application instance. It currently belongs to: %rrJ   )r   r5   r   r   r    r      s   
zProtocolMixin.set_appc                 C   s<   t | dd }t |dd }t|d u r| n||d u r|S |S )N__orig__)rM   rR   )subr4   suborigclsorigr   r   r    rR      s   
zProtocolMixin.issubclassc                    s   t d| t| j | j d }|d ur|S t fddt jt D  | j < } jj	rK jj	| j
i }||  jj	| i }|| |S )Nz%r attrcache size: %dc                    s&   g | ]}| d s|t j|fqS )__)
startswithrM   rO   ).0kr4   r   r    
<listcomp>   s    z/ProtocolMixin.get_cls_attrs.<locals>.<listcomp>)r1   debugrN   r   getr
   dirrO   	META_ATTR
prot_attrs	__class__update)r   r4   attrr%   
inst_attrsr   r_   r    get_cls_attrs   s   

zProtocolMixin.get_cls_attrsc                 C   s
   t ||S r   )r   )r   parent	transportr   r   r    get_context   s   
zProtocolMixin.get_contextc                 C   sV   |  |}t|dkrt|jg }|D ]}|dusJ | }||_|| q|S )zGenerates MethodContext instances for every callable assigned to the
        given method handle.

        The first element in the returned list is always the primary method
        context whereas the rest are all auxiliary method contexts.
        r   N)get_call_handlesrN   r	   method_request_stringcopy
descriptorappend)r   ctxcall_handlesretvaldcr   r   r    generate_method_contexts   s   

z&ProtocolMixin.generate_method_contextsc                 C   s:   |j }|dsd| jj |f }| jjj|g }|S )a   Method to be overriden to perform any sort of custom method mapping
        using any data in the method context. Returns a list of contexts.
        Can return multiple contexts if a method_request_string matches more
        than one function. (This is called the fanout mode.)
        {z{%s}%s)ro   r\   r   	interfaceget_tnsservice_method_maprb   )r   rs   namert   r   r   r    rn      s
   
zProtocolMixin.get_call_handlesc                 C   s   | j std|  |dfS |jp|}|j|u r"td|j |dfS t||s3td|j| |dfS | |}|j|jd}|durOtd|| |dfS td||j |jdfS )	zZIf the protocol is polymorphic, extract what's returned by the user
        code.
        z%PMORPH Skipped: %r is NOT polymorphicFzFPMORPH Skipped: Instance class %r is the same as designated base classzOPMORPH Skipped: Instance class %r is not a subclass of designated base class %rNz,PMORPH OK: cls switch with polymap: %r => %rTz/PMORPH OK: cls switch without polymap: %r => %r)	polymorphicr1   ra   rW   rf   
isinstancerj   polymaprb   )r   r4   r&   orig_clscls_attrpolymap_clsr   r   r    get_polymorphic_target   s2   




z$ProtocolMixin.get_polymorphic_targetc                 C   sr   |du r	t }d}nd}| jjdu r|}d}n| jj|t}|tu r'|}d}nd}tdd||f| || |S )	Translate a class.

        :param cls: class
        :param locale: locale string
        :param default: default string if no translation found
        :returns: translated string
        Ndefault locale '%s'given locale '%s'7translated to '%s' without any translations at all with&translated to '%s': No translation fortranslated to '%s' with %r )r   rO   translationsrb   r   r1   ra   join)r4   localedefault_log_localeru   _log_trr   r   r    trc_verbose  s    
zProtocolMixin.trc_verbosec                 C   s,   |du rt }| jjdur| jj||S |S )r   N)r   rO   r   rb   )r4   r   r   r   r   r    trc=  s
   
zProtocolMixin.trcc                 C   s~   |du r	t }d}nd}| du r|}d}nt| tr| }d}n| |t}|tu r-|}d}nd}tdd	||f| || |S )
Translate from a translations dict.

        :param trdict: translation dict
        :param locale: locale string
        :param default: default string if no translation found
        :returns: translated string
        Nr   r   r   z translated to '%s' regardless ofr   r   r   r   )r   r   r   rb   r   r1   ra   r   )trdictr   r   r   ru   r   r   r   r    trd_verboseM  s&   

zProtocolMixin.trd_verbosec                 C   s2   |du rt }| du r|S t| tr| S | ||S )r   N)r   r   r   rb   )r   r   r   r   r   r    trdr  s   

zProtocolMixin.trdc                    s   t d| t| j | j|d }|d ur|S |d u r$t|| }i  |D ]\}}| |j	}|d urG|dk rCt||  |< q(| |< q(|D ]\}}| |j	}|d u r^t  |< qJ|j
 fddd || j|< |S )Nz%r sortcache size: %dr   c                    s    | d  S )Nr   r   )xindexesr   r    <lambda>  s    z+ProtocolMixin.sort_fields.<locals>.<lambda>)rU   )r1   ra   rN   r   rb   listget_flat_type_infoitemsrj   ordersort)r   r4   r   ru   r^   vr   r   r   r    sort_fields  s,   
zProtocolMixin.sort_fields)NNNNN)NN))__name__
__module____qualname__r   typeobjectSOFT_VALIDATIONREQUESTRESPONSEsetr   r   
type_attrsr!   r'   _parser*   r6   r8   r:   r=   r>   rD   rF   rI   propertyr   staticmethodrV   r   rR   rj   rm   rx   rn   r   r   r   r   r   r   r   r   r   r    r   '   s`    



"
 

$
r   nullabledefault_factory)
__future__r   logging	getLoggerr   r1   r   weakrefr   spyner   r   spyne.constr   spyne.modelr   spyne.errorr	   
spyne.utilr
   spyne.util.sixr   r   r   r   r   rd   r   r   r   r    <module>   s    
  }