o
    Ýîid  ã                   @   s~   d dl mZ d dlm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 G dd	„ d	eƒZe	eƒG d
d„ deeƒƒZdS )é    )Úwarn)ÚdefaultdictN)ÚAny)Úadd_metaclass)ÚComplexModelMeta)ÚComplexModelBasec                       s   e Zd Z‡ fdd„Z‡  ZS )Ú	FaultMetac                    sp   t t| ƒ |||¡ | dd ¡}|d ur2tj| }| | ¡ tjj	r4t
|ƒdkr6td ||¡ƒ d S d S d S d S )NÚCODEé   z.Duplicate faultcode {} detected for classes {})Úsuperr   Ú__init__ÚgetÚFaultÚ
REGISTEREDÚaddÚspyneÚconstÚWARN_ON_DUPLICATE_FAULTCODEÚlenr   Úformat)ÚselfÚcls_nameÚ	cls_basesÚcls_dictÚcodeÚtarget©Ú	__class__© úQ/var/www/html/LicenciasMIG/venv/lib/python3.10/site-packages/spyne/model/fault.pyr   "   s   

ÿüzFaultMeta.__init__)Ú__name__Ú
__module__Ú__qualname__r   Ú__classcell__r   r   r   r   r   !   s    r   c                   @   s†   e Zd ZdZeeƒZ	 d ZdZdddde	j
fdd„Zdd„ Zd	d
„ Zdd„ Zedd„ ƒZeddd„ƒZedd„ ƒZdd„ Zdd„ ZdS )r   aH  Use this class as a base for all public exceptions.
    The Fault object adheres to the
    `SOAP 1.1 Fault definition <http://www.w3.org/TR/2000/NOTE-SOAP-20000508/#_Toc478383507>`_,

    which has three main attributes:

    :param faultcode: It's a dot-delimited string whose first fragment is
        either 'Client' or 'Server'. Just like HTTP 4xx and 5xx codes,
        'Client' indicates that something was wrong with the input, and 'Server'
        indicates something went wrong during the processing of an otherwise
        legitimate request.

        Protocol implementors should heed the values in ``faultcode`` to set
        proper return codes in the protocol level when necessary. E.g. HttpRpc
        protocol will return a HTTP 404 error when a
        :class:`spyne.error.ResourceNotFound` is raised, and a general HTTP 400
        when the ``faultcode`` starts with ``'Client.'`` or is ``'Client'``.

        Soap would return Http 500 for any kind of exception, and denote the
        nature of the exception in the Soap response body. (because that's what
        the standard says... Yes, soap is famous for a reason :))
    :param faultstring: It's the human-readable explanation of the exception.
    :param detail: Additional information dict.
    :param lang: Language code corresponding to the language of faultstring.
    NÚServerÚ c                 C   s*   || _ |p|  ¡ | _|| _|| _|| _d S ©N)Ú	faultcodeÚget_type_nameÚfaultstringÚ
faultactorÚdetailÚlang)r   r'   r)   r*   r+   r,   r   r   r   r   S   s
   
zFault.__init__c                 C   s   dS )Nr
   r   ©r   r   r   r   Ú__len__[   s   zFault.__len__c                 C   s   t | ƒS r&   )Úreprr-   r   r   r   Ú__str__^   s   zFault.__str__c                 C   s:   | j d u rd| jj| j| jf S d| jj| j| j| j f S )Nz
%s(%s: %r)z%s(%s: %r detail: %r))r+   r   r    r'   r)   r-   r   r   r   Ú__repr__a   s   
ÿÿzFault.__repr__c                 C   sn   t | tƒsd| jt|ƒdœS |j|jdœ}|jd ur)t|jƒdks$|js)|j|d< |j	d ur5| 
|¡|d< |S )NúServer.Unknown)r'   r)   r+   )r'   r)   r   r*   r+   )Ú
issubclassr   r    Ústrr'   r)   r*   r   Úignore_empty_faultactorr+   Údetail_to_doc©ÚclsÚvalueÚprotÚretvalr   r   r   Úto_dicti   s   
ýþ


zFault.to_dictc                 C   sv   t | tƒsd| jdt|ƒgS |j|jg}|jd ur | |j¡ n| d¡ |jd ur4| | 	|¡¡ |S | d¡ |S )Nr2   r%   )
r3   r   r    r4   r'   r)   r*   Úappendr+   r6   r7   r   r   r   Úto_listˆ   s"   
üþ



þzFault.to_listc                 C   s   |j  d¡d|j d¡gS )NÚutf8s   

)r'   Úencoder)   )r8   r9   r   r   r   Úto_bytes_iterable£   s   

ýzFault.to_bytes_iterablec                 C   s   | j S r&   ©r+   )r   r:   r   r   r   r6   «   s   zFault.detail_to_docc                 C   s
   || _ d S r&   rB   )r   r:   Údocr   r   r   Údetail_from_doc®   s   
zFault.detail_from_docr&   )r    r!   r"   Ú__doc__r   Úsetr   Ú__type_name__r	   r   ÚDEFAULT_LANGUAGEr   r.   r0   r1   Ústaticmethodr<   r>   ÚclassmethodrA   r6   rD   r   r   r   r   r   /   s(    
ÿ

r   )Úwarningsr   Úcollectionsr   Úspyne.constr   Úspyne.model.primitiver   Úspyne.util.sixr   Úspyne.model.complexr   r   r   Ú	Exceptionr   r   r   r   r   Ú<module>   s   