o
    w¨Êh�   ã                   @   s¤   d Z ddlmZ ddlZddlmZmZ ddlmZm	Z	 ddl
mZ ddd„Zddd	„Zdd
d„Zddd„Zddd„Z										ddd„Z	ddd„ZdS )zÅ
    pyexcel_io.io
    ~~~~~~~~~~~~~~~~~~~

    The io interface to file extensions

    :copyright: (c) 2014-2017 by Onni Software Ltd.
    :license: New BSD License, see LICENSE for more details
é    )ÚGeneratorTypeN)ÚisstreamÚPY2)ÚREADERSÚWRITERSc                 K   s"   t | f|ddœ|¤Ž\}}||fS )aû  Get data from an excel file source

    :param afile: a file name, a file stream or actual content
    :param sheet_name: the name of the sheet to be loaded
    :param sheet_index: the index of the sheet to be loaded
    :param sheets: a list of sheet to be loaded
    :param file_type: used only when filename is not a physial file name
    :param force_file_type: used only when filename refers to a physical file
                            and it is intended to open it as forced file type.
    :param streaming: toggles the type of returned data. The values of the
                      returned dictionary remain as generator if it is set
                      to True. Default is False.
    :param library: explicitly name a library for use.
                    e.g. library='pyexcel-ods'
    :param auto_detect_float: defaults to True
    :param auto_detect_int: defaults to True
    :param auto_detect_datetime: defaults to True
    :param ignore_infinity: defaults to True
    :param ignore_nan_text: various forms of 'NaN', 'nan' are ignored
    :param default_float_nan: choose one form of 'NaN', 'nan'
    :param pep_0515_off: turn off pep 0515. default to True.
    :param keywords: any other library specific parameters
    :returns: an ordered dictionary
    T©Ú	file_typeÚ	streaming)Ú	_get_data)Úafiler   ÚkeywordsÚdataÚreader© r   ú?/var/www/html/env/lib/python3.10/site-packages/pyexcel_io/io.pyÚ	iget_data   s   ÿÿ
ÿr   c                 K   s8   |dur|du rt  d¡ t| f|ddœ|¤Ž\}}|S )am  Get data from an excel file source

    :param afile: a file name, a file stream or actual content
    :param sheet_name: the name of the sheet to be loaded
    :param sheet_index: the index of the sheet to be loaded
    :param file_type: used only when filename is not a physial file name
    :param streaming: toggles the type of returned data. The values of the
                      returned dictionary remain as generator if it is set
                      to True. Default is False.
    :param library: explicitly name a library for use.
                    e.g. library='pyexcel-ods'
    :param auto_detect_float: defaults to True
    :param auto_detect_int: defaults to True
    :param auto_detect_datetime: defaults to True
    :param ignore_infinity: defaults to True
    :param keywords: any other library specific parameters
    :returns: an ordered dictionary
    NTzPlease use iget_data insteadFr   )ÚwarningsÚwarnr
   )r   r   r	   r   r   Ú_r   r   r   Úget_data1   s   
ÿÿ
ÿr   c                 K   sf   t | ƒr| t| |ptjd�¡ n| d u s|d u r#| t| |d�¡ n	| t| |d�¡ tdi |¤ŽS )N©Úfile_streamr   ©Ú	file_namer   )Úfile_contentr   r   )r   ÚupdateÚdictÚ	constantsÚFILE_FORMAT_CSVÚ	load_data)r   r   r   r   r   r   r
   L   s   þÿr
   c           	      K   s‚   |}t |ttfƒ}|rd}tj|i}ntr| ¡ }nt| ¡ ƒ}t|ƒdk}t| ƒo-|du }|r3tj	}t
| |f||dœ|¤Ž dS )aG  Save data to an excel file source

    Your data must be a dictionary

    :param filename: actual file name, a file stream or actual content
    :param data: a dictionary but an ordered dictionary is preferred
    :param file_type: used only when filename is not a physial file name
    :param library: explicitly name a library for use.
                    e.g. library='pyexcel-ods'
    :param keywords: any other parameters that python csv module's
                     `fmtparams <https://docs.python.org/release/3.1.5/library/csv.html#dialects-and-formatting-parameters>`_
    Té   N)r   Úsingle_sheet_in_book)Ú
