
    Xhr                        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y)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.
    c                    	 | j                    d}t        t        | j                  |   j	                  |            }|S # t
        $ r  t        t        t        |   |            cY S w xY w)z1Return the jinja template object for a given name_jinja2_env)namer   r   settingsget_templater	   super)selfr   envtemplate	__class__s       T/var/www/html/myenv/lib/python3.12/site-packages/jupyter_server/extension/handler.pyr   z'ExtensionHandlerJinjaMixin.get_template   sc    	>YYK{+CHdmmC&8&E&Ed&KLHO 	>%'"6t"<==	>s   <A   &A)(A))r   strreturnr   )__name__
__module____qualname____doc__r   __classcell__r   s   @r   r   r      s    > >    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   c                R    || _         	 t        |   |i | y # t        $ r Y y w xY wN)r   r   
initialize	TypeError)r   r   argskwargsr   s       r   r(   z ExtensionHandlerMixin.initialize0   s3    		G// 		s    	&&c                H    t        d| j                  | j                           S )Nr   r   r   r   r   s    r   extensionappz"ExtensionHandlerMixin.extensionapp7   s    NDMM$))$<==r#   c                8    d}t        d| j                  |         S )N	serverappr   r   r   )r   keys     r   r1   zExtensionHandlerMixin.serverapp;   s    Ks!344r#   c                    t        | d      st        t        t        |         S 	 t        t        | j
                  j                        S # t        $ r' t        t        | j                  j                        cY S w xY w)Nr   )hasattrr   r   r   logr/   AttributeErrorr1   )r   r   s    r   r6   zExtensionHandlerMixin.log@   sb    tV$,,	4 1 1 5 566 	4 2 233	4s   #A -A;:A;c                N    t        d| j                  | j                   d         S )Nr   _configr-   r.   s    r   configzExtensionHandlerMixin.configJ   s#    Hdmmtyyk,ABCCr#   c                4    t        d| j                  d         S )Nr   r:   r2   r.   s    r   server_configz#ExtensionHandlerMixin.server_configN   s    HdmmH566r#   c                V    t        t        | j                  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                         |j
                  | j                  d   u rt        |    |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   rC   r   render)r   r   nsr   r   s       r   render_templatez%ExtensionHandlerMixin.render_templateV   so     $"3"3D"9:
		$))*4==#>>$w1B|C.2.//r#   c                .    | j                   j                  S r'   )r/   static_url_prefixr.   s    r   rL   z'ExtensionHandlerMixin.static_url_prefixd   s      222r#   c                V    t        t        | j                  | j                   d         S )N_static_paths)r   r   r   r   r.   s    r   static_pathz!ExtensionHandlerMixin.static_pathh   s#    C$))M'BCDDr#   c           	        | j                    d}	 | j                  |d       | j                  j	                  dt
              j                  }|t        | dd      }d}|r0| j                  j                  d	z   | j                  j                  z   }| j                  | j                  d
}	|t        t         ||	|fi |      z   S # t        $ r#}|| j                  v rd}t        |      d|d}~ww xY w)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.
        rN   rC   zlThis extension doesn't have any static paths listed. Check that the extension's `static_paths` trait is set.Nstatic_handler_classinclude_hostF z://)rO   rL   )r   require_setting	Exceptionr   r@   r
   make_static_urlgetattrrequestprotocolhostrO   rL   r   r   )
r   pathrR   r+   r3   emsgget_urlbaser   s
             r   rC   z ExtensionHandlerMixin.static_urll   s    " =)
	  l3 --##$:OL\\"4?L<<((504<<3D3DDD
  ++!%!7!7

 d3$ A& ABBB5  	dmm#?   n$.	s   C 	C0C++C0)r   r   r*   r   r+   r   r   None)r   r   )r   r   )r   r   )r   r   )r   r   )r   r   r   r   r'   )r[   r   rR   zbool | Noner+   r   r   r   )r   r   r   r    __annotations__r(   propertyr/   r1   r6   r:   r<   r>   rJ   rL   rO   rC   r!   r"   s   @r   r%   r%   #   s      > > 5 5 4 4 D D 7 7 = =0 3 3 E E.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%   rD   r#   r   <module>rl      sA     "  + +  . 8'A2> >wC wCr#   