o
    tfX                     @  s   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 er8ddlmZ ddlmZ dd	lmZ G d
d dZG dd dZdS )zAn extension handler.    )annotations)Logger)TYPE_CHECKINGAnycast)TemplateNotFound)FileFindHandler)Config)ExtensionApp)	ServerAppc                      s"   e Zd ZdZd fddZ  ZS )ExtensionHandlerJinjaMixinz`Mixin class for ExtensionApp handlers that use jinja templating for
    template rendering.
    namestrreturnc                   sJ   z| j  d}tt| j| |W S  ty$   ttt | Y S w )z1Return the jinja template object for a given nameZ_jinja2_env)r   r   r   settingsget_templater   super)selfr   env	__class__ i/var/www/html/software/conda/envs/catlas/lib/python3.10/site-packages/jupyter_server/extension/handler.pyr      s   z'ExtensionHandlerJinjaMixin.get_template)r   r   r   r   )__name__
__module____qualname____doc__r   __classcell__r   r   r   r   r      s    r   c                      s   e Zd ZU dZded< d' fddZed(ddZed)ddZed* fddZ	ed+ddZ
ed+ddZed,ddZed,ddZed,dd Zd-d.d%d&Z  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                   s4   || _ zt j|i | W d S  ty   Y d S w N)r   r   
initialize	TypeError)r   r   r   r    r   r   r   r#   .   s   z ExtensionHandlerMixin.initializer
   c                 C  s   t d| j| j S )Nr
   r   r   r   r   r   r   r   extensionapp5   s   z"ExtensionHandlerMixin.extensionappr   c                 C  s   d}t d| j| S )N	serverappr   r   r   )r   keyr   r   r   r(   9   s   zExtensionHandlerMixin.serverappr   c                   sJ   t | dsttt jS ztt| jjW S  ty$   tt| jj Y S w )Nr   )hasattrr   r   r   logr'   AttributeErrorr(   r&   r   r   r   r,   >   s   
zExtensionHandlerMixin.logr	   c                 C  s   t d| j| j d S )Nr	   _configr%   r&   r   r   r   configH      zExtensionHandlerMixin.configc                 C  s   t d| jd S )Nr	   r/   r)   r&   r   r   r   server_configL   s   z#ExtensionHandlerMixin.server_configc                 C  s   t t| jddS )Nbase_url/)r   r   r   getr&   r   r   r   r2   P   s   zExtensionHandlerMixin.base_urlc                 C  s   | j jS r"   )r'   static_url_prefixr&   r   r   r   r5   T   s   z'ExtensionHandlerMixin.static_url_prefixc                 C  s   t t| j| j d S )N_static_paths)r   r   r   r   r&   r   r   r   static_pathX   r0   z!ExtensionHandlerMixin.static_pathNpathinclude_hostbool | Nonec           
   
   K  s   | j  d}z| |d W n ty( } z|| jv r"d}t|d|d}~ww | jdtj}|du r;t| dd}d}|rI| jj	d	 | jj
 }| j| jd
}	|tt||	|fi | 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.
        r6   
static_urlzlThis extension doesn't have any static paths listed. Check that the extension's `static_paths` trait is set.NZstatic_handler_classr9   F z://)r7   r5   )r   Zrequire_setting	Exceptionr   r4   r   Zmake_static_urlgetattrrequestprotocolhostr7   r5   r   r   )
r   r8   r9   r    r*   emsgZget_urlbaser   r   r   r   r;   \   s*   


z ExtensionHandlerMixin.static_url)r   r   r   r   r    r   r   r!   )r   r
   )r   r   )r   r   )r   r	   )r   r   r"   )r8   r   r9   r:   r    r   r   r   )r   r   r   r   __annotations__r#   propertyr'   r(   r,   r/   r1   r2   r5   r7   r;   r   r   r   r   r   r   !   s*   
 
	r   N)r   
__future__r   loggingr   typingr   r   r   Zjinja2.exceptionsr   Zjupyter_server.base.handlersr   Ztraitlets.configr	   Z$jupyter_server.extension.applicationr
   Zjupyter_server.serverappr   r   r   r   r   r   r   <module>   s    