isinstanceÚlistr   r   ÚDEFAULT_SHEET_NAMEr   ÚkeysÚlenr   r   Ú
store_data)	r   r   r   r   Úto_storeÚis_listr!   r%   Úno_file_typer   r   r   Ú	save_data\   s*   
þü
ûr+   c                 K   sl   t | ƒr| t| |d�¡ n	| t| |d�¡ tdi |¤Ž�}| |¡ W d  ƒ dS 1 s/w   Y  dS )a  Non public function to store data to afile

    :param filename: actual file name, a file stream or actual content
    :param data: the data to be written
    :param file_type: used only when filename is not a physial file name
    :param keywords: any other parameters
    r   r   Nr   )r   r   r   Ú
get_writerÚwrite)r   r   r   r   Úwriterr   r   r   r'   ƒ   s   "ÿr'   Fc
                 K   s:  i }| ||g}dd„ |D ƒ}t |ƒdkrttjƒ‚|du r7|r"|}nz	|  d¡d }W n ty6   tdƒ‚w t ||¡}| rI|j	| fi |
¤Ž n|rU|j
|fi |
¤Ž n|r`|j|fi |
¤Ž |rh| |¡}n|durr| |¡}n|dur|| |¡}n| ¡ }|	du r™| ¡ D ]
}t|| ƒ||< qˆ| ¡  d}||fS )	aý  Load data from any supported excel formats

    :param filename: actual file name, a file stream or actual content
    :param file_type: used only when filename is not a physial file name
    :param force_file_type: used only when filename refers to a physical file
                            and it is intended to open it as forced file type.
    :param sheet_name: the name of the sheet to be loaded
    :param sheet_index: the index of the sheet to be loaded
    :param keywords: any other parameters
    c                 S   ó   g | ]}|d ur|‘qS ©Nr   ©Ú.0Úxr   r   r   Ú
<listcomp>¬   ó    zload_data.<locals>.<listcomp>r    NÚ.éÿÿÿÿú!file_name should be a string typeF)r&   ÚIOErrorr   ÚMESSAGE_ERROR_02ÚsplitÚAttributeErrorÚ	Exceptionr   Úget_a_pluginÚopenÚopen_contentÚopen_streamÚread_sheet_by_nameÚread_sheet_by_indexÚ	read_manyÚread_allr%   r#   Úclose)r   r   r   r   Úforce_file_typeÚ
sheet_nameÚsheet_indexÚsheetsÚlibraryr	   r   ÚresultÚinputsÚnumber_of_none_inputsr   Úkeyr   r   r   r   “   sB   

ÿr   c           	      K   sÄ   | |g}dd„ |D ƒ}t |ƒdkrttjƒ‚d}|du r5| r5z	|  d¡d }W n ty2   tdƒ‚w d	}t ||¡}| rU|rJ|j	| fi |¤Ž |S |j
| fi |¤Ž |S |r`|j|fi |¤Ž |S )
zfind a suitable writerc                 S   r/   r0   r   r1   r   r   r   r4   Ö   r5   zget_writer.<locals>.<listcomp>r    TNr6   r7   r8   F)r&   r9   r   r:   r;   r<   r=   r   r>   r@   r?   rA   )	r   r   r   rK   r   rM   rN   Úfile_type_givenr.   r   r   r   r,   Ñ   s,   
ÿüýr,   r0   )NN)
NNNNNNNNNF)NNNN)Ú__doc__Útypesr   r   Úpyexcel_io._compactr   r   Úpyexcel_io.pluginsr   r   Úpyexcel_io.constantsr   r   r   r
   r+   r'   r   r,   r   r   r   r   Ú<module>   s0    	




'
ö?ÿ