a
    2b                     @   s   d dl Zd dl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 dd Zed	d
 Zedd
 Zedd
 Zedd
 Zejdd Zejdd Zejdd ZdS )    N)url_path_join)	LabConfig)
url_escape)UnicodeLabAppc                 G   s"   | j | }| s|jdd |S )NT)parents)joinpathexistsmkdir)tmp_pathpartspath r   7lib/python3.9/site-packages/jupyterlab/pytest_plugin.pyr      s    
r   c                 C   s
   t | dS )NZapp_settingsr   r   r   r   r   <lambda>       r   c                 C   s
   t | dS )NZuser_settingsr   r   r   r   r   r      r   c                 C   s
   t | dS )NZschemasr   r   r   r   r   r      r   c                 C   s
   t | dS )NZ
workspacesr   r   r   r   r   r      r   c                    s.    fdd} d}|d |S )Nc                     s(   G  fdddt }| }|S )Nc                
       sP   e Zd ZdZdZedddZedeede eeedZ	dS )z7make_lab_app.<locals>._make_lab_app.<locals>.TestLabAppz/lab/z'The default URL to redirect to from `/`)helpzJupyterLab Test App)Zapp_nameZ
static_dirZtemplates_dirZapp_urlapp_settings_diruser_settings_dirschemas_dirworkspaces_dirN)
__name__
__module____qualname__Zbase_urlZextension_urlr   Zdefault_urlr   strZ
lab_configr   r   jp_root_dirjp_template_dirr   r   r   r   r   
TestLabApp   s   r"   r   )kwargsr"   appr   r   r   _make_lab_app   s    z#make_lab_app.<locals>._make_lab_appz
index.htmla  
<!DOCTYPE html>
<html>
<head>
  <title>{{page_config['appName'] | e}}</title>
</head>
<body>
    {# Copy so we do not modify the page_config with updates. #}
    {% set page_config_full = page_config.copy() %}

    {# Set a dummy variable - we just want the side effect of the update. #}
    {% set _ = page_config_full.update(baseUrl=base_url, wsUrl=ws_url) %}

      <script id="jupyter-config-data" type="application/json">
        {{ page_config_full | tojson }}
      </script>
  <script src="{{page_config['fullStaticUrl'] | e}}/bundle.js" main="index"></script>

  <script type="text/javascript">
    /* Remove token from URL. */
    (function () {
      var parsedUrl = new URL(window.location.href);
      if (parsedUrl.searchParams.get('token')) {
        parsedUrl.searchParams.delete('token');
        window.history.replaceState({ }, '', parsedUrl.href);
      }
    })();
  </script>
</body>
</html>
)r	   
write_text)r    r!   r   r   r   r   r%   indexr   r   r   make_lab_app   s    

 r(   c                 C   s   | }| |  |  |S )N)Z_link_jupyter_server_extensionZ
initialize)Zjp_serverappr(   r$   r   r   r   labappQ   s    
r)   c                    s   i i d fdd
}|S )z3fetch fixture that handles auth, base_url, and path)headersparamsc                    sT   t t| dd}t|}tj|}|d | }|   j|f| dd|S )NF)Zplus?   )r*   Zrequest_timeout)r   r   urllibparse	urlencodeupdateZfetch)r*   r+   r   r#   Zpath_urlZ
params_urlurlhttp_server_clientjp_auth_headerjp_base_urlr   r   client_fetch\   s    

z fetch_long.<locals>.client_fetchr   )r4   r5   r6   r7   r   r3   r   
fetch_longY   s    r8   )urllib.parser.   ZpytestZjupyter_server.utilsr   Zjupyterlab_serverr   Ztornado.escaper   Z	traitletsr   Zjupyterlab.labappr   r   Zfixturer   r   r   r   r(   r)   r8   r   r   r   r   <module>   s"   
9
