o
    ia                     @   sl   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mZ ddlmZ G d	d
 d
eee
ZdS )z-Tornado handlers for frontend config storage.    N)ValidationError)ExtensionHandlerJinjaMixinExtensionHandlerMixin)web   )SchemaHandlerget_settingssave_settings)
translatorc                   @   s6   e Zd ZdZdd Zejd
ddZejdd Zd	S )SettingsHandlerzA settings API handler.c                 K   s"   t | |||| t| | dS )zInitialize the handler.N)r   
initializer   )selfnameapp_settings_dirschemas_dirsettings_dirlabextensions_pathkwargs r   ]/var/www/edux/Edux_v2/venv/lib/python3.10/site-packages/jupyterlab_server/settings_handler.pyr      s   
zSettingsHandler.initialize c              
   C   st   |   }t| | dddk}t| j| j| j| j|| j	tj
|d\}}|D ]
}|r1| j| q'| t|S )aF  
        Get setting(s)

        Parameters
        ----------
        schema_name: str
            The id of a unique schema to send, added to the URL

        ## NOTES:
            An optional argument `ids_only=true` can be provided in the URL to get only the
            ids of the schemas instead of the content.
        ids_onlyr   true)r   schema_name	overridesr
   r   )get_current_localer
   
set_localeget_argumentr   r   r   r   r   r   translate_schemalogwarningfinishjsondumps)r   r   localer   resultwarningswr   r   r   get   s$   

zSettingsHandler.getc              
   C   s   | j }| j}| j}d}d}d}d}|std|| jj d}	zt	
|	d }
t||||
|| j W n> t	jjyN } ztd|t| d	d	}~w ttfy]   td|d	 tys } ztd|t| d	d	}~ww | d
 d	S )zUpdate a settingzNo current settings directoryzFailed parsing JSON payload: %szAInvalid format for JSON payload. Must be in the form {'raw': ...}zFailed validating input: %si  zutf-8rawi  N   )r   r   r   r   	HTTPErrorrequestbodystripdecoder"   loadsr	   r   decoderJSONDecodeErrorstrKeyError	TypeErrorr   
set_status)r   r   r   r   r   settings_errorinvalid_json_errorinvalid_payload_format_errorvalidation_errorraw_payloadraw_settingser   r   r   putB   s>   zSettingsHandler.putN)r   )	__name__
__module____qualname____doc__r   r   authenticatedr(   r>   r   r   r   r   r      s    	&r   )rB   r"   
jsonschemar    jupyter_server.extension.handlerr   r   tornador   settings_utilsr   r   r	   translation_utilsr
   r   r   r   r   r   <module>   s    