
    $j#                        d Z ddlmZ ddlZddlmZ ddlmZ ddlm	Z	m
Z
mZmZ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  ej        d          Z G d de          ZdS )z2Namespace transform for prefixing component names.    )annotationsN)Sequence)TYPE_CHECKING)GetPromptNextGetResourceNextGetResourceTemplateNextGetToolNext	Transform)VersionSpec)Prompt)Resource)ResourceTemplate)Toolz^([^:]+://)(.*?)$c                      e Zd ZdZd,dZd-dZd.d	Zd/dZd0dZd1dZ	d2dZ
ddd3dZd4dZddd5dZd6d"Zddd7d%Zd8d(Zddd9d+ZdS ):	Namespaceu  Prefixes component names with a namespace.

    - Tools: name → namespace_name
    - Prompts: name → namespace_name
    - Resources: protocol://path → protocol://namespace/path
    - Resource Templates: same as resources

    Example:
        ```python
        transform = Namespace("math")
        # Tool "add" becomes "math_add"
        # Resource "file://data.txt" becomes "file://math/data.txt"
        ```
    prefixstrreturnNonec                (    || _         | d| _        dS )zjInitialize Namespace transform.

        Args:
            prefix: The namespace prefix to apply.
        _N)_prefix_name_prefix)selfr   s     k/home/rurouni/.hermes/hermes-agent/venv/lib/python3.11/site-packages/fastmcp/server/transforms/namespace.py__init__zNamespace.__init__,   s     %LLL    c                    d| j         dS )Nz
Namespace())r   )r   s    r   __repr__zNamespace.__repr__5   s    -DL----r   namec                    | j          | S )z!Apply namespace prefix to a name.)r   r   r!   s     r   _transform_namezNamespace._transform_name<   s    #+T+++r   
str | Nonec                r    |                     | j                  r|t          | j                  d         S dS )z9Remove namespace prefix from a name, or None if no match.N)
startswithr   lenr#   s     r   _reverse_namezNamespace._reverse_name@   s:    ??4,-- 	2D-..0011tr   uric                    t                               |          }|r%|                                \  }}| | j         d| S |S )uH   Apply namespace to a URI: protocol://path → protocol://namespace/path./)_URI_PATTERNmatchgroupsr   )r   r*   r.   protocolpaths        r   _transform_urizNamespace._transform_uriJ   sN    ""3'' 	6"\\^^NHd555t555
r   c                    t                               |          }|rS|                                \  }}| j         d}|                    |          r| |t          |          d          S dS dS )z1Remove namespace from a URI, or None if no match.r,   N)r-   r.   r/   r   r'   r(   )r   r*   r.   r0   r1   r   s         r   _reverse_urizNamespace._reverse_uriR   s|    ""3'' 	"\\^^NHd'''Fv&& :"9DV$79994tr   toolsSequence[Tool]c                $    K    fd|D             S )z!Prefix tool names with namespace.c                p    g | ]2}|                     d                     |j                  i          3S r!   update
model_copyr$   r!   .0tr   s     r   
<listcomp>z(Namespace.list_tools.<locals>.<listcomp>c   I     
 
 
LMALL)=)=af)E)E FLGG
 
 
r    )r   r5   s   ` r   
list_toolszNamespace.list_toolsa   s2      
 
 
 
QV
 
 
 	
r   Nversion	call_nextr	   rF   VersionSpec | NoneTool | Nonec                  K   |                      |          }|dS  |||           d{V }|r|                    d|i          S dS )zGet tool by namespaced name.NrE   r!   r:   r)   r=   )r   r!   rG   rF   originaltools         r   get_toolzNamespace.get_toolg   sq       %%d++4Yx999999999 	:??64.?999tr   	resourcesSequence[Resource]c                $    K    fd|D             S )z,Add namespace path segment to resource URIs.c           
         g | ]?}|                     d                     t          |j                            i          @S )r*   r:   )r=   r2   r   r*   )r?   rr   s     r   rA   z,Namespace.list_resources.<locals>.<listcomp>y   sR     
 
 
 LL(;(;CJJ(G(G HLII
 
 
r   rC   )r   rO   s   ` r   list_resourceszNamespace.list_resourcesw   s2      
 
 
 

 
 
 	
r   r   Resource | Nonec                  K   |                      |          }|dS  |||           d{V }|r|                    d|i          S dS )zGet resource by namespaced URI.NrE   r*   r:   )r4   r=   )r   r*   rG   rF   rL   resources         r   get_resourcezNamespace.get_resource~   st       $$S))4"8W========= 	<&&ucl&;;;tr   	templatesSequence[ResourceTemplate]c                $    K    fd|D             S )z,Add namespace path segment to template URIs.c                p    g | ]2}|                     d                     |j                  i          3S )uri_templater:   )r=   r2   r]   r>   s     r   rA   z5Namespace.list_resource_templates.<locals>.<listcomp>   sL     
 
 
 LL1D1DQ^1T1T ULVV
 
 
