U
    [e&                  
   @   s   d Z ddlZddlZddlmZ ddlmZ ddlmZ ddl	m
Z
 ddlmZmZ ddlmZ dd	lmZ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eZdS )z
    pyexcel_io.io
    ~~~~~~~~~~~~~~~~~~~

    The io interface to file extensions

    :copyright: (c) 2014-2022 by Onni Software Ltd.
    :license: New BSD License, see LICENSE for more details
    N)GeneratorType)	constants)Reader)Writer)OLD_READERSOLD_WRITERS)isstream)NoSupportingPluginFound(SupportingPluginAvailableButNotInstalledc                 K   s"   t | f|dd|\}}||fS )aQ  Get data from an excel file source

    The data has not gone into memory yet. If you use dedicated partial read
    plugins, such as pyexcel-xlsxr, pyexcel-odsr, you will notice
    the memory consumption drop when you work with big files.

    :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 physical 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 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 keep_trailing_empty_cells: keep trailing columns. default to False
    :param keywords: any other library specific parameters
    :returns: an ordered dictionary
    T	file_type	streaming)	_get_data)afiler   keywordsdatareader r   O/var/www/html/services/stratfitenv/lib/python3.8/site-packages/pyexcel_io/io.py	iget_data   s     
r   c                 K   s8   |dk	r|dkrt d t| f|dd|\}}|S )aI  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 keep_trailing_empty_cells: keep trailing columns. default to False
    :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_data:   s    
 
r   c                 K   sb   t | r"|t| |ptjd n6| d ks2|d krF|t| |d n|t| |d tf |S )Nfile_streamr   	file_namer   )file_contentr   )r   updatedictr   FILE_FORMAT_CSV	load_data)r   r   r   r   r   r   r   \   s    r   c           
   	   K   s   |}t |ttf}|r&d}tj|i}nt| }t|dk}t| oL|dk}|rXtj}t| rt|	t
| |d n|	t
| |d ||d< tf |}	|	| W 5 Q R X dS )a  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 force_file_type: used only when filename refers to a physical file
                            and it is intended to open it as forced file type.
    :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   Nr   r   single_sheet_in_book)
isinstancelistr   r   ZDEFAULT_SHEET_NAMEkeyslenr   r!   r   r    
get_writerwrite)
r   r   r   r   Zto_storeZis_listr$   r'   Zno_file_typewriterr   r   r   	save_datal   s     r,   Fc
              	   K   s  i }| ||g}dd |D }t |dkr2ttj|dkrv|rD|}n2z| dd }W n tk
rt   ttjY nX zt	||}W n" t
tfk
r   t||}Y nX z| r|j| f|
 n0|r|j|f|
 n|r|j|f|
 ntd|r||}n4|dk	r||}n|dk	r.||}n| }|	dkrl| D ]}t|| ||< qH|  d}||fW S  t
k
r   | rtj| rtj| r nttj|  nttj|  n Y nX d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   s   g | ]}|d k	r|qS Nr   .0xr   r   r   
<listcomp>   s      zload_data.<locals>.<listcomp>r#   N.zUnrecognized optionsF)r(   IOErrorr   MESSAGE_ERROR_02splitAttributeError	Exception"MESSAGE_FILE_NAME_SHOULD_BE_STRINGr   get_a_pluginr	   r
   r   openopen_contentopen_streamZread_sheet_by_nameZread_sheet_by_indexZ	read_manyZread_allr'   r&   closeospathexistsisfileZMESSAGE_NOT_FILE_FORMATTERZMESSAGE_FILE_DOES_NOT_EXIST)r   r   r   r   force_file_typeZ
sheet_nameZsheet_indexZ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kr|| r||rF|}n2z| dd }W n tk
rv   ttjY nX d}zt	||}	W n" t
tfk
r   t||}	Y nX | r|r|	j| f| q|	j| f| n|r|	j|f| |	S )	zfind a suitable writerc                 S   s   g | ]}|d k	r|qS r-   r   r.   r   r   r   r1      s      zget_writer.<locals>.<listcomp>r#   TNr2   r3   F)r(   r4   r   r5   r6   r7   r8   r9   r   r:   r	   r
   r   r<   r;   r=   )
r   r   r   rD   rC   r   rF   rG   Zfile_type_givenr+   r   r   r   r)      s0    	
r)   )N)NN)N)N)
NNNNNNNNNF)NNNNN)__doc__r?   r   typesr   Z
pyexcel_ior   Zpyexcel_io.readerr   Zpyexcel_io.writerr   Zpyexcel_io.pluginsr   r   Zpyexcel_io._compactr   Zpyexcel_io.exceptionsr	   r
   r   r   r   r,   r"   r)   Z
store_datar   r   r   r   <module>   s>   	
!
"

'          
U     
-