
    Ef&                         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
ZddZddZddZ	 	 	 	 	 	 	 	 	 	 ddZ	 	 	 	 	 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                 0    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readers        O/var/www/ffwdstore.be/apps/py-env/lib/python3.11/site-packages/pyexcel_io/io.py	iget_datar      s=    6 "d 6> LD& <    c                 `    ||du rt          j        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   _s         r   get_datar   :   sY    4 d!2!24555"e 7? GD! Kr   c                 4   t          |           r1|                    t          | |pt          j                             nM| |%|                    t          | |                     n$|                    t          | |                     t          di |S )Nfile_streamr   	file_namer   )file_contentr    )r	   updatedictr   FILE_FORMAT_CSV	load_data)r   r   r   s      r   r   r   \   s     K!#@y'@  	
 	
 	
 	
 =I-OOD5IFFFGGGGOODeyIIIJJJ  x   r   c                 @   |}t          |t          t          f          }|rd}t          j        |i}n4t          |                                          }t          |          dk    }t          |           o|du }|rt          j        }t          |           r%|	                    t          | |                     n$|	                    t          | |                     ||d<   t          di |5 }	|	                    |           ddd           dS # 1 swxY w Y   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_bookr#   )
isinstancelistr   r   DEFAULT_SHEET_NAMEkeyslenr	   r&   r$   r%   
get_writerwrite)
r   r   r   r   to_storeis_listr*   r.   no_file_typewriters
             r   	save_datar6   l   sf    Hm455G .#0$7DIIKK  "4yyA~E??8yD'8L .-	 D)DDDEEEEu	BBBCCC';H#$			h		 6X                 s   0DDDFc
                 z   i }| ||g}d |D             }t          |          dk    rt          t          j                  |I|r|}nD	 |                     d          d         }n'# t
          $ r t          t          j                  w xY w	 t          j	        ||          }n'# t          t          f$ r t          ||          }Y nw xY w	 | r |j        | fi |
 n1|r |j        |fi |
 n |r |j        |fi |
 nt          d          |r|                    |          }nD||                    |          }n,||                    |          }n|                                }|	du rE|                                D ]}t+          ||                   ||<   |                                 d}||fS # t          $ r{ | rwt.          j                            |           r<t.          j                            |           r t          t          j        | z            t          t          j        | z             w xY w)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                     g | ]}||S Nr#   .0xs     r   
<listcomp>zload_data.<locals>.<listcomp>       @@@1!-Q---r   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_streamread_sheet_by_nameread_sheet_by_index	read_manyread_allr.   r,   closeospathexistsisfileMESSAGE_NOT_FILE_FORMATTERMESSAGE_FILE_DOES_NOT_EXIST)r!   r"   r   r   force_file_type
sheet_namesheet_indexsheetslibraryr   r   resultinputsnumber_of_none_inputsr   keys                   r   r'   r'      s   . F{3F@@@@@
 !!Q&&i0111 	N'IIN%OOC004		! N N N	 LMMMN,))W==#%MN , , ,	7++,& 	2FK	..X.... 	2F999999 	2F{77h77770111 	'..z::FF$//<<FF%%f--FF__&&F{{}} 0 0"6#;//sLLNNNFv~"    	w~~i(( 
7>>),, !!<yH   9IE   s,   A$ $$BB" "!CC
C*F5 5BH:c                     | |g}d |D             }t          |          dk    rt          t          j                  d}|M| rK|r|}nD	 |                     d          d         }n'# t
          $ r t          t          j                  w xY wd}	 t          j	        ||          }	n'# t          t          f$ r t          ||          }	Y nw xY w| r |r |	j        | fi | n |	j        | fi | n|r |	j        |fi | |	S )zfind a suitable writerc                     g | ]}||S r9   r#   r:   s     r   r=   zget_writer.<locals>.<listcomp>   r>   r   r)   TNr?   r@   F)r/   rA   r   rB   rC   rD   rE   rF   r   rG   r
   r   r   rI   rH   rJ   )
r!   r   r   rZ   rV   r   r\   r]   file_type_givenr5   s
             r   r0   r0      s~    %F@@@@@
 !!Q&&i0111OY 	N'IIN%OOC004		! N N N	 LMMMN  ,))W==#%MN , , ,	7++,  4 	/F	66X6666FK	..X....	 4;33(333Ms   	A% %$B	B% %!C	C	r9   )NN)
NNNNNNNNNF)NNNNN)__doc__rP   r   typesr   
pyexcel_ior   pyexcel_io.readerr   pyexcel_io.writerr   pyexcel_io.pluginsr   r   pyexcel_io._compactr	   pyexcel_io.exceptionsr
   r   r   r   r   r6   r'   r0   
store_datar#   r   r   <module>rk      sz    
			                    $ $ $ $ $ $ $ $ $ $ $ $ 7 7 7 7 7 7 7 7 ( ( ( ( ( (          B   D! ! ! ! # # # #N Q Q Q Qj ) ) ) )Z 


r   