
    lKj                        d 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rddlmZ 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y)zAn extension handler.    )annotations)TYPE_CHECKINGAnycast)TemplateNotFound)FileFindHandler)Logger)Template)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        d| j                  |   j                  |            }|S # t        $ r t        dt
        |   |            cY S w xY w)z1Return the jinja template object for a given name_jinja2_envr
   )namer   settingsget_templater   super)selfr   envtemplate	__class__s       q/Users/ahmed/devFolder/Ultron/claude-voice/.venv/lib/python3.12/site-packages/jupyter_server/extension/handler.pyr   z'ExtensionHandlerJinjaMixin.get_template   sf    	@YYK{+CJc(:(G(G(MNHO 	@
EG$8$>??	@s   8< "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.initialize1   s3    		G// 		s    	&&c                H    t        d| j                  | j                           S )Nr   r   r   r   r   s    r   extensionappz"ExtensionHandlerMixin.extensionapp8   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        dt        |         S 	 t        d| j                  j                        S # t
        $ r# t        d| j                  j                        cY S w xY w)Nr   r	   )hasattrr   r   logr/   AttributeErrorr1   )r   r   s    r   r6   zExtensionHandlerMixin.logA   sb    tV$%'+..	6$"3"3"7"788 	6$.."4"455	6s   A )A/.A/c                N    t        d| j                  | j                   d         S )Nr   _configr-   r.   s    r   configzExtensionHandlerMixin.configK   s#    Hdmmtyyk,ABCCr#   c                4    t        d| j                  d         S )Nr   r:   r2   r.   s    r   server_configz#ExtensionHandlerMixin.server_configO   s    HdmmH566r#   c                N    t        d| j                  j                  dd            S )Nr   base_url/)r   r   getr.   s    r   r>   zExtensionHandlerMixin.base_urlS   s     E4==,,Z=>>r#   c                    t        d| j                  |            }|j                  | j                         |j                  | j
                  d   u rt        |   |d<    |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.
        r
   
jinja2_env
static_url )	r   r   updatetemplate_namespaceenvironmentr   r   rC   render)r   r   nsr   r   s       r   render_templatez%ExtensionHandlerMixin.render_templateW   sh     
D$5$5d$;<
		$))*4==#>>$w1B|x$$$r#   c                .    | j                   j                  S r'   )r/   static_url_prefixr.   s    r   rL   z'ExtensionHandlerMixin.static_url_prefixe   s      222r#   c                N    t        d| j                  | j                   d         S )Nr   _static_pathsr-   r.   s    r   static_pathz!ExtensionHandlerMixin.static_pathi   s#    E4==DII;m)DEFFr#   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        d ||	|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   )r   require_setting	Exceptionr   r@   r   make_static_urlgetattrrequestprotocolhostrO   rL   r   )
r   pathrR   r+   r3   emsgget_urlbaser   s
             r   rC   z ExtensionHandlerMixin.static_urlm   s    " =)
	  l3 --##$:OL\\"4?L<<((504<<3D3DDD
  ++!%!7!7

 d5'(D"CF"CDDD5  	dmm#?   n$.	s   C   	C,	C''C,)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 6 6 D D 7 7 ? ?% 3 3 G G.E .Er#   r%   N)r    
__future__r   typingr   r   r   jinja2.exceptionsr   jupyter_server.base.handlersr   loggingr	   jinja2r
   traitlets.configr   $jupyter_server.extension.applicationr   jupyter_server.serverappr   r   r%   rD   r#   r   <module>rl      sC     " + + . 8'A2@ @wE wEr#   