o
    ‹¨Êh¿  ã                   @   s~   d 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ZejejfZG dd„ deƒZdd	„ Zd
d„ Zeƒ ZdS )z¹
    pyexcel.internal.source_plugin
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    Second level abstraction

    :copyright: (c) 2015-2017 by Onni Software Ltd.
    :license: New BSD License
é    N)ÚPluginManager)Úregister_book_attributeÚregister_sheet_attributez%s-%sc                   @   sn   e Zd ZdZdd„ Zdd„ Zddd„Zd	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S )ÚSourcePluginManagerzData source plugin loaderc                 C   s   t  | d¡ i | _d S )NÚsource)r   Ú__init__Úkeywords)Úself© r
   úP/var/www/html/env/lib/python3.10/site-packages/pyexcel/internal/source_plugin.pyr      s   
zSourcePluginManager.__init__c                 C   s   t  | |¡ |  |¡ d S )N)r   Úload_me_laterÚ_register_a_plugin_info)r	   Úplugin_infor
   r
   r   r      s   z!SourcePluginManager.load_me_laterNc                 K   sr   | j  d| ¡ d}| j| D ]}|j|fi |¤Žr.|  |¡}t|jƒ}|r+||kr+q |S qt|fi |¤Ž |S )z%get source module into memory for usezload me now:N)Ú_loggerÚdebugÚregistryÚis_my_businessÚdynamic_load_libraryÚ_get_me_pypi_package_nameÚ
__module__Ú_error_handler)r	   ÚkeyÚactionÚlibraryr   Úpluginr   Úmodule_namer
   r
   r   Úload_me_now#   s   

ôzSourcePluginManager.load_me_nowc                 C   s   t  | ||¡ |  |¡ dS )z for dynamically loaded plugin N)r   Úregister_a_pluginr   )r	   Ú
plugin_clsr   r
   r
   r   r   6   s   z%SourcePluginManager.register_a_pluginc           	      K   s\   t ||f }d}d|v r| d¡}| j|f||dœ|¤Ž}|dur%||d< |di |¤Ž}|S )z6obtain a source plugin for pyexcel signature functionsNr   )r   r   r
   )ÚREGISTRY_KEY_FORMATÚpopr   )	r	   Útargetr   Úsource_libraryr   r   Ú
io_libraryÚ
source_clsÚsource_instancer
   r
   r   Úget_a_plugin;   s   
ÿÿÿz SourcePluginManager.get_a_pluginc                 K   ó   | j dtjtjdœ|¤ŽS )zAobtain a sheet read source plugin for pyexcel signature functions©r!   r   Nr
   )r&   Ú	constantsÚSHEETÚREAD_ACTION©r	   r   r
   r
   r   Ú
get_sourceL   ó
   ÿÿzSourcePluginManager.get_sourcec                 K   r'   )z@obtain a book read source plugin for pyexcel signature functionsr(   Nr
   )r&   r)   ÚBOOKr+   r,   r
   r
   r   Úget_book_sourceR   r.   z#SourcePluginManager.get_book_sourcec                 K   r'   )zKobtain a sheet write source plugin for pyexcel signature functions
        r(   Nr
   )r&   r)   r*   ÚWRITE_ACTIONr,   r
   r
   r   Úget_writable_sourceX   s
   ÿÿz'SourcePluginManager.get_writable_sourcec                 K   r'   )zAobtain a book write source plugin for pyexcel signature functionsr(   Nr
   )r&   r)   r/   r1   r,   r
   r
   r   Úget_writable_book_source_   r.   z,SourcePluginManager.get_writable_book_sourcec                 C   s   | j  |d¡S )zcustom keyword for an attributeN)r   Úget)r	   r   r
   r
   r   Úget_keyword_for_parametere   s   z-SourcePluginManager.get_keyword_for_parameterc           
      C   sÒ   d}d}d}|  ¡ D ]L}| d¡\}}|j}t|tƒs|ƒ }|D ]1}	|	tv r'q |dkr2t|||	ƒ n|dkr=t|||	ƒ ntd| ƒ‚|d|	 7 }|j	| j
|	< d	}q |d
7 }q
|rg| j |¡ | j |¡ d S d S )NzSource registry: zInstance attribute: Fú-ÚbookÚsheetzKnown target: %sz%s Tz, )ÚtagsÚsplitÚ
attributesÚ
isinstanceÚlistÚNO_DOT_NOTATIONr   r   Ú	Exceptionr   r   r   r   )
r	   r   Údebug_registryÚdebug_attributeÚanythingr   r!   r   r;   Úattrr
   r
   r   r   i   s0   

þz+SourcePluginManager._register_a_plugin_info)NN)NNN)Ú__name__r   Ú__qualname__Ú__doc__r   r   r   r   r&   r-   r0   r2   r3   r5   r   r
   r
   r
   r   r      s    

ÿr   c                 K   sf   |r.|  dd ¡}|rt tj|| f ¡‚d|v r| d¡ d}|d7 }|d7 }t || ¡‚t d¡‚)NÚ	file_typeÚ	on_demandz$Please check if there were typos in z#function parameters: %s. Otherwise z#unrecognized parameters were given.zNo parameters found!)r4   Ú
exceptionsÚFileTypeNotSupportedr)   ÚFILE_TYPE_NOT_SUPPORTED_FMTr    ÚUnknownParameters)r   r   rG   Úmsgr
   r
   r   r   †   s   ÿ

r   c                 C   s   |   d¡d }| dd¡S )NÚ.r   Ú_r6   )r:   Úreplace)r   Úroot_module_namer
   r
   r   r   š   s   r   )rF   Úpyexcel.constantsr)   Úpyexcel.exceptionsrI   Úpyexcel_io.constantsÚio_constantsÚ
lml.pluginr   Úpyexcel.internal.attributesr   r   r   Ú	DB_DJANGOÚDB_SQLr>   r   r   r   ÚSOURCEr
   r
   r
   r   Ú<module>   s    	n
