U
    [e                     @   s   d Z ddl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 ddlmZ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-2022 by Onni Software Ltd.
    :license: New BSD License
    N)product)	constants)
PluginInfoPluginInfoChain)	is_string)FileTypeNotSupported)PARSERRENDERERc                   @   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| d S )Nsource)r   __init__)selfZabsolute_import_pathkeywords r   Z/var/www/html/services/stratfitenv/lib/python3.8/site-packages/pyexcel/plugins/__init__.pyr      s    zSourceInfo.__init__c                 c   s.   t | j| j}|D ]\}}d||f V  qd S )Nz%s-%s)r   targetsactions)r   Z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 kr|qS )Fr   )r   statusr   r   r   r   $   s      r   )fieldslen)r   r   r   Z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   sr   t j| |f|}|rn|dd }|rX|d}|d krbtt|rNt||}qbtdn
|d}| ||}|S )N	file_nameZ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d S )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                   @   s   e Zd ZdZdd ZdS )InputSourceInfoz&Plugin description for an input sourcec                 C   s0   d }|r|  }|tjkr(|t k}nd}|S NF)lowerr   ZREAD_ACTIONr   get_all_file_types)r   r   r&   Z_InputSourceInfo__file_typer   r   r   r   r+   F   s    
zInputSourceInfo.can_i_handleNr    r!   r"   r#   r+   r   r   r   r   r.   C   s   r.   c                   @   s   e Zd ZdZdd ZdS )OutputSourceInfoz+Plugin description for a output file sourcec                 C   s(   |t jkr | tt k}nd}|S r/   )r   ZWRITE_ACTIONr0   tupler	   r1   )r   r   r&   r   r   r   r   r+   T   s    
zOutputSourceInfo.can_i_handleNr2   r   r   r   r   r3   Q   s   r3   c                 C   s   | |ko||  d k	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rft|td}|d }n6t|dkr||d }n |dd }t	t
j||f |S )z*
    Extract file type from file name
    read   )keyr   .)r   r1   r	   r0   endswithappendr   sortedsplitr   r   ZFILE_TYPE_NOT_SUPPORTED_FMT)r%   r   Zlist_of_file_types
file_typesZlowercase_file_nameZa_supported_typer&   r   r   r   r)   `   s$    



r)   c                   @   s   e Zd ZdZdd ZdS )IOPluginInfoz-Plugin description for a parser or a rendererc                 c   s,   | j }t|tjr| }|D ]
}|V  qd S r5   )r?   
isinstancetypesFunctionType)r   r?   r&   r   r   r   r   ~   s
    zIOPluginInfo.tagsN)r    r!   r"   r#   r   r   r   r   r   r@   {   s   r@   c                   @   sB   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 pluginsNc                 K   s0   dg d}| | | t| |f| | S )zB
        Add a data source plugin for signature functions
        Nr8   
attributes)updateadd_a_plugin_instancer
   _get_abs_pathr   relative_plugin_class_pathr   defaultr   r   r   add_a_source   s    

zPyexcelPluginChain.add_a_sourcec                 K   s0   dg d}| | | t| |f| | S )z*
        append file input source
        NrE   )rG   rH   r.   rI   rJ   r   r   r   add_an_input_source   s    

z&PyexcelPluginChain.add_an_input_sourcec                 K   s0   dg d}| | | t| |f| | S )z+
        append file output source
        NrE   )rG   rH   r3   rI   rJ   r   r   r   add_a_output_source   s    

z&PyexcelPluginChain.add_a_output_sourcec                 C   s   |  td| ||d | S )z-
        append an excel file reader
        parser)r?   )rH   r@   rI   )r   rK   r?   r   r   r   add_a_parser   s    zPyexcelPluginChain.add_a_parserc                 C   s*   t ||d}| td| |f| | S )z-
        append an excel file writer
        )r?   stream_typerenderer)dictrH   r@   rI   )r   rK   r?   rR   rL   r   r   r   add_a_renderer   s    	z!PyexcelPluginChain.add_a_renderer)N)N)N)NN)NNN)	r    r!   r"   r#   rM   rN   rO   rQ   rU   r   r   r   r   rD      s   



   rD   )r#   rB   	itertoolsr   Zpyexcelr   Z
lml.pluginr   r   Zpyexcel._compactr   Zpyexcel.exceptionsr   Zpyexcel.internal.pluginsr   r	   r
   r$   r.   r3   r   r)   r@   rD   r   r   r   r   <module>   s   	