o
    j                      @   s   d dl Z e eZd dlmZ d dlmZ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 d dlmZ d d	lmZ d
d ZG dd deZG dd deZeZdS )    N)defaultdict)etreehtml)E)	coroutineBreaksix)oset)dict_to_etree)XmlCloth)XmlClothProtocolContextc                 C   s$   t t|  }| | |S N)r   
fromstringopenread	getparentremove)T_FILESelt r   Y/var/www/html/LicenciasMiG/venv/lib/python3.10/site-packages/spyne/protocol/html/_base.pyparse_html_fragment_file$   s   r   c                       s   e Zd Zd fdd	Z  ZS )HtmlClothProtocolContextNc                    s\   t t| ||| g | _tt| _tt| _t | _	t
 | _t | _d | _d | _d | _d S r   )superr   __init__assetsr   listeltstackctxstackr	   	rootstacksettagsdictobjcachescreen	prev_view	next_view)selfparent	transporttype	__class__r   r   r   +   s   


z!HtmlClothProtocolContext.__init__r   )__name__
__module____qualname__r   __classcell__r   r   r+   r   r   *   s    r   c                       s   e Zd ZdZ				d3 f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edd Zedd Zed4ddZd5d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d/d0 Zd1d2 Z  ZS )6	HtmlClothztext/html; charset=UTF-8Nutf8FT.c                    s8   t t| j|||||||||	d	 |
| _|| _d| _d S )N)	appencoding	mime_typeignore_uncapignore_wrappersclothcloth_parserpolymorphicstrip_commentsr   )r   r1   r   
hier_delimdoctypedefault_method)r'   r4   r5   r6   r7   r8   r9   r:   r;   r<   r=   r>   r+   r   r   r   >   s   
zHtmlCloth.__init__c                 C   s&   |d u rt  }t j||d}| S )N)parser)r   
HTMLParserparsegetroot)r'   	file_namer:   r9   r   r   r   _parse_fileM   s   zHtmlCloth._parse_filec                 O   s   t d|| tj|i |S )NzStarting file with %r %r)loggerdebugr   htmlfile)r'   argskwargsr   r   r   docfileT   s   zHtmlCloth.docfilec                 C   s
   t ||S r   )r   )r'   r(   r)   r   r   r   get_contextX   s   
zHtmlCloth.get_contextc                 C      | j jS r   )
Attributes_html_clothclsr   r   r   get_class_cloth[      zHtmlCloth.get_class_clothc                 C   rM   r   )rN   _html_root_clothrP   r   r   r   get_class_root_cloth_   rS   zHtmlCloth.get_class_root_clothc                 K   s   | t| d S r   )writereprr'   ctxrQ   instr(   namerJ   r   r   r   dict_to_parentc   s   zHtmlCloth.dict_to_parentc                 C   s2   | |v rd |dd|f|| < d S ||| < d S )N class )joinget)	attr_name	attr_dict
class_namer   r   r   add_html_attrf   s
   zHtmlCloth.add_html_attrc                 C   s4   |  dd }|d urd||| d< d S || d< d S )Nstyle;)ra   r`   )rc   datarf   r   r   r   	add_stylen   s   zHtmlCloth.add_stylec                 C   s   |  dd dd ddS )N[r_   ]r3   __)replace)sr   r   r   selsafex   s   zHtmlCloth.selsafec           
      k   s    | |}||I | j||||fddi|}|d urDz
	 d V }	||	 q  tyC   z|t  W n	 ty@   Y nw Y n	w W d    d S W d    d S 1 sWw   Y  d S )Nuse_nsF)get_serialization_instanceelement_write_memberssendr   throwStopIteration)
r'   rY   rQ   rZ   r(   r[   rp   rJ   retsv2r   r   r   complex_to_parent|   s0   

" zHtmlCloth.complex_to_parentc           
      C   s   |d usJ |  |}t|dd }|d u r|}d }|j}nt|dd }t|dd }|d u r0|j}|d u r7|j}|d u r=|}t|}	|d urK||	jd< |d urT||	jd< |d ur]|	| |	S )Nhrefcontenttextr^   )get_cls_attrsgetattrr|   anchor_classr   aattribappend)
r'   rQ   rZ   r[   r   	cls_attrsrz   r{   r|   retvalr   r   r   
gen_anchor   s.   




zHtmlCloth.gen_anchorc                 K   s   |  |||}|| d S r   )r   rV   )r'   rY   rQ   rZ   r(   r[   rJ   r   r   r   r   any_uri_to_parent   s   zHtmlCloth.any_uri_to_parentc           
      K   sv   t |dd }|d u r|}t |jdd }nt |dd }|d u r%t |jdd }tj|d}	|d ur4||	jd< ||	 d S )Nrz   r|   )srcalt)r~   rN   r   imgr   rV   )
r'   rY   rQ   rZ   r(   r[   rJ   rz   r|   r   r   r   r   imageuri_to_parent   s   
zHtmlCloth.imageuri_to_parentc                 K   s*   |  ||| j}|d ur|| d S d S r   )
to_unicodebinary_encodingrV   r'   rY   rQ   rZ   r(   r[   rJ   rw   r   r   r   byte_array_to_parent   s   zHtmlCloth.byte_array_to_parentc                 K   s&   |  ||}|d ur|| d S d S r   )r   rV   r   r   r   r   model_base_to_parent   s   zHtmlCloth.model_base_to_parentc                 K   s   d S r   r   rX   r   r   r   null_to_parent   s   zHtmlCloth.null_to_parentc                 K   s*   t |tjtjfrt|}|| d S r   )
isinstancer   	text_typebinary_typer   r   rV   rX   r   r   r   any_xml_to_parent   s   
zHtmlCloth.any_xml_to_parentc                 K   s`   |  |}|jrt|tst|tjst|}nt|ts$t|tjr)t|}|	| d S r   )
r}   	as_stringr   strr   r   r   tostringr   rV   )r'   rY   rQ   rZ   r(   r[   rJ   r   r   r   r   any_html_to_parent   s   


zHtmlCloth.any_html_to_parentc                 K   s   | | d S r   )rV   rX   r   r   r   any_to_parent   s   zHtmlCloth.any_to_parentc                 K   s$   t d}t|| ||d  d S )Nfoor   )r   r
   rV   )r'   rY   rQ   rZ   r(   r[   rJ   r   r   r   r   any_dict_to_parent   s   
zHtmlCloth.any_dict_to_parentc                 K   s   | j |||||fi | d S r   )ry   rX   r   r   r   fault_to_parent   s   zHtmlCloth.fault_to_parent)Nr2   NFFNNTTr3   N)Fr   )r-   r.   r/   r6   r   rE   rK   rL   staticmethodrR   rU   r\   re   ri   ro   r   ry   r   r   r   r   r   r   r   r   r   r   r   r0   r   r   r+   r   r1   ;   sD    



	

$r1   )logging	getLoggerr-   rF   collectionsr   lxmlr   r   lxml.html.builderr   
spyne.utilr   r   r   spyne.util.osetr	   spyne.util.etreeconvr
   spyne.protocol.clothr   spyne.protocol.cloth._baser   r   r   r1   HtmlBaser   r   r   r   <module>   s   
 A