o
    j                     @   s   d dl mZ d dlmZ d dlmZmZmZ d dlm	Z	 d dl
mZmZmZmZmZmZmZmZ d dlmZ G dd deZd d	lmZ ee_d
S )    )isgenerator)E)six	coroutineBreak)cdict)ArrayAnyHtmlComplexModelBase	ByteArray	ModelBasePushBaseImageUriAnyUri)HtmlBasec                       sh   e Zd Z						d fdd		Zd
d Zdd Zdd Ze	dddZedddZ	dd Z
  ZS )HtmlMicroFormatNFT<!DOCTYPE html>divclass
field_namec                    s   t t| j||||||d|d tjrt}nt}t||sJ t|	|s&J t|
|s-J |du s8t||s8J || _|	| _	|
| _
|| _|durMt|| _|| _|dur[| jd| tt| jt| jt| jt| jt| jt| jt| ji| _dS )a  Protocol that returns the response object according to the "html
        microformat" specification. See
        https://en.wikipedia.org/wiki/Microformats for more info.

        The simple flavour is like the XmlDocument protocol, but returns data in
        <div> or <span> tags.

        :param app: A spyne.application.Application instance.
        :param root_tag: The type of the root tag that encapsulates the return
            data.
        :param child_tag: The type of the tag that encapsulates the fields of
            the returned object.
        :param field_name_attr: The name of the attribute that will contain the
            field names of the complex object children.
        N)appignore_uncapignore_wrappersclothcloth_parserpolymorphic
hier_delimdoctypebefore_first_root) superr   __init__r   PY2
basestringstr
isinstanceroot_tag	child_tagfield_name_attrfield_name_tagr   _field_name_classevent_manageradd_listenerr   r   array_to_parentr   any_uri_to_parentr	   any_html_to_parentr   imageuri_to_parentr   not_supportedr   model_base_to_parentr
   complex_model_to_parentserialization_handlers)selfr   r   r   r   r   r   r   r%   r&   r'   r(   field_name_classr   	text_type	__class__ _/var/www/html/LicenciasMiG/venv/lib/python3.10/site-packages/spyne/protocol/html/microformat.pyr    "   s@   
zHtmlMicroFormat.__init__c                 K   s(   |  |||}||j| j< || d S N)
gen_anchorattribr'   write)r4   ctxclsinstparentnamekwargsretvalr9   r9   r:   anyuri_to_parent\   s   z HtmlMicroFormat.anyuri_to_parentc                 K   sz   t | jfi | j|i}| ||}| jd ur3|jj|}	| j|	fi d| ji}
||
_	|
|
 n||_|| d S )Nr   )r   r&   r'   
to_unicoder(   
Attributestranslationsgetr)   tailappendtextr>   )r4   r?   r@   rA   rB   rC   rD   rE   data_strr   r(   r9   r9   r:   r1   a   s   

z$HtmlMicroFormat.model_base_to_parentc                 K   sV   t |jddst|jjdkr| jdur|| j d|j_| j|||||fi |S )zThis is what subserialize callsdoctype_writtenF   NT)	getattroutprot_ctxlenprotocol
prot_stackr   write_doctyperO   	to_parentr4   r?   r@   rA   rB   rC   rD   r9   r9   r:   start_to_parentq   s   
zHtmlMicroFormat.start_to_parentc                 k   s   | j |i}t|jdds | jjd|||||fi | d|j_|| j|Q | j||||fddi|}	t	|	rhz
	 d V }
|	
|
 q< tyg } zz|	| W n	 ty\   Y nw W Y d }~nd }~ww W d    d S W d    d S 1 s{w   Y  d S )Nr   FTuse_ns)r'   rQ   rT   r*   
fire_eventr   elementr%   _write_membersr   sendr   throwStopIteration)r4   r?   r@   rA   rB   rC   rZ   rD   attrsretsv2er9   r9   r:   r2      s>   


" z'HtmlMicroFormat.complex_model_to_parentc                 k   s   | j |i}t|tr|j \}| }|| j| t|t	rh	 d V }	| j
|||	||fddi|}
t|
rgz
	 d V }|
| q; tyf } zz|
| W n	 ty[   Y nw W Y d }~nd }~ww q#|D ]C}	| j
|||	||fddi|}
t|
rz
	 d V }|
| q ty } zz|
| W n	 ty   Y nw W Y d }~qjd }~ww qjW d    d S 1 sw   Y  d S )NTfrom_arr)r'   
issubclassr   
_type_infovaluesget_type_namer\   r%   r$   r   rW   r   r^   r   r_   r`   )r4   r?   r@   rA   rB   rC   re   rD   ra   svrb   rc   rd   r9   r9   r:   r,      sh   




"zHtmlMicroFormat.array_to_parentc                 K   s   t | jfi | j|igS r;   )r   r&   r'   rX   r9   r9   r:   null_to_parent   s   zHtmlMicroFormat.null_to_parent)NFFNNTr   r   r   r   Nr   N)F)__name__
__module____qualname__r    rF   r1   rY   r   r2   r,   rk   __classcell__r9   r9   r7   r:   r   !   s"    :'r   )XmlClothN)inspectr   lxml.html.builderr   
spyne.utilr   r   r   spyne.util.cdictr   spyne.modelr   r	   r
   r   r   r   r   r   spyne.protocol.htmlr   r   spyne.protocol.clothrp   r9   r9   r9   r:   <module>   s   ( $
