o
    ‹¨Êhƒ  ã                   @   sÐ   d Z ddl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lmZ ddlmZ G dd	„ d	eƒZG d
d„ deƒZG dd„ deƒZG dd„ deƒZdd„ Zdd„ ZG dd„ deƒZG dd„ deƒZdS )z¬
    pyexcel.plugins
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    Public interface for plugins

    :copyright: (c) 2015-2017 by Onni Software Ltd.
    :license: New BSD License
é    N)Úproduct)Ú
PluginInfoÚPluginInfoChain)Ú	is_string)ÚPARSERÚRENDERER)ÚFileTypeNotSupportedc                   @   s(   e Zd ZdZdd„ Zdd„ Zdd„ ZdS )	Ú
SourceInfozPlugin description for a sourcec                 K   s   t j| d|fi |¤Ž d S )NÚsource)r   Ú__init__)ÚselfÚabsolute_import_pathÚkeywords© r   úJ/var/www/html/env/lib/python3.10/site-packages/pyexcel/plugins/__init__.pyr      s   zSourceInfo.__init__c                 c   s0   � t | j| jƒ}|D ]\}}d||f V  q
d S )Nz%s-%s)r   ÚtargetsÚactions)r   Útarget_action_listÚtargetÚactionr   r   r   Útags   s
   €ÿzSourceInfo.tagsc                    s.   ‡ fdd„| j D ƒ}dd„ |D ƒ}t|ƒdkS )zS
        Check if incoming keywords match the parameters in source plugins
        c                    s   g | ]}t |ˆ ƒ‘qS r   )Ú
_has_field)Ú.0Úfield©r   r   r   Ú
<listcomp>$   s    z-SourceInfo.is_my_business.<locals>.<listcomp>c                 S   s   g | ]}|d u r|‘qS )Fr   )r   Ústatusr   r   r   r   %   s    r   )ÚfieldsÚlen)r   r   r   ÚstatusesÚresultsr   r   r   Úis_my_business    s   zSourceInfo.is_my_businessN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r!   r   r   r   r   r	      s
    r	   c                   @   s    e Zd ZdZdd„ Zdd„ ZdS )ÚFileSourceInfoz$Plugin description for a file sourcec                 K   sv   t j| |fi |¤Ž}|r9| dd ¡}|r.| d¡}|d u r-tt|ƒƒr)t||ƒ}n
tdƒ‚n| d¡}|  ||¡}|S )NÚ	file_nameÚforce_file_typezUnsupported file typeÚ	file_type)r	   r!   Úgetr   ÚtypeÚfind_file_type_from_file_nameÚIOErrorÚcan_i_handle)r   r   r   r   r'   r)   r   r   r   r!   ,   s   
ÿú
zFileSourceInfo.is_my_businessc                 C   s   t dƒ‚)NÚ )ÚNotImplementedError)r   r   r)   r   r   r   r.   @   s   zFileSourceInfo.can_i_handleN)r"   r#   r$   r%   r!   r.   r   r   r   r   r&   )   s    r&   c                   @   ó   e Zd ZdZdd„ ZdS )ÚInputSourceInfoz&Plugin description for an input sourcec                 C   s2   d }|r|  ¡ }|tjkr|t ¡ v }|S d}|S ©NF)ÚlowerÚ	constantsÚREAD_ACTIONr   Úget_all_file_types)r   r   r)   Ú_InputSourceInfo__file_typer   r   r   r   r.   G   s   
ÿzInputSourceInfo.can_i_handleN©r"   r#   r$   r%   r.   r   r   r   r   r2   D   ó    r2   c                   @   r1   )ÚOutputSourceInfoz+Plugin description for a output file sourcec                 C   s*   |t jkr| ¡ tt ¡ ƒv }|S d}|S r3   )r5   ÚWRITE_ACTIONr4   Útupler   r7   )r   r   r)   r   r   r   r   r.   U   s
   
ÿzOutputSourceInfo.can_i_handleNr9   r   r   r   r   r;   R   r:   r;   c                 C   s   | |v o	||  d uS ©Nr   )r   r   r   r   r   r   ]   s   r   c                 C   s    |dkr	t  ¡ }nt ¡ }g }|  ¡ }|D ]}| |¡r!| |¡ qt|ƒdkr4t|td�}|d }|S t|ƒdkr@|d }|S | d¡d }t	t
j||f ƒ‚)z*
    Extract file type from file name
    Úreadé   )Úkeyéÿÿÿÿr   Ú.)r   r7   r   r4   ÚendswithÚappendr   ÚsortedÚsplitr   r5   ÚFILE_TYPE_NOT_SUPPORTED_FMT)r'   r   Úlist_of_file_typesÚ
file_typesÚlowercase_file_nameÚa_supported_typer)   r   r   r   r,   a   s(   


€	øûÿr,   c                   @   r1   )ÚIOPluginInfoz-Plugin description for a parser or a rendererc                 c   s.   � | j }t|tjƒr|ƒ }|D ]}|V  qd S r>   )rJ   Ú
isinstanceÚtypesÚFunctionType)r   rJ   r)   r   r   r   r      s   €ÿzIOPluginInfo.tagsN)r"   r#   r$   r%   r   r   r   r   r   rM   |   r:   rM   c                   @   sH   e Zd ZdZddd„Zddd„Zddd„Zdd	d
„Z			ddd„ZdS )ÚPyexcelPluginChainz"It is used by pyexcel plugins
    Nc                 K   ó4   dg dœ}|  |¡ |  t|  |¡fi |¤Ž¡ | S )zB
        Add a data source plugin for signature functions
        N©rA   Ú
attributes)ÚupdateÚadd_a_plugin_instancer	   Ú_get_abs_path©r   Úrelative_plugin_class_pathr   Údefaultr   r   r   Úadd_a_source‹   ó   

ÿÿÿzPyexcelPluginChain.add_a_sourcec                 K   rR   )z*
        append file input source
        NrS   )rU   rV   r2   rW   rX   r   r   r   Úadd_an_input_source˜   r\   z&PyexcelPluginChain.add_an_input_sourcec                 K   rR   )z+
        append file output source
        NrS   )rU   rV   r;   rW   rX   r   r   r   Úadd_a_output_source¥   r\   z&PyexcelPluginChain.add_a_output_sourcec                 C   s   |   td|  |¡|d�¡ | S )z-
        append an excel file reader
        Úparser)rJ   )rV   rM   rW   )r   rY   rJ   r   r   r   Úadd_a_parser²   s   ýÿzPyexcelPluginChain.add_a_parserc                 C   s.   t ||d�}|  td|  |¡fi |¤Ž¡ | S )z-
        append an excel file writer
        )rJ   Ústream_typeÚrenderer)ÚdictrV   rM   rW   )r   rY   rJ   ra   rZ   r   r   r   Úadd_a_renderer¿   s   	þýÿz!PyexcelPluginChain.add_a_rendererr>   )NN)NNN)	r"   r#   r$   r%   r[   r]   r^   r`   rd   r   r   r   r   rQ   ‡   s    



ürQ   )r%   rO   Ú	itertoolsr   Ú
lml.pluginr   r   Úpyexcel._compactr   Úpyexcel.internal.pluginsr   r   Úpyexcel.constantsr5   Úpyexcel.exceptionsr   r	   r&   r2   r;   r   r,   rM   rQ   r   r   r   r   Ú<module>   s     	