o
    i                     @   sH   d Z d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.    )no_type_check)TemplateNotFound)FileFindHandlerc                       s$   e Zd ZdZe fddZ  ZS )ExtensionHandlerJinjaMixinz`Mixin class for ExtensionApp handlers that use jinja templating for
    template rendering.
    c                    s>   z| j  d}| j| |W S  ty   t | Y S w )z1Return the jinja template object for a given name_jinja2_env)namesettingsget_templater   super)selfr   env	__class__ [/var/www/edux/Edux_v2/venv/lib/python3.10/site-packages/jupyter_server/extension/handler.pyr	      s   z'ExtensionHandlerJinjaMixin.get_template)__name__
__module____qualname____doc__r   r	   __classcell__r   r   r   r   r   	   s    r   c                       s   e Zd ZdZ fddZedd Zedd Ze fdd	Zed
d Z	edd Z
edefddZedd Zedd Z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.
    c                    s4   || _ zt j|i | W d S  ty   Y d S w N)r   r
   
initialize	TypeError)r   r   argskwargsr   r   r   r   #   s   z ExtensionHandlerMixin.initializec                 C   s   | j | j S r   r   r   r   r   r   r   extensionapp*   s   z"ExtensionHandlerMixin.extensionappc                 C   s   d}| j | S )N	serverappr   )r   keyr   r   r   r   .   s   
zExtensionHandlerMixin.serverappc                    s8   t | ds	t jS z| jjW S  ty   | jj Y S w )Nr   )hasattrr
   logr   AttributeErrorr   r   r   r   r   r#   3   s   

zExtensionHandlerMixin.logc                 C      | j | j d S )N_configr   r   r   r   r   config=      zExtensionHandlerMixin.configc                 C   s
   | j d S )Nr'   r    r   r   r   r   server_configA   s   
z#ExtensionHandlerMixin.server_configreturnc                 C   s   | j ddS )Nbase_url/)r   getr   r   r   r   r+   E   s   zExtensionHandlerMixin.base_urlc                 C   s   | j jS r   )r   static_url_prefixr   r   r   r   r.   I   s   z'ExtensionHandlerMixin.static_url_prefixc                 C   r%   )N_static_pathsr   r   r   r   r   static_pathM   r(   z!ExtensionHandlerMixin.static_pathNc           
   
   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}|rH| jj	d | jj
 }nd	}| j| jd
}	|||	|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.
        r/   
static_urlzlThis extension doesn't have any static paths listed. Check that the extension's `static_paths` trait is set.Nstatic_handler_classinclude_hostFz:// )r0   r.   )r   require_setting	Exceptionr   r-   r   make_static_urlgetattrrequestprotocolhostr0   r.   )
r   pathr3   r   r!   emsgget_urlbaser   r   r   r   r1   Q   s2   


z ExtensionHandlerMixin.static_urlr   )r   r   r   r   r   propertyr   r   r#   r'   r)   strr+   r.   r0   r1   r   r   r   r   r   r      s(    


	



r   N)	r   typingr   jinja2.exceptionsr   jupyter_server.base.handlersr   r   r   r   r   r   r   <module>   s    