r   rC   )r   rY   s   ` r   list_resource_templatesz!Namespace.list_resource_templates   s2      
 
 
 

 
 
 	
r   r   ResourceTemplate | Nonec                  K   |                      |          }|dS  |||           d{V }|r0|                    d|                     |j                  i          S dS )z(Get resource template by namespaced URI.NrE   r]   r:   )r4   r=   r2   r]   )r   r*   rG   rF   rL   templates         r   get_resource_templatezNamespace.get_resource_template   s       $$S))4"8W========= 	&&&(;(;H<Q(R(RS '    tr   promptsSequence[Prompt]c                $    K    fd|D             S )z#Prefix prompt names with namespace.c                p    g | ]2}|                     d                     |j                  i          3S r9   r<   )r?   pr   s     r   rA   z*Namespace.list_prompts.<locals>.<listcomp>   rB   r   rC   )r   rc   s   ` r   list_promptszNamespace.list_prompts   s2      
 
 
 
QX
 
 
 	
r   r   Prompt | Nonec                  K   |                      |          }|dS  |||           d{V }|r|                    d|i          S dS )zGet prompt by namespaced name.NrE   r!   r:   rK   )r   r!   rG   rF   rL   prompts         r   
get_promptzNamespace.get_prompt   st       %%d++4 y7;;;;;;;;; 	<$$VTN$;;;tr   )r   r   r   r   )r   r   )r!   r   r   r   )r!   r   r   r%   )r*   r   r   r   )r*   r   r   r%   )r5   r6   r   r6   )r!   r   rG   r	   rF   rH   r   rI   )rO   rP   r   rP   )r*   r   rG   r   rF   rH   r   rU   )rY   rZ   r   rZ   )r*   r   rG   r   rF   rH   r   r_   )rc   rd   r   rd   )r!   r   rG   r   rF   rH   r   ri   )__name__
__module____qualname____doc__r   r    r$   r)   r2   r4   rD   rN   rT   rX   r^   rb   rh   rl   rC   r   r   r   r      sv        ) ) ) ). . . ., , , ,      	 	 	 	
 
 
 
 SW
 
 
 
 
 
 
 
 
 
 '+     (
 
 
 
 '+     ,
 
 
 
 UY
 
 
 
 
 
 
 
r   r   )rp   
__future__r   recollections.abcr   typingr   fastmcp.server.transformsr   r   r   r	   r
   fastmcp.utilities.versionsr   fastmcp.prompts.baser   fastmcp.resources.baser   fastmcp.resources.templater   fastmcp.tools.baser   compiler-   r   rC   r   r   <module>r|      sF   8 8 " " " " " " 				 $ $ $ $ $ $                          3 2 2 2 2 2 (++++++//////;;;;;;'''''' rz.//e e e e e	 e e e e er   