o
    �¨Êh}D  ã                   @   s2  d Z ddlZdZi dd“dd“dd	“d
d	“dd“dd“de“dd“dd“dd“dd“dd“dd“dd“dd“dd“dd“ddddd d!œ¥ZG d"d#„ d#eƒZG d$d%„ d%eƒZd=d'd(„Zea		d>d)d*„Z
d+d,„ Z		d?d-d.„Z	d>d/d0„Z	d>d1d2„Z	d>d3d4„Z	d>d5d6„Z	d>d7d8„Z	d>d9d:„Z	d>d;d<„ZdS )@zÇ
    pyexcel_webio
    ~~~~~~~~~~~~~~~~~~~

    A generic request and response interface for pyexcel web extensions

    :copyright: (c) 2015-2017 by Onni Software Ltd.
    :license: New BSD License
é    NzAapplication/vnd.openxmlformats-officedocument.spreadsheetml.sheetÚcsvztext/csvÚtsvztext/tab-separated-valuesÚcsvzzapplication/zipÚtsvzÚodsz.application/vnd.oasis.opendocument.spreadsheetÚxlszapplication/vnd.ms-excelÚxlsxÚxlsmz.application/vnd.ms-excel.sheet.macroenabled.12Újsonzapplication/jsonÚplainz
text/plainÚsimpleÚgridÚpipeÚorgtblÚrstÚ	mediawikiÚlatexzapplication/x-latexzapplication/svg+xmlztext/html; charset=UTF-8z	image/png)Úlatex_booktabsÚsvgÚhtmlzhandsontable.htmlÚpngc                   @   s¢   e Zd ZdZd dd„Zdd„ Zdd„ Zd	d
„ Zdd„ Zdd„ Z	dd„ Z
			d!dd„Z			d!dd„Zdd„ Zdd„ Z			d!dd„Z			d!dd„Zdd„ ZdS )"Ú
ExcelInputznA generic interface for an excel file input

    The source could be from anywhere, memory or file system
    Nc                 K   ó   t dƒ‚)a}  Abstract method

        :param sheet_name: For an excel book, there could be multiple
                           sheets. If it is left unspecified, the
                           sheet at index 0 is loaded. For 'csv', 'tsv'
                           file, *sheet_name* should be None anyway.
        :param keywords: additional key words
        :returns: A sheet object
        úPlease implement this function©ÚNotImplementedError)ÚselfÚ
sheet_nameÚkeywords© r   úH/var/www/html/env/lib/python3.10/site-packages/pyexcel_webio/__init__.pyÚ
get_params/   s   
zExcelInput.get_paramsc                 K   ó    | j di |¤Ž}tjdi |¤ŽS )a¢  
        Get a :class:`Sheet` instance from the file

        :param sheet_name: For an excel book, there could be multiple
                           sheets. If it is left unspecified, the
                           sheet at index 0 is loaded. For 'csv',
                           'tsv' file, *sheet_name* should be None anyway.
        :param keywords: additional key words
        :returns: A sheet object
        Nr   )r!   ÚpeÚ	get_sheet©r   r   Úparamsr   r   r    r$   ;   ó   zExcelInput.get_sheetc                 K   r"   )a™  
        Get a list of lists from the file

        :param sheet_name: For an excel book, there could be multiple
                           sheets. If it is left unspecified, the
                           sheet at index 0 is loaded. For 'csv',
                           'tsv' file, *sheet_name* should be None anyway.
        :param keywords: additional key words
        :returns: A list of lists
        Nr   )r!   r#   Ú	get_arrayr%   r   r   r    r(   I   r'   zExcelInput.get_arrayc                 K   r"   )a¹  
        Get a generator for a list of lists from the file

        :param sheet_name: For an excel book, there could be multiple
                           sheets. If it is left unspecified, the
                           sheet at index 0 is loaded. For 'csv',
                           'tsv' file, *sheet_name* should be None anyway.
        :param keywords: additional key words
        :returns: A generator for a list of lists
        Nr   )r!   r#   Ú
