
    Mhr                        d Z ddlmZ ddlmZ ddlmZmZmZ ddl	m
Z
 ddlmZ ddlmZ erddlmZ dd	lmZ dd
lmZ  G d d          Z G d d          ZdS )zAn extension handler.    )annotations)Logger)TYPE_CHECKINGAnycast)Template)TemplateNotFound)FileFindHandler)Config)ExtensionApp)	ServerAppc                  $     e Zd ZdZd fdZ xZS )ExtensionHandlerJinjaMixinz`Mixin class for ExtensionApp handlers that use jinja templating for
    template rendering.
    namestrreturnr   c                   	 | j          d}t          t          | j        |                             |                    }|S # t
          $ r7 t          t          t                                          |                    cY S w xY w)z1Return the jinja template object for a given name_jinja2_env)r   r   r   settingsget_templater	   super)selfr   envtemplate	__class__s       `/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/jupyter_server/extension/handler.pyr   z'ExtensionHandlerJinjaMixin.get_template   s    	>Y+++CHdmC&8&E&Ed&K&KLLHO 	> 	> 	>%''"6"6t"<"<=====	>s   >A >BB)r   r   r   r   )__name__
__module____qualname____doc__r   __classcell__r   s   @r   r   r      sG         > > > > > > > > > >    r   c                  
    e Zd ZU dZded<   d fdZedd            Zed d            Zed! fd            Z	ed"d            Z
ed"d            Zed#d            Zd$ fdZed#d            Zed#d            Zd%d&dZ xZS )'ExtensionHandlerMixina.  Base class for Jupyter server extension handlers.

    Subclasses can serve static files behind a namespaced
    endpoint: "<base_url>/static/<name>/"

    This allows multiple extensions to serve static files under
    their own namespace and avoid intercepting requests for
    other extensions.
    zdict[str, Any]r   r   r   argsr   kwargsr   Nonec                l    || _         	  t                      j        |i | d S # t          $ r Y d S w xY wN)r   r   
initialize	TypeError)r   r   r&   r'   r   s       r   r+   z ExtensionHandlerMixin.initialize0   sS    		EGG////// 	 	 	DD	s   % 
33r   c                B    t          d| j        | j                           S )Nr   r   r   r   r   s    r   extensionappz"ExtensionHandlerMixin.extensionapp7   s    NDM$)$<===r#   r   c                <    d}t          d| j        |                   S )N	serverappr   r   r   )r   keys     r   r2   zExtensionHandlerMixin.serverapp;   s    Ks!3444r#   r   c                   t          | d          s&t          t          t                      j                  S 	 t          t          | j        j                  S # t          $ r" t          t          | j        j                  cY S w xY w)Nr   )hasattrr   r   r   logr0   AttributeErrorr2   )r   r   s    r   r7   zExtensionHandlerMixin.log@   s|    tV$$ 	-,,,	4 1 5666 	4 	4 	4 233333	4s   A )BBr   c                H    t          d| j        | j         d                   S )Nr   _configr.   r/   s    r   configzExtensionHandlerMixin.configJ   s$    Hdmty,A,A,ABCCCr#   c                8    t          d| j        d                   S )Nr   r;   r3   r/   s    r   server_configz#ExtensionHandlerMixin.server_configN   s    HdmH5666r#   c                ^    t          t          | j                            dd                    S )Nbase_url/)r   r   r   getr/   s    r   r?   zExtensionHandlerMixin.base_urlR   s$    C**:s;;<<<r#   c                   t          t          |                     |                    }|                    | j                   |j        | j        d         u rt                      j        |d<   t          t           |j
        di |          S )zOverride render template to handle static_paths

        If render_template is called with a template from the base environment
        (e.g. default error pages)
        make sure our extension-specific static_url is _not_ used.
        
jinja2_env
static_url )r   r   r   updatetemplate_namespaceenvironmentr   r   rD   r   render)r   r   nsr   r   s       r   render_templatez%ExtensionHandlerMixin.render_templateV   s     $"3"3D"9"9::
		$)***4=#>>>$ww1B|C..2..///r#   c                    | j         j        S r*   )r0   static_url_prefixr/   s    r   rM   z'ExtensionHandlerMixin.static_url_prefixd   s     22r#   c                R    t          t          | j        | j         d                   S )N_static_paths)r   r   r   r   r/   s    r   static_pathz!ExtensionHandlerMixin.static_pathh   s$    C$)'B'B'BCDDDr#   Npathinclude_hostbool | Nonec           	        | j          d}	 |                     |d           n/# t          $ r"}|| j        v rd}t          |          d|d}~ww xY w| j                            dt
                    j        }|t          | dd          }d}|r| j        j	        d	z   | j        j
        z   }| j        | j        d
}	|t          t           ||	|fi |          z   S )a  Returns a static URL for the given relative static file path.
        This method requires you set the ``{name}_static_path``
        setting in your extension (which specifies the root directory
        of your static files).
        This method returns a versioned url (by default appending
        ``?v=<signature>``), which allows the static files to be
        cached indefinitely.  This can be disabled by passing
        ``include_version=False`` (in the default implementation;
        other static file implementations are not required to support
        this, but they may support other options).
        By default this method returns URLs relative to the current
        host, but if ``include_host`` is true the URL returned will be
        absolute.  If this handler has an ``include_host`` attribute,
        that value will be used as the default for all `static_url`
        calls that do not pass ``include_host`` as a keyword argument.
        rO   rD   zlThis extension doesn't have any static paths listed. Check that the extension's `static_paths` trait is set.Nstatic_handler_classrR   F z://)rP   rM   )r   require_setting	Exceptionr   rA   r
   make_static_urlgetattrrequestprotocolhostrP   rM   r   r   )
r   rQ   rR   r'   r4   emsgget_urlbaser   s
             r   rD   z ExtensionHandlerMixin.static_urll   s   " )))
	  l3333 	 	 	dm##?   nn$.	 -##$:OLL\"4??L 	E<(504<3DDD
  +!%!7
 

 d3$ A A& A ABBBBs   # 
AA

A)r   r   r&   r   r'   r   r   r(   )r   r   )r   r   )r   r   )r   r   )r   r   )r   r   r   r   r*   )rQ   r   rR   rS   r'   r   r   r   )r   r   r   r    __annotations__r+   propertyr0   r2   r7   r;   r=   r?   rK   rM   rP   rD   r!   r"   s   @r   r%   r%   #   s                > > > X> 5 5 5 X5 4 4 4 4 4 X4 D D D XD 7 7 7 X7 = = = X=0 0 0 0 0 0 3 3 3 X3 E E E XE.C .C .C .C .C .C .C .C .Cr#   r%   N)r    
__future__r   loggingr   typingr   r   r   jinja2r   jinja2.exceptionsr	   jupyter_server.base.handlersr
   traitlets.configr   $jupyter_server.extension.applicationr   jupyter_server.serverappr   r   r%   rE   r#   r   <module>rm      s/     " " " " " "       + + + + + + + + + +       . . . . . . 8 8 8 8 8 8 3''''''AAAAAA222222> > > > > > > >wC wC wC wC wC wC wC wC wC wCr#   