U
    [et                     @   sp   d Z ddlZddlZddlmZmZ ejd dkZee	Z
G dd deZdd Zd	d
 Zdd Zdd ZdS )z
    lml.utils
    ~~~~~~~~~~~~~~~~~~~

    json utils for dump plugin info class

    :copyright: (c) 2017-2020 by Onni Software Ltd.
    :license: New BSD License, see LICENSE for more details
    N)JSONEncoderdumps   c                   @   s   e Zd ZdZdd ZdS )PythonObjectEncoderz-
    Custom object encoder for json dump
    c                 C   sF   t ttttttd f}tr$|tf7 }t	||r:t
| |S dt|iS )NZ_python_object)listdictstrintfloatbooltypePY2unicode
isinstancer   default)selfobjZa_list_of_types r   K/var/www/html/services/stratfitenv/lib/python3.8/site-packages/lml/utils.pyr      s    

zPythonObjectEncoder.defaultN)__name__
__module____qualname____doc__r   r   r   r   r   r      s   r   c                 C   s   t | tdS )z(
    Dump function keywords in json
    )cls)r   r   )keywordsr   r   r   
json_dumps    s    r   c                 C   s2   z
t | W S  tk
r,   td|   Y nX dS )zdynamically import a modulez"%s is absent or cannot be importedN)
_do_importImportErrorlog	exception)plugin_module_namer   r   r   	do_import'   s
    
r!   c                 C   sH   t | }d| kr6| d}|dd  D ]}t||}q&td|   |S )N.   zfound )
__import__splitgetattrr   debug)r    plugin_modulemodulesmoduler   r   r   r   0   s    
r   c                 C   sl   zD|  ddd }t|}| d}|dd D ]}t||}q0|W S  tk
rf   td|  Y nX dS )zdynamically import a classr"   r#   r   NzFailed to import %s)rsplitr$   r%   r&   r   r   r   )Zplugin_classr    r(   r)   r*   r   r   r   do_import_class:   s    
r,   )r   sysloggingjsonr   r   version_infor   	getLoggerr   r   r   r   r!   r   r,   r   r   r   r   <module>   s   	
	
