
    4Rj]                        d dl mZ d dlZd dlmZmZmZ d dlmZ  ej                  d      Z
 ej                  d      ZddZddZdd	Z	 	 	 	 	 	 	 	 dd
ZddZy)    )annotationsN)AnyMappingCallablequotez^(?:\.|%2[eE]){1,2}$z	\{(\w+)\}c                    t        | d      S )u   Percent-encode `value` for use in a URI path segment.

    Considers characters not in `pchar` set from RFC 3986 §3.3 to be unsafe.
    https://datatracker.ietf.org/doc/html/rfc3986#section-3.3
    z!$&'()*+,;=:@safer   values    ^/var/www/html/meridian/meridian-ai/venv/lib/python3.12/site-packages/anthropic/_utils/_path.py_quote_path_segment_partr      s     _--    c                    t        | d      S )u   Percent-encode `value` for use in a URI query string.

    Considers &, = and characters not in `query` set from RFC 3986 §3.4 to be unsafe.
    https://datatracker.ietf.org/doc/html/rfc3986#section-3.4
    z!$'()*+,;:@/?r
   r   r   s    r   _quote_query_partr      s     _--r   c                    t        | d      S )u   Percent-encode `value` for use in a URI fragment.

    Considers characters not in `fragment` set from RFC 3986 §3.5 to be unsafe.
    https://datatracker.ietf.org/doc/html/rfc3986#section-3.5
    z!$&'()*+,;=:@/?r
   r   r   s    r   _quote_fragment_partr   &   s     .//r   c                0   t         j                  |       }t        dt        |      d      D ]X  }||   }||vrt	        d| d      ||   }|d||<   (t        |t              r
|rdnd||<   B |t        ||               ||<   Z dj                  |      S )	zReplace {name} placeholders in `template`, quoting each value with `quoter`.

    Placeholder names are looked up in `values`.

    Raises:
        KeyError: If a placeholder is not found in `values`.
          za value for placeholder {z} was not providednulltruefalse )	_PLACEHOLDER_REsplitrangelenKeyError
isinstanceboolstrjoin)templatevaluesquoterpartsinamevals          r   _interpolater,   /   s     !!(+E1c%j!$ 
1Qxv7v=PQRRTl;E!HT"!$v'E!Hc&,/0E!H
1 775>r   c               ~   d}d}| }d|v r|j                  dd      \  }}d|v r|j                  dd      \  }}|}t        ||t              }|j                  d      D ])  }t        j	                  |      st        d|d|d       |}||dt        ||t              z   z  }||dt        ||t              z   z  }|S )	u  Interpolate {name} placeholders in `template` from keyword arguments.

    Args:
        template: The template string containing {name} placeholders.
        **kwargs: Keyword arguments to interpolate into the template.

    Returns:
        The template with placeholders interpolated and percent-encoded.

        Safe characters for percent-encoding are dependent on the URI component.
        Placeholders in path and fragment portions are percent-encoded where the `segment`
        and `fragment` sets from RFC 3986 respectively are considered safe.
        Placeholders in the query portion are percent-encoded where the `query` set from
        RFC 3986 §3.3 is considered safe except for = and & characters.

    Raises:
        KeyError: If a placeholder is not found in `kwargs`.
        ValueError: If resulting path contains /./ or /../ segments (including percent-encoded dot-segments).
    N#r   ?/zConstructed path z contains dot-segment z which is not allowed)r   r,   r   _DOT_SEGMENT_REmatch
ValueErrorr   r   )	r%   kwargsfragment_templatequery_templaterestpath_templatepath_resultsegmentresults	            r   r8   r8   N   s    * %)!%ND
d{"&**S!"4
d{#zz#q1nM }f6NOK $$S) x  )0?UV]U``uvwwx F!#^V=NOOO$#%6@TUUUMr   )r   r#   returnr#   )r%   r#   r&   zMapping[str, Any]r'   zCallable[[str], str]r<   r#   )r%   r#   r4   r   r<   r#   )
__future__r   retypingr   r   r   urllib.parser   compiler1   r   r   r   r   r,   r8    r   r   <module>rC      sz    " 	 
  "**45"**\*	..0 ! 		>1r   