
    )`i                         d Z ddl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dee	z  dz  dedz  fdZdS )zKUtilities for OAuth 2.0 Resource Indicators (RFC 8707) and PKCE (RFC 7636).    N)urlparseurlsplit
urlunsplit)AnyUrlHttpUrlurlreturnc                     t          |           }t          |          }t          |                    |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       i/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/mcp/shared/auth_utils.pyresource_url_from_server_urlr   	   sb     #hhG gF6??&-2E2E2G2GPVP]PcPcPePepr?ssttI    requested_resourceconfigured_resourcec                    t          |           }t          |          }|j                                        |j                                        k    s4|j                                        |j                                        k    rdS |j        }|j        }t          |          t          |          k     rdS |                    d          s|dz  }|                    d          s|dz  }|                    |          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#:#:#<#<<<	@P@V@V@X@X\f\m\s\s\u\u@u@uu ^N oO >S1111u
 ""3'' ###C(( 3$$_555r   
expires_inc                 P    | dS t          j                     t          |           z   S )zCalculate token expiry timestamp from expires_in seconds.

    Args:
        expires_in: Seconds until token expiration (may be string from some servers)

    Returns:
        Unix timestamp when token expires, or None if no expiry specified
    N)timeint)r%   s    r   calculate_token_expiryr)   I   s&     t9;;Z((r   )__doc__r'   urllib.parser   r   r   pydanticr   r   r   r   boolr$   r(   floatr)    r   r   <module>r0      s    Q Q  7 7 7 7 7 7 7 7 7 7 $ $ $ $ $ $ $ $cGmf&<     ,'6s '6 '6QU '6 '6 '6 '6T)sSy4'7 )EDL ) ) ) ) ) )r   