
    {h/                    z    d Z ddlmZ ddl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 ddlmZmZ  G d d	e
      Zy)
z Resource template functionality.    )annotationsN)Callable)Any)	BaseModelFieldTypeAdaptervalidate_call)FunctionResourceResourcec                      e Zd ZU dZ ed      Zded<    ed      Zded<    edd	
      Zded<    ed      Z	ded<    edd      Z
ded<    ed      Zded<    ed      Zded<   e	 	 	 	 d	 	 	 	 	 	 	 	 	 	 	 	 	 dd       ZddZd dZy	)!ResourceTemplatez.A template for dynamically creating resources.z<URI template with parameters (e.g. weather://{city}/current))descriptionstruri_templatezName of the resourcenamez$Human-readable title of the resourceN)r   default
str | Nonetitlez%Description of what the resource doesr   
text/plainz!MIME type of the resource content)r   r   	mime_typeT)excludeCallable[..., Any]fnz#JSON schema for function parametersdict[str, Any]
parametersc           	         |xs |j                   }|dk(  rt        d      t        |      j                         }t	        |      } | ||||xs |j
                  xs d|xs d||      S )z"Create a template from a function.z<lambda>z,You must provide a name for lambda functions r   )r   r   r   r   r   r   r   )__name__
ValueErrorr   json_schemar	   __doc__)	clsr   r   r   r   r   r   	func_namer   s	            g/var/www/html/hubwallet-dev/venv/lib/python3.12/site-packages/mcp/server/fastmcp/resources/templates.pyfrom_functionzResourceTemplate.from_function   s{     'BKK	
"KLL !_002
 2%#7rzz7R/<!
 	
    c                    | j                   j                  dd      j                  dd      }t        j                  d| d|      }|r|j	                         S y)z5Check if URI matches template and extract parameters.{z(?P<}z>[^/]+)^$N)r   replacerematch	groupdict)selfuripatternr.   s       r$   matcheszResourceTemplate.matches9   sT     ##++C8@@iP1WIQ-??$$r&   c           	     *  K   	  | j                   di |t        j                        r
 d{   t        || j                  | j
                  | j                  | j                  fd      S 7 @# t        $ r}t        d|       d}~ww xY ww)z>Create a resource from the template with the given parameters.Nc                      S )N )results   r$   <lambda>z2ResourceTemplate.create_resource.<locals>.<lambda>P   s    6 r&   )r1   r   r   r   r   r   z'Error creating resource from template: r6   )
r   inspectiscoroutiner
   r   r   r   r   	Exceptionr   )r0   r1   paramser7   s       @r$   create_resourcez ResourceTemplate.create_resourceB   s     	LTWW&v&F""6*%#YYjj ,,..!  &  	LFqcJKK	Ls8   B,A4 A2?A4 1B2A4 4	B=BBB)NNNN)r   r   r   r   r   r   r   r   r   r   r   r   returnr   )r1   r   r?   zdict[str, Any] | None)r1   r   r<   r   r?   r   )r   
__module____qualname__r!   r   r   __annotations__r   r   r   r   r   r   classmethodr%   r3   r>   r6   r&   r$   r   r      s    8*hiL#i"89D#9*PZ^_E:_#0WXKX<=`aIsa"40B0!&3X!YJY
   "& $

 
 	

 
  
 
 

 
<Lr&   r   )r!   
__future__r   r9   r-   collections.abcr   typingr   pydanticr   r   r   r	   "mcp.server.fastmcp.resources.typesr
   r   r   r6   r&   r$   <module>rI      s0    & "  	 $  A A IDLy DLr&   