o
    jl                     @   s   d Z ddlmZ ddlZeeZddlZddlm	Z	 ddl
mZ ddlmZ ejr1ddlmZ nddlmZ dd	 ZG d
d deZdS )zThe ``spyne.protocol.csv`` package contains the Csv output protocol.

This protocol is here merely for illustration purposes. While it is in a
somewhat working state, it is not that easy to use. Expect a revamp in the
coming versions.
    )absolute_importN)ComplexModelBase)six)HierDictDocument)StringIOc                 c   s   |j jj \}t }|j \}t|tr'||}dd | |D }n|	 |i}t
| }|jd urgtj|tjd}|dg |jd ur[|j|jD ]}||g qR| V  |d d S tj|tj|d}| jri }	|D ]}
||
 }| ||j|
|	|
< qw||	 | V  |d |jd d ur|jd D ]5}| ||t }tjr|D ]}
t||
 tr||
 d||
< q|| | }|V  |d qd S d S )Nc                 S   s   g | ]\}}|qS  r   ).0k_r   r   R/var/www/html/LicenciasMiG/venv/lib/python3.10/site-packages/spyne/protocol/csv.py
<listcomp>5   s    z#_complex_to_csv.<locals>.<listcomp>)dialectz Error in generating the documentr   )r   
fieldnamesutf8) 
descriptorout_message
_type_infovaluesr   
issubclassr   get_flat_type_infosort_fieldsget_type_namelistkeys	out_errorcsvwriterexcelwriterowto_bytes_iterablegetvaluetruncate
DictWriterheadertrclocale
out_object_to_dict_valuesetr   PY2
isinstanceunicodeencode)protctxclsqueue
serializer	type_infor   r   rtitlesr	   vdyvalr   r   r   _complex_to_csv,   sP   








r8   c                	       sp   e Zd ZdZdZeejZed ddddde	dddf	 fdd	Z
dd	 Zd
d Zdd Z fddZ  ZS )Csvztext/csvTr   NFc
           
   
      s*   t t| j||||||||d |	| _d S )N)app	validator	mime_typeignore_uncapignore_wrappers
complex_asorderedpolymorphic)superr9   __init__r#   )
selfr:   r;   r<   r=   r>   r?   r@   rA   r#   	__class__r   r   rC   g   s   
zCsv.__init__c                 C   s   t  N)NotImplementedErrorrD   r.   r   r   r   create_in_documentr   s   zCsv.create_in_documentc                 C   sH   || j fv sJ |jd u rg |_t|jjjdks"J d|jjj d S )N   zBCSV Serializer supports functions with exactly one return type: %r)RESPONSEr&   lenr   r   r   )rD   r.   messager   r   r   	serializeu   s   
zCsv.serializec                 C   s4   t | ||_d|jjv rd|jj |jjd< d S d S )Nhttpzattachment; filename=%s.csv;zContent-Disposition)r8   
out_string	transporttyper   nameresp_headersrI   r   r   r   create_out_string   s
   
zCsv.create_out_stringc                    s,   t ||jr	|j}tt| j||fi |S rG   )r*   ValuetextrB   r9   any_uri_to_unicode)rD   r/   valuer
   rE   r   r   rY      s   zCsv.any_uri_to_unicode)__name__
__module____qualname__r<   
text_basedr(   r   rS   adddictrC   rJ   rO   rV   rY   __classcell__r   r   rE   r   r9   `   s    


r9   )__doc__
__future__r   logging	getLoggerr[   loggerr   spyner   
spyne.utilr   spyne.protocol.dictdocr   r)   r   ior8   r9   r   r   r   r   <module>   s   
4