o
    ix$                     @   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mZmZmZmZ d dlmZmZ d dlmZ d dlmZ G d	d
 d
eZdS )    )print_functionN)isgenerator)E)	ModelBase	ByteArrayComplexModelBaseArrayAnyUriImageUri)	coroutineBreak)cdict)HtmlTableBasec                       sJ   e Zd ZdZ fddZdddZe	dddZe fd	d
Z  Z	S )HtmlRowTablea  Protocol that returns the response object as a html table.

    The simple flavour is like the HtmlMicroFormatprotocol, but returns data
    as a html table using the <table> tag.

    Returns one record per table in a table with two columns.

    :param app: A spyne.application.Application instance.
    :param header: Boolean value to determine whether to show field
        names in the beginning of the table or not. Defaults to True. Set to
        False to skip headers.
    :param table_name_attr: The name of the attribute that will contain the
        response name of the complex object in the table tag. Set to None to
        disable.
    :param table_name: When not none, overrides what goes in `table_name_attr`.
    :param table_class: When not none, specifies what goes in `class` attribute
        in the `<table>` tag. Table name gets appended when
        `table_name_attr == 'class'`
    :param field_name_attr: The name of the attribute that will contain the
        field names of the complex object children for every table cell. Set
        to None to disable.
    :param row_class: value that goes inside the <tr class="">
    :param cell_class: value that goes inside the <td class="">
    :param header_cell_class: value that goes inside the <th class="">
    c                    sH   t t| j|i | tt| jt| jt| j	t
| jt| jt| ji| _d S N)superr   __init__r   r   model_base_to_parentr	   any_uri_to_parentr
   imageuri_to_parentr   not_supportedr   complex_model_to_parentr   array_to_parentserialization_handlers)selfargskwargs	__class__ ]/var/www/html/LicenciasMIG/venv/lib/python3.10/site-packages/spyne/protocol/html/table/row.pyr   ?   s   zHtmlRowTable.__init__Fc           	   	   K   sJ   |ri }	 |ttj| ||fi | d S || || d S r   )field_name_attrwriter   trtd
to_unicode)	r   ctxclsinstparentnamefrom_arrr   	td_attribr   r   r    r   K   s
   *z!HtmlRowTable.model_base_to_parentc                 k   s   i }| j d ur| || j < | jd ur| j|d< |d|/ |d | |D ] \}	}
| |
}|jrCtd|	|
| q-zt	||	d }W n   d }Y |
j
j}|d u r\|	}i }| jd urk| d|| j |d| i }| jd ur| d|| j | |||
 |jr| |d | jr|tj| |
|j|fi | i }| jd ur| d|| j | |||
 |jr| |d |d|J | j||
|||fi |}t|rz
	 d V }|| q ty } zz|| W n
 ty   Y nw W Y d }~nd }~ww W d    n	1 sw   Y  W d    n	1 s)w   Y  q-W d    n1 s:w   Y  W d    d S W d    d S 1 sSw   Y  d S )	Nwidthtabletbodyz%	Exclude table cell %r type %r for %rclassr#   display:Noner$   )table_name_attrget_type_nametable_widthelementsort_fieldsget_cls_attrsexcloggerdebuggetattr
Attributessub_name	row_classadd_html_attrheader_cell_classadd_field_attrshidden	add_styleheaderr"   r   thtrclocale
cell_class	to_parentr   sendr   throwStopIteration)r   r&   r'   r(   r)   r*   r+   r   attribkv	sub_attrs	sub_valuer=   tr_attrsth_attrstd_attrsretsv2br   r   r    r   V   s   








 $z$HtmlRowTable.complex_model_to_parentc                 +   s   | d` t|trQtt| j|||||fi |}t|rPz
	 d V }|| q# tyO }	 zz|	|	 W n	 t
yC   Y nw W Y d }	~	nd }	~	ww ni }
| jr[| j|i}
| jd ure| j|
d< | d|
 i }| jd urx| j|d< | d| | jr|t| ||j|  i }| jd ur| d|| j | ||| | |}|jr| |d | d|b | dL tt| j|||||fi |}t|rz
	 d V }|| q ty }	 zz|	|	 W n	 t
y   Y nw W Y d }	~	nd }	~	ww W d    n	1 sw   Y  W d    n	1 s"w   Y  W d    n	1 s2w   Y  W d    n!1 sBw   Y  W d    d S W d    d S W d    d S W d    d S 1 skw   Y  d S )	NdivTr-   r.   r0   r#   r1   r$   )r5   
issubclassr   r   r   r   r   rJ   r   rK   rL   r2   r4   r>   rD   r"   r   rE   rF   rG   r3   rH   r?   rA   r7   rB   rC   )r   r&   r'   r(   r)   r*   r   rU   rV   rW   table_attrib	tr_attribrT   	cls_attrsr   r   r    r      s   













  $zHtmlRowTable.array_to_parent)F)
__name__
__module____qualname____doc__r   r   r   r   r   __classcell__r   r   r   r    r   $   s    
Gr   )
__future__r   logging	getLoggerr]   r9   inspectr   lxml.html.builderr   spyner   r   r   r   r	   r
   
spyne.utilr   r   spyne.util.cdictr   spyne.protocol.html.tabler   r   r   r   r   r    <module>   s   
 