a
    ø£Be¦  ã                   @  sŒ   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rlddl
m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.é    )Úannotations)ÚTYPE_CHECKINGÚAny)ÚTemplateNotFound)ÚFileFindHandler)ÚLogger)ÚConfig)ÚExtensionApp)Ú	ServerAppc                      s(   e Zd ZdZdddœ‡ fdd„Z‡  ZS )ÚExtensionHandlerJinjaMixinz`Mixin class for ExtensionApp handlers that use jinja templating for
    template rendering.
    Ústr)ÚnameÚreturnc                   sB   z| j › d�}| j|  |¡W S  ty<   tƒ  |¡ Y S 0 dS )z1Return the jinja template object for a given nameZ_jinja2_envN)r   ÚsettingsÚget_templater   Úsuper)Úselfr   Úenv©Ú	__class__© úc/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/jupyter_server/extension/handler.pyr      s
    z'ExtensionHandlerJinjaMixin.get_template)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   Ú__classcell__r   r   r   r   r      s   r   c                      sÖ   e Zd ZdZdddddœ‡ fdd„Zedd	œd
d„ƒZedd	œdd„ƒZedd	œ‡ fdd„ƒZedd	œdd„ƒZ	edd	œdd„ƒZ
edd	œdd„ƒZedd	œdd„ƒZedd	œdd„ƒZd"ddd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.
    r   r   ÚNone)r   ÚargsÚkwargsr   c                   s4   || _ ztƒ j|i |¤Ž W n ty.   Y n0 d S ©N)r   r   Ú
initializeÚ	TypeError)r   r   r   r    r   r   r   r"   ,   s
    z ExtensionHandlerMixin.initializer	   )r   c                 C  s   | j | j S r!   ©r   r   ©r   r   r   r   Úextensionapp3   s    z"ExtensionHandlerMixin.extensionappr
   c                 C  s   d}| j | S )NÚ	serverapp©r   )r   Úkeyr   r   r   r'   7   s    zExtensionHandlerMixin.serverappr   c                   s<   t | dƒstƒ jS z
| jjW S  ty6   | jj Y S 0 d S )Nr   )Úhasattrr   Úlogr&   ÚAttributeErrorr'   r%   r   r   r   r+   <   s    

zExtensionHandlerMixin.logr   c                 C  s   | j | j› d� S )NÚ_configr$   r%   r   r   r   ÚconfigF   s    zExtensionHandlerMixin.configc                 C  s
   | j d S )Nr.   r(   r%   r   r   r   Úserver_configJ   s    z#ExtensionHandlerMixin.server_configc                 C  s   | j  dd¡S )NÚbase_urlú/)r   Úgetr%   r   r   r   r0   N   s    zExtensionHandlerMixin.base_urlc                 C  s   | j jS r!   )r&   Ústatic_url_prefixr%   r   r   r   r3   R   s    z'ExtensionHandlerMixin.static_url_prefixc                 C  s   | j | j› d� S )NÚ_static_pathsr$   r%   r   r   r   Ústatic_pathV   s    z!ExtensionHandlerMixin.static_pathNzbool | None)ÚpathÚinclude_hostr    r   c           
   
   K  sÆ   | j › d�}z|  |d¡ W nB ty^ } z*|| jv rFd}t|ƒd‚n|‚W Y d}~n
d}~0 0 | j dt¡j}|du r„t| ddƒ}|rž| 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.
        r4   Ú
static_urlzlThis extension doesn't have any static paths listed. Check that the extension's `static_paths` trait is set.NZstatic_handler_classr7   Fz://Ú )r5   r3   )r   Zrequire_settingÚ	Exceptionr   r2   r   Zmake_static_urlÚgetattrÚrequestÚprotocolÚhostr5   r3   )
r   r6   r7   r    r)   ÚeÚmsgÚget_urlÚbaser   r   r   r   r8   Z   s*    
ÿÿþz ExtensionHandlerMixin.static_url)N)r   r   r   r   r"   Úpropertyr&   r'   r+   r.   r/   r0   r3   r5   r8   r   r   r   r   r   r   !   s&   
	r   N)r   Ú
__future__r   Útypingr   r   Zjinja2.exceptionsr   Zjupyter_server.base.handlersr   Úloggingr   Ztraitlets.configr   Z$jupyter_server.extension.applicationr	   Zjupyter_server.serverappr
   r   r   r   r   r   r   Ú<module>   s   