iget_arrayr%   r   r   r    r)   W   r'   zExcelInput.iget_arrayc                 K   ó0   | j di |¤Ž}d|vrd|d< tjdi |¤ŽS )aŠ  Get a dictionary from the file

        :param sheet_name: For an excel book, there could be multiple
                           sheets. If it is left unspecified, the
                           sheet at index 0 is loaded. For 'csv',
                           'tsv' file, *sheet_name* should be None anyway.
        :param keywords: additional key words
        :returns: A dictionary
        Úname_columns_by_rowr   Nr   )r!   r#   Úget_dictr%   r   r   r    r,   e   ó   
zExcelInput.get_dictc                 K   r*   )a”  Get a list of records from the file

        :param sheet_name: For an excel book, there could be multiple
                           sheets. If it is left unspecified, the
                           sheet at index 0 is loaded. For 'csv',
                           'tsv' file, *sheet_name* should be None anyway.
        :param keywords: additional key words
        :returns: A list of records
        r+   r   Nr   )r!   r#   Úget_recordsr%   r   r   r    r.   t   r-   zExcelInput.get_recordsc                 K   r"   )a±  Get a generator of a list of records from the file

        :param sheet_name: For an excel book, there could be multiple
                           sheets. If it is left unspecified, the
                           sheet at index 0 is loaded. For 'csv',
                           'tsv' file, *sheet_name* should be None anyway.
        :param keywords: additional key words
        :returns: A generator of alist of records
        Nr   )r!   r#   Úiget_recordsr%   r   r   r    r/   ƒ   s   
zExcelInput.iget_recordsTc                 K   sl   | j di |¤Ž}d|vrd|d< d|vrd|d< ||d< ||d< ||d< ||d< ||d	< tjdi |¤Ž d
S )aî  
        Save data from a sheet to database

        :param session: a SQLAlchemy session
        :param table: a database table
        :param initializer: a custom table initialization function if
                            you have one
        :param mapdict: the explicit table column names if your excel
                        data do not have the exact column names
        :param keywords: additional keywords to
                         :meth:`pyexcel.Sheet.save_to_database`
        r+   r   Úname_rows_by_columnéÿÿÿÿÚdest_sessionÚ
dest_tableÚdest_initializerÚdest_mapdictÚdest_auto_commitNr   )r!   r#   Úsave_as©r   ÚsessionÚtableÚinitializerÚmapdictÚauto_commitr   r&   r   r   r    Úsave_to_database�   s   zExcelInput.save_to_databasec                 K   óL   | j di |¤Ž}||d< ||d< ||d< ||d< ||d< tjdi |¤Ž dS )aô  
        Save large data from a sheet to database

        :param session: a SQLAlchemy session
        :param table: a database table
        :param initializer: a custom table initialization function if
                            you have one
        :param mapdict: the explicit table column names if your excel
                        data do not have the exact column names
        :param keywords: additional keywords to
                         :meth:`pyexcel.Sheet.save_to_database`
        r2   r3   r4   r5   r6   Nr   )r!   r#   Úisave_asr8   r   r   r    Úisave_to_database¬   s   zExcelInput.isave_to_databasec                 K   r"   )z“Get a instance of :class:`Book` from the file

        :param keywords: additional key words
        :returns: A instance of :class:`Book`
        Nr   )r!   r#   Úget_bookr%   r   r   r    rB   Ä   ó   zExcelInput.get_bookc                 K   r"   )z¨Get a dictionary of two dimensional array from the file

        :param keywords: additional key words
        :returns: A dictionary of two dimensional arrays
        Nr   )r!   r#   Úget_book_dictr%   r   r   r    rD   Í   rC   zExcelInput.get_book_dictc                 K   r?   )a  
        Save a book into database

        :param session: a SQLAlchemy session
        :param tables: a list of database tables
        :param initializers: a list of model
                             initialization functions.
        :param mapdicts: a list of explicit table column names
                         if your excel data sheets do not have
                         the exact column names
        :param keywords: additional keywords to
                         :meth:`pyexcel.Book.save_to_database`

        r2   Údest_tablesÚdest_initializersÚdest_mapdictsr6   Nr   )r!   r#   Úsave_book_as©r   r9   ÚtablesÚinitializersÚmapdictsr=   r   r&   r   r   r    Úsave_book_to_databaseÖ   ó   z ExcelInput.save_book_to_databasec                 K   r?   )a  
        Save a large book into database

        :param session: a SQLAlchemy session
        :param tables: a list of database tables
        :param initializers: a list of model
                             initialization functions.
        :param mapdicts: a list of explicit table column names
                         if your excel data sheets do not have
                         the exact column names
        :param keywords: additional keywords to
                         :meth:`pyexcel.Book.save_to_database`

        r2   rE   rF   rG   r6   Nr   )r!   r#   Úisave_book_asrI   r   r   r    Úisave_book_to_databaseï   rN   z!ExcelInput.isave_book_to_databasec                 C   s   t  ¡  dS )zq
        After you have used iget_array and iget_records, it's
        recommended to call this function
        N)r#   Úfree_resources)r   r   r   r    rQ     s   zExcelInput.free_resources©N)NNNNT)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r!   r$   r(   r)   r,   r.   r/   r>   rA   rB   rD   rM   rP   rQ   r   r   r   r    r   *   s8    

