o
    h	                     @   s\   d Z ddlmZmZmZ ddlmZmZ deeB eB defddZ	ded	ede
fd
dZdS )z7Utilities for OAuth 2.0 Resource Indicators (RFC 8707).    )urlparseurlsplit
urlunsplit)AnyUrlHttpUrlurlreturnc                 C   s4   t | }t|}t|j|j |j dd}|S )aD  Convert server URL to canonical resource URL per RFC 8707.

    RFC 8707 section 2 states that resource URIs "MUST NOT include a fragment component".
    Returns absolute URI with lowercase scheme/host for canonical form.

    Args:
        url: Server URL to convert

    Returns:
        Canonical resource URL string
     )schemenetlocfragment)strr   r   _replacer
   lowerr   )r   url_strparsed	canonical r   V/var/www/html/openai_agents/venv/lib/python3.10/site-packages/mcp/shared/auth_utils.pyresource_url_from_server_url   s    r   requested_resourceconfigured_resourcec                 C   s   t | }t |}|j |j ks|j |j krdS |j}|j}t|t|k r.dS |ds7|d7 }|ds@|d7 }||S )a$  Check if a requested resource URL matches a configured resource URL.

    A requested resource matches if it has the same scheme, domain, port,
    and its path starts with the configured resource's path. This allows
    hierarchical matching where a token for a parent resource can be used
    for child resources.

    Args:
        requested_resource: The resource URL being requested
        configured_resource: The resource URL that has been configured

    Returns:
        True if the requested resource matches the configured resource
    F/)r   r
   r   r   pathlenendswith
startswith)r   r   	requested
configuredrequested_pathconfigured_pathr   r   r   check_resource_allowed   s   (


r!   N)__doc__urllib.parser   r   r   pydanticr   r   r   r   boolr!   r   r   r   r   <module>   s
    