
    .h                        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dS )
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          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dS )#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%Description of what the resource does
str | Noner   
text/plainz!MIME type of the resource content)defaultr   	mime_typeT)excludeCallable[..., Any]fnz#JSON schema for function parametersdict[str, Any]
parametersNreturnc                    |p|j         }|dk    rt          d          t          |                                          }t	          |          } | |||p|j        pd|p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   )__name__
ValueErrorr   json_schemar	   __doc__)clsr   r   r   r   r   	func_namer   s           c/var/www/FlaskApp/flask-venv/lib/python3.11/site-packages/mcp/server/fastmcp/resources/templates.pyfrom_functionzResourceTemplate.from_function   s     'BK	
""KLLL !__0022
 2s%#7rz7R/<!
 
 
 	
    uridict[str, Any] | Nonec                    | j                             dd                              dd          }t          j        d| d|          }|r|                                S dS )z5Check if URI matches template and extract parameters.{z(?P<}z>[^/]+)^$N)r   replacerematch	groupdict)selfr'   patternr0   s       r$   matcheszResourceTemplate.matches<   sb     #++C88@@iPPW-- 	%??$$$tr&   paramsr   c                   K   	  | j         di |t          j                  r d{V t          || j        | j        | j        fd          S # t          $ r}t          d|           d}~ww xY w)z>Create a resource from the template with the given parameters.Nc                      S )N )results   r$   <lambda>z2ResourceTemplate.create_resource.<locals>.<lambda>R   s    6 r&   )r'   r   r   r   r   z'Error creating resource from template: r8   )	r   inspectiscoroutiner
   r   r   r   	Exceptionr   )r2   r'   r5   er9   s       @r$   create_resourcez ResourceTemplate.create_resourceE   s      	LTW&&v&&F"6** &%#Y ,.!>>>     	L 	L 	LJqJJKKK	Ls   AA 
A5A00A5)NNN)r   r   r   r   r   r   r   r   r   r   r   r   )r'   r   r   r(   )r'   r   r5   r   r   r   )r   
__module____qualname__r!   r   r   __annotations__r   r   r   r   r   classmethodr%   r4   r?   r8   r&   r$   r   r      sd        88R  L     "8999D9999#e0WXXXKXXXXU*M  I     #U4000B0000!&9" " "J     
  "& $
 
 
 
 [
8   L L L L L Lr&   r   )r!   
__future__r   r;   r/   collections.abcr   typingr   pydanticr   r   r   r	   "mcp.server.fastmcp.resources.typesr
   r   r   r8   r&   r$   <module>rI      s    & & " " " " " "  				 $ $ $ $ $ $       A A A A A A A A A A A A I I I I I I I IFL FL FL FL FLy FL FL FL FL FLr&   