þ
þ		
þ
þr   c                   @   s"   e Zd ZdZdd„ Zddd„ZdS )ÚExcelInputInMultiDictzT
    A generic interface for an upload excel file
    appearing in a dictionary
    c                 C   r   )z’
        Abstract method to get the file tuple

        It is expected to return file type and a file handle to the
        uploaded file
        r   r   )r   Ú
field_namer   r   r    Úget_file_tuple  s   z$ExcelInputInMultiDict.get_file_tupleNc                 K   s\   |   |¡\}}|dur*|dur*| d¡ | ¡ }|r&||dœ}| |¡ |S tdƒ‚tdƒ‚)z=
        Load the single sheet from named form field
        Nr   )Ú	file_typeÚfile_contentzNo content was uploadedzInvalid parameters)rY   ÚseekÚreadÚupdateÚIOErrorÚ	Exception)r   rX   r   rZ   Úfile_handleÚcontentr&   r   r   r    r!     s   
þ
z ExcelInputInMultiDict.get_paramsrR   )rS   rT   rU   rV   rY   r!   r   r   r   r    rW     s    	rW   éÈ   c                 C   s   d S rR   r   )rb   Úcontent_typeÚstatusÚ	file_namer   r   r    Ú
dummy_func3  s   rg   c                 C   s@   t | dƒr	|  ¡ } |r| |¡sd||f }t| t| ||d�S )Nr]   z%s.%s)rd   re   rf   )Úhasattrr]   ÚendswithÚ__excel_response_func__ÚFILE_TYPE_MIME_TABLE)rb   rZ   re   rf   r   r   r    Ú_make_response:  s   

ýrl   c                 C   s   | a d S rR   )rj   )Úresponse_functionr   r   r    Ú
init_webioG  s   rn   c                 K   s:   t | dƒr|dur|| _| j|dfi |¤Ž}t||||ƒS )a1  
    Make a http response from a pyexcel instance of
    :class:`~pyexcel.Sheet` or :class:`~pyexcel.Book`

    :param pyexcel_instance: pyexcel.Sheet or pyexcel.Book
    :param file_type: one of the following strings:

                      * 'csv'
                      * 'tsv'
                      * 'csvz'
                      * 'tsvz'
                      * 'xls'
                      * 'xlsx'
                      * 'xlsm'
                      * 'ods'

    :param status: unless a different status is to be returned.
    :returns: http response
    ÚnameN)rh   ro   Úsave_to_memoryrl   )Úpyexcel_instancerZ   re   rf   r   r   r[   r   r   r    Úmake_responseL  s   rr   c                 K   ó$   t jd| |dœ|¤Ž}t||||ƒS )zî
    Make a http response from an array

    :param array: a list of lists
    :param file_type: same as :meth:`~pyexcel_webio.make_response`
    :param status: same as :meth:`~pyexcel_webio.make_response`
    :returns: http response
    )ÚarrayÚdest_file_typeNr   ©r#   r7   rl   )rt   rZ   re   rf   r   Úfile_streamr   r   r    Úmake_response_from_arrayh  ó   
