o
    j4                     @   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 d dlmZmZmZ d dlmZ d dlmZ G d	d
 d
eZG dd deeZdS )    )print_functionN)isgenerator)E)	ModelBaseComplexModelBaseArray)	coroutineBreak	urlencode)oset)HtmlTableBasec                   @   s$   e Zd Zdd Zdd Zdd ZdS )HtmlColumnTableRowProtocolc                 K      dS )NF selfctxclsparentnamekwargsr   r   `/var/www/html/LicenciasMiG/venv/lib/python3.10/site-packages/spyne/protocol/html/table/column.pycolumn_table_gen_header$      z2HtmlColumnTableRowProtocol.column_table_gen_headerc                 K      d S Nr   r   r   r   instr   r   r   r   r   r   column_table_before_row'   r   z2HtmlColumnTableRowProtocol.column_table_before_rowc                 K   r   r   r   r   r   r   r   column_table_after_row*   r   z1HtmlColumnTableRowProtocol.column_table_after_rowN)__name__
__module____qualname__r   r   r   r   r   r   r   r   #   s    r   c                       s   e Zd ZdZ fddZ	dddZe		ddd	Zd
d Zedd Z		dddZ
 fddZdd Zdd Zdd Zdd Z  ZS )HtmlColumnTablea_  Protocol that returns the response object as a html table.

    Returns one record per table row in a table that has as many columns as
    field names, just like a regular spreadsheet.

    This is not quite unlike the HtmlMicroFormatprotocol, but returns data
    as a html table using the <table> tag.

    Generally used to serialize Array()'s of ComplexModel objects. If an
    array has prot=HtmlColumnTable, its serializer (what's inside the Array( ))
    must implement HtmlColumnTableRowProtocol interface.

    :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="">
    :param mrpc_delim_text: The text that goes between mrpc sessions.
    c                    s^   | dd }tt| j|i | | jt| jt| j	t
| ji |d ur-| jd| d S d S )Nbefore_table)popsuperr#   __init__serialization_handlersupdater   model_base_to_parentr   complex_model_to_parentr   array_to_parentevent_manageradd_listener)r   argsr   r$   	__class__r   r   r'   P   s   zHtmlColumnTable.__init__Fc           
      K   s^   d}|d ur|  ||}|r(i }	| |	|| |ttj|fi |	 d S || d S )N )
to_unicodeadd_field_attrswriter   trtd)
r   r   r   r   r   r   from_arrr   inst_strtd_attrsr   r   r   r*   ^   s   "z$HtmlColumnTable.model_base_to_parentNc                 k   s~   |d u rd S t d| d}	| jd ur#tj| jfi ddi}	d|	_|d | |D ]\}
}| |}|j	rDt d|
|| q/zt
||
d }W n   d }Y |j}|d u r\|
}| jd urw|d u rnd|| j|f }n	d	||| j|f }t d
||| i }| ||jp|
| |jr| |d |d|J | j|||||f||d|}t|rz
	 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 sw   Y  q/|jj}|d urt|dkrddi}|d| d}| |||D ]u\}}|rd}n|	d ur*|d ||	 i }| |D ] \}
}t
|jdd rP| |t
||
d }|d urP|||
< q1t|}|jjj}|t | !ddd }|"|j#|j$% }|tj&|fdd||f iddi qW d    n	1 sw   Y  t d| | j'|||||fd|i| W d    d S 1 sw   Y  d S )NzGenerate row for %rr2   classzmrpc-delimiter r6   z%	Exclude table cell %r type %r for %rz%s%s%sz
%s[%d]%s%sz&	Generate table cell %r type %r for %rdisplay:Noner7   )r8   array_indexTr   	mrpc-cellFprimary_key}   hrefz%s?%szmrpc-operationzGenerate row for %r done.r>   )(loggerdebugmrpc_delim_textr   spantailelementsort_fieldsget_cls_attrsexcgetattrsub_name
hier_delimr4   hidden	add_style	to_parentr   sendr	   throwStopIteration
Attributesmethodslen_methodsr5   r3   r
   app	interfacemethod_descriptor_id_to_keyidrsplit	translatelocale
in_messageget_type_nameaextend_data_row)r   r   r   r   r   r   r8   r>   r   mrpc_delim_eltkvcls_attr	sub_valuerO   r:   retsv2bmfirstmnmdpdrparamsmdid2keyrD   textr   r   r   _gen_rown   s   









$zHtmlColumnTable._gen_rowc              	   C   s|  t d| |d |d t|trp| |}|D ]3\}}| |}|jr+qi }	| |	|| |j	r=| 
|	d | ||j|}
|tj|
fi |	 q|jj}|d urot|dkroddi}	|tjdi |	 ni }	| |	|| | ||j|}
|tj|
fi |	 | |||| W d    n1 sw   Y  W d    d S W d    d S 1 sw   Y  d S )	NzGenerate header for %rtheadr6   r=   r   r;   r?   r   )rE   rF   rJ   
issubclassr   rK   rL   rM   r4   rQ   rR   trcra   r5   r   thrW   rX   rY   extend_header_row)r   r   r   r   r   ftirg   rh   ri   th_attrsheader_namern   r   r   r   
_gen_thead   s:   


"zHtmlColumnTable._gen_theadc                 k   s   t d| | |}i }	t }
| jd ur|
| j | jd ur=| jd ur)| jn| }| jdkr8|
| n||	| j< d	|
|	d< | j
d urN| j
|	d< | jjd|||||fd| i| |d|	 | j}|jdu rq|j}|rd}| ||}|d ur|||||}|s| |||| |d	R ||||||fi |}t|rz
	 d V }|| q ty } zz|| W n	 ty   Y nw W Y d }~nd }~ww | j||||fi | W d    n1 sw   Y  W d    d S W d    d S 1 sw   Y  d S )
NzGenerate table for %rr;   r<   widthr$   prottableFtbody)rE   rF   rL   r   table_classaddtable_name_attr
table_namerc   jointable_widthr-   
fire_eventrJ   headerget_subprotr   r   r   rT   r	   rU   rV   extend_table)r   r   r   r   r   r   gen_rowsr   	cls_attrsattribr   tnwrite_headerrk   subprotrl   rm   r   r   r   
_gen_table   sv   










$zHtmlColumnTable._gen_tablec                 K   s<   |r| j |||||fi |S | j|||||| j fi |S r   )rw   
wrap_table)r   r   r   r   r   r   r8   r   r   r   r   r+   2  s
   z'HtmlColumnTable.complex_model_to_parentc              	      s$   | j |||||tt| jfi |S r   )r   r&   r#   r,   r   r0   r   r   r,   <  s
   
zHtmlColumnTable.array_to_parentc                 K   s   | j ||||||fi |S r   )r   )r   r   r   r   r   r   r   r   r   r   r   r   @  s   zHtmlColumnTable.wrap_tablec                 K   r   )zThis is called as the last operation during the table body generation
        after all the <tr> tags are generated before exiting the <table> tag
        which in turn is inside a <tbody> tag.Nr   r   r   r   r   r   C      zHtmlColumnTable.extend_tablec                 K   r   )zThis is called as the last operation during the row generation
        after all the <td> tags are generated before exiting the <tr> tag which
        in turn is inside a <tbody> tag.Nr   r   r   r   r   re   H  r   zHtmlColumnTable.extend_data_rowc                 K   r   )zThis is called once as the last operation during the table header
        generation after all the <th> tags are generated before exiting the <tr>
        tag which in turn is inside a <thead> tag.Nr   r   r   r   r   r|   M  r   z!HtmlColumnTable.extend_header_row)F)FN)r    r!   r"   __doc__r'   r*   r   rw   r   r   r+   r,   r   r   re   r|   __classcell__r   r   r0   r   r#   /   s&     
g$
8

r#   )
__future__r   logging	getLoggerr    rE   inspectr   lxml.html.builderr   spyner   r   r   
spyne.utilr   r	   r
   spyne.util.osetr   spyne.protocol.html.tabler   objectr   r#   r   r   r   r   <module>   s   
