
    Ke                        d Z ddlmZ ddlmZ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 dd	lmZ  G d
 d          Z G d d          ZdS )zAn extension handler.    )annotations)TYPE_CHECKINGAny)TemplateNotFound)FileFindHandler)Logger)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returnc                    	 | j          d}| j        |                             |          S # t          $ r$ t	                                          |          cY S w xY w)z1Return the jinja template object for a given name_jinja2_env)r   settingsget_templater   super)selfr   env	__class__s      @lib/python3.11/site-packages/jupyter_server/extension/handler.pyr   z'ExtensionHandlerJinjaMixin.get_template   sl    	.Y+++C=%224888 	. 	. 	.77''-----	.s   )- +AA)r   r   r   r   )__name__
__module____qualname____doc__r   __classcell__r   s   @r   r   r      sG         . . . . . . . . . .    r   c                       e Zd ZdZ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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.
    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.initialize,   sS    		EGG////// 	 	 	DD	s   % 
33r
   c                &    | j         | j                 S r'   r   r   r   s    r   extensionappz"ExtensionHandlerMixin.extensionapp3   s    }TY''r    r   c                     d}| j         |         S )N	serverappr   )r   keys     r   r/   zExtensionHandlerMixin.serverapp7   s    }S!!r    r   c                    t          | d          st                      j        S 	 | j        j        S # t          $ r | j        j        cY S w xY w)Nr   )hasattrr   logr-   AttributeErrorr/   )r   r   s    r   r4   zExtensionHandlerMixin.log<   s^    tV$$ 	77;	&$(( 	& 	& 	&>%%%%	&s   2 A
Ar	   c                ,    | j         | j         d         S )N_configr+   r,   s    r   configzExtensionHandlerMixin.configF   s    }	22233r    c                    | j         d         S )Nr8   r0   r,   s    r   server_configz#ExtensionHandlerMixin.server_configJ   s    }X&&r    c                8    | j                             dd          S )Nbase_url/)r   getr,   s    r   r<   zExtensionHandlerMixin.base_urlN   s    }  S111r    c                    | j         j        S r'   )r-   static_url_prefixr,   s    r   r@   z'ExtensionHandlerMixin.static_url_prefixR   s     22r    c                ,    | j         | j         d         S )N_static_pathsr+   r,   s    r   static_pathz!ExtensionHandlerMixin.static_pathV   s    }	88899r    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          }|r| j        j	        dz   | j        j
        z   }nd	}| j        | j        d
}	| ||	|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.
        rB   
static_urlzlThis extension doesn't have any static paths listed. Check that the extension's `static_paths` trait is set.Nstatic_handler_classrE   Fz:// )rC   r@   )r   require_setting	Exceptionr   r>   r   make_static_urlgetattrrequestprotocolhostrC   r@   )
r   rD   rE   r$   r1   emsgget_urlbaser   s
             r   rH   z ExtensionHandlerMixin.static_urlZ   s   " )))
	  l3333 	 	 	dm##?   nn$.	 -##"O
 

 	 "4??L 	<(504<3DDDDD
  +!%!7
 

 ggh777777s   # 
AA

A)r   r   r#   r   r$   r   r   r%   )r   r
   )r   r   )r   r   )r   r	   )r   r   r'   )rD   r   rE   rF   r$   r   r   r   )r   r   r   r   r(   propertyr-   r/   r4   r8   r:   r<   r@   rC   rH   r   r   s   @r   r"   r"   !   sj              ( ( ( X( " " " X" & & & & & X& 4 4 4 X4 ' ' ' X' 2 2 2 X2 3 3 3 X3 : : : X:18 18 18 18 18 18 18 18 18r    r"   N)r   
__future__r   typingr   r   jinja2.exceptionsr   jupyter_server.base.handlersr   loggingr   traitlets.configr	   $jupyter_server.extension.applicationr
   jupyter_server.serverappr   r   r"    r    r   <module>r`      s     " " " " " " % % % % % % % % . . . . . . 8 8 8 8 8 8 3''''''AAAAAA222222. . . . . . . .j8 j8 j8 j8 j8 j8 j8 j8 j8 j8r    