rx   c                 K   rs   )zÿ
    Make a http response from a dictionary of lists

    :param dict: a dictinary of lists
    :param file_type: same as :meth:`~pyexcel_webio.make_response`
    :param status: same as :meth:`~pyexcel_webio.make_response`
    :returns: http response
    )Úadictru   Nr   rv   ©rz   rZ   re   rf   r   rw   r   r   r    Úmake_response_from_dictv  ry   r|   c                 K   rs   )a  
    Make a http response from a list of dictionaries

    :param records: a list of dictionaries
    :param file_type: same as :meth:`~pyexcel_webio.make_response`
    :param status: same as :meth:`~pyexcel_webio.make_response`
    :returns: http response
    )Úrecordsru   Nr   rv   )r}   rZ   re   rf   r   rw   r   r   r    Úmake_response_from_records„  s   
ÿÿr~   c                 K   rs   )a+  
    Make a http response from a dictionary of two dimensional
    arrays

    :param book_dict: a dictionary of two dimensional arrays
    :param file_type: same as :meth:`~pyexcel_webio.make_response`
    :param status: same as :meth:`~pyexcel_webio.make_response`
    :returns: http response
    )Úbookdictru   Nr   ©r#   rH   rl   r{   r   r   r    Úmake_response_from_book_dict“  s   ÿÿr�   c                 K   ó&   t jd| ||dœ|¤Ž}t||||ƒS )a•  
    Make a http response from a dictionary of two dimensional
    arrays

    :param query_sets: a query set
    :param column_names: a nominated column names. It could not be N
                         one, otherwise no data is returned.
    :param file_type: same as :meth:`~pyexcel_webio.make_response`
    :param status: same as :meth:`~pyexcel_webio.make_response`
    :returns: a http response
    )Ú
query_setsÚcolumn_namesru   Nr   rv   )rƒ   r„   rZ   re   rf   r   rw   r   r   r    Úmake_response_from_query_sets¤  s   
ÿÿr…   c                 K   r‚   )a"  
    Make a http response from sqlalchmey table

    :param session: SQLAlchemy session
    :param table: a SQLAlchemy table
    :param file_type: same as :meth:`~pyexcel_webio.make_response`
    :param status: same as :meth:`~pyexcel_webio.make_response`
    :returns: a http response
    )r9   r:   ru   Nr   rv   )r9   r:   rZ   re   rf   r   rw   r   r   r    Úmake_response_from_a_table·  ó   
ÿÿr†   c                 K   r‚   )a"  
    Make a http response from sqlalchmy tables

    :param session: SQLAlchemy session
    :param tables: SQLAlchemy tables
    :param file_type: same as :meth:`~pyexcel_webio.make_response`
    :param status: same as :meth:`~pyexcel_webio.make_response`
    :returns: a http response
    )r9   rJ   ru   Nr   r€   )r9   rJ   rZ   re   rf   r   rw   r   r   r    Úmake_response_from_tablesÈ  r‡   rˆ   )Nrc   N)rc   N)rc   NN)rV   Úpyexcelr#   Ú
_XLSX_MIMErk   Úobjectr   rW   rg   rj   rl   rn   rr   rx   r|   r~   r�   r…   r†   rˆ   r   r   r   r    Ú<module>   sŒ    	ÿÿþýüûúùø	÷
öõôóòñðïê g
#
ÿ
þ
ÿ
ÿ
ÿ
ÿ
ÿ
ÿÿ