
    {h	                     \    d Z ddlmZmZmZ ddlmZmZ deez  ez  defdZ	dedede
fd	Zy
)z7Utilities for OAuth 2.0 Resource Indicators (RFC 8707).    )urlparseurlsplit
urlunsplit)AnyUrlHttpUrlurlreturnc                     t        |       }t        |      }t        |j                  |j                  j                         |j                  j                         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	canonicals       V/var/www/html/hubwallet-dev/venv/lib/python3.12/site-packages/mcp/shared/auth_utils.pyresource_url_from_server_urlr      sV     #hG gF6??&--2E2E2GPVP]P]PcPcPepr?stI    requested_resourceconfigured_resourcec                    t        |       }t        |      }|j                  j                         |j                  j                         k7  s5|j                  j                         |j                  j                         k7  ry|j                  }|j                  }t        |      t        |      k  ry|j                  d      s|dz  }|j                  d      s|dz  }|j                  |      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_paths         r   check_resource_allowedr$      s      +,I-.J :#4#4#:#:#<<	@P@P@V@V@X\f\m\m\s\s\u@u ^^N ooO >S11
 ""3'###C(3$$_55r   N)__doc__urllib.parser   r   r   pydanticr   r   r   r   boolr$    r   r   <module>r*      sH    = 7 7 $cGmf&<  ,'6s '6 '6QU '6r   