o
    dl                  
   @   sd   d dl Z d dlZd dlZdddZdddZdddZdd	 Zdd
dZeeeeeeeeed	ZdS )    Nc                 C   sP   |du r	t | }t| d}t| ||W  d   S 1 s!w   Y  dS )a  
    Convert a file into the format expected by the Download component.
    :param path: path to the file to be sent
    :param filename: name of the file, if not provided the original filename is used
    :param type: type of the file (optional, passed to Blob in the javascript layer)
    :return: dict of file content (base64 encoded) and meta data used by the Download component
    Nrb)ntpathbasenameopen
send_bytesread)pathfilenametypef r   U/var/www/html/visualizacion-main/env/lib/python3.10/site-packages/dash/dcc/express.py	send_file   s
   	
$r   c                 K   s>   t | tr| n
tt | fi |}tt| ||ddS )a  
    Convert data written to BytesIO into the format expected by the Download component.
    :param src: array of bytes or a writer that can write to BytesIO
    :param filename: the name of the file
    :param type: type of the file (optional, passed to Blob in the javascript layer)
    :return: dict of data frame content (base64 encoded) and meta data used by the Download component
    Tcontentr	   r
   base64)	
isinstancebytes
_io_to_strioBytesIOdictr   	b64encodedecodesrcr	   r
   kwargsr   r   r   r   r      s   $r   c                 K   s4   t | tr| n
tt | fi |}t|||ddS )a  
    Convert data written to StringIO into the format expected by the Download component.
    :param src: a string or a writer that can write to StringIO
    :param filename: the name of the file
    :param type: type of the file (optional, passed to Blob in the javascript layer)
    :return: dict of data frame content (NOT base64 encoded) and meta data used by the Download component
    Fr   )r   strr   r   StringIOr   r   r   r   r   send_string)   s   $r   c                 K   s2   | j }dd | _ || fi | |  }|  |S )Nc                   S   s   d S Nr   r   r   r   r   <lambda>8   s    z_io_to_str.<locals>.<lambda>)closegetvalue)data_iowriterr   data_io_close
data_valuer   r   r   r   5   s   
r   c                 K   s8   | j }|t vrtd|t| | ||fi |S )a  
    Convert data frame into the format expected by the Download component.
    :param writer: a data frame writer
    :param filename: the name of the file
    :param type: type of the file (optional, passed to Blob in the javascript layer)
    :return: dict of data frame content (base64 encoded) and meta data used by the Download component

    Examples
    --------

    >>> df = pd.DataFrame({'a': [1, 2, 3, 4], 'b': [2, 1, 5, 6], 'c': ['x', 'x', 'y', 'y']})
    ...
    >>> send_data_frame(df.to_csv, "mydf.csv")  # download as csv
    >>> send_data_frame(df.to_json, "mydf.json")  # download as json
    >>> send_data_frame(df.to_excel, "mydf.xls", index=False) # download as excel
    >>> send_data_frame(df.to_pickle, "mydf.pkl") # download as pickle

    zZThe provided writer ({}) is not supported, try calling send_string or send_bytes directly.)__name___data_frame_senderskeys
ValueErrorformat)r%   r	   r
   r   namer   r   r   send_data_frame@   s   r.   )	to_csvto_jsonto_htmlto_excel
to_feather
to_parquet
to_msgpackto_stata	to_pickle)NNr    )	r   r   r   r   r   r   r   r.   r)   r   r   r   r   <module>   s$    




