
    MhE                         d Z ddlZ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  G d	 d
e          ZddZd Zd Zd Zd Zd ZdS )ae  
This module contains a Jupyter Server extension that attempts to
make classic server and notebook extensions work in the new server.

Unfortunately, you'll notice that requires some major monkey-patching.
The goal is that this extension will only be used as a temporary
patch to transition extension authors from classic notebook server to jupyter_server.
    N)wraps)jupyter_config_path)is_trait)ConfigManager   )NotebookAppTraitsc                       e Zd ZdS )ClassProxyErrorN)__name__
__module____qualname__     V/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/notebook_shim/nbserver.pyr
   r
      s        Dr   r
   Fc                    t          |           r3|du r/t          d                    | j        j                            t	                    t	          j                  }t          |          st                    t          k    rt          fd          }n7t          t          j
                  rt                    fd            }n}t          | j        |           dS )zARedirects a method, property, or trait from object 1 to object 2.FzZCannot proxy the attribute '{name}' from {cls2} because {cls1} already has this attribute.)namecls1cls2c                 $    t                    S N)getattr)selfr   obj2s    r   <lambda>zproxy.<locals>.<lambda>)   s    gdD&9&9 r   c                      |i |S r   r   )r   argskwargsattrs      r   thingzproxy.<locals>.thing,   s    4((((r   N)hasattrr
   format	__class__r   r   typeproperty
isinstancetypes
MethodTyper   setattr)obj1r   r   	overwritecls_attrr   r   s    ``   @r   proxyr,      s   tT 
yE11117^^ 28 2 2
 
 	
 4D t~t,,H 
T$ZZ83399999::	D%*	+	+ 	t	) 	) 	) 	) 
	) 	)
 DND%(((((r   c                 B    t          j        |           }d |D             S )Nc                 B    g | ]\  }}|                     d           |S )_)
startswith).0mr/   s      r   
<listcomp>z"public_members.<locals>.<listcomp>9   s-    ;;;$!Qc):):;A;;;r   )inspect
getmembers)objmemberss     r   public_membersr8   7   s&     %%G;;';;;;r   c                     t          |           }t          |          }t          |                              |          S )z5Return all attribute names found in obj2 but not obj1)r8   set
difference)r)   r   m1m2s       r   diff_membersr>   <   s6    			B			Br77b!!!r   c                     t          |           }|                    d          }|                    di                               di           }|S )N)read_config_pathjupyter_notebook_configNotebookAppnbserver_extensions)r   get)config_dirscmsection
extensionss       r   get_nbserver_extensionsrI   C   sN    		4	4	4Bff.//G]B//334I2NNJr   c                    | j         }| j        }d }t          |          |j        _        	 |j        d         }|                    d|            |j        d         }|j        }n# t          $ r t                      }Y nw xY wt          | |          }|D ]}t          | ||           t                      }	|	| j        gz   }
t          |
          }|                                D ]e\  }}||j        vrW|                    ||          }|r>|                    d                    |                     |                    |           fd S )Nc                      t           j                                                  }|                    d           dg|z   } fd|D             S )zkDictionary with extension package names as keys
        and an ExtensionPackage objects as values.
        notebook_shimc                 ,    i | ]}|j         |         S r   )rH   )r1   keyr   s     r   
<dictcomp>zM_link_jupyter_server_extension.<locals>.sorted_extensions.<locals>.<dictcomp>\   s"    :::cT_S):::r   )sortedrH   keysremove)r   rQ   s   ` r   sorted_extensionsz9_link_jupyter_server_extension.<locals>.sorted_extensionsT   sY    
 do**,,--O$$$ 4'::::T::::r   rL   )enabledz}{name} | extension was found and enabled by notebook_shim. Consider moving the extension to Jupyter Server's extension paths.)r   )extension_managerlogr$   r"   rS   rH   
link_pointextension_pointsapp	Exceptionr   r>   r,   r   
config_dirrI   itemsadd_extensioninfor!   link_extension)	serverappmanagerloggerrS   pkgpointnbappr7   r2   jupyter_pathsrE   rC   r   rT   
successfuls                  r   _link_jupyter_server_extensionrh   J   s   )G]F; ; ; +33D*E*EG'$ 1	222$_5	 $ $ $!##$ 9e,,G # #i"""" ())M9#7"88K1+>> -2244 - -g w))) ..tW.EEJ -''-v4v'8'8  
 &&t,,,- -s   7A$ $A?>A?c                 f    | j         }|j        }|d t                      D             z  }||_        d S )Nc                 N    g | ]"}t           j                            |d           #S )nbconfig)ospathjoin)r1   ps     r   r3   z2_load_jupyter_server_extension.<locals>.<listcomp>   s8     9 9 9 a44 9 9 9r   )config_managerr@   r   )r`   rp   r@   s      r   _load_jupyter_server_extensionrq      sP     -N%6 9 9"5"7"79 9 9 9&6N###r   )F)__doc__rl   r&   r4   	functoolsr   jupyter_core.pathsr   traitlets.traitletsr   &jupyter_server.services.config.managerr   traitsr   rZ   r
   r,   r8   r>   rI   rh   rq   r   r   r   <module>rx      s    
			         2 2 2 2 2 2 ( ( ( ( ( ( A @ @ @ @ @ % % % % % %	 	 	 	 	i 	 	 	) ) ) )<< < <
" " "  :- :- :-x7 7 7 7 7r   