
    i]                        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dS )    )annotationsN)AnyMappingCallablequotez^(?:\.|%2[eE]){1,2}$z	\{(\w+)\}valuestrreturnc                $    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   r	   s    S/root/projects/qq-shell/venv/lib/python3.11/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   templatevaluesMapping[str, Any]quoterCallable[[str], str]c                   t                               |           }t          dt          |          d          D ]q}||         }||vrt	          d| d          ||         }|d||<   1t          |t                    r
|rdnd||<   P |t          ||                             ||<   rd	                    |          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 providedNnulltruefalse )	_PLACEHOLDER_REsplitrangelenKeyError
isinstanceboolr
   join)r   r   r   partsinamevals          r   _interpolater/   /   s     !!(++E1c%jj!$$ 
1 
1QxvQQQQRRRTl;E!HHT"" 	1!$1vv'E!HHvc&,//00E!HH775>>r   kwargsr   c                  d}d}| }d|v r|                     dd          \  }}d|v r|                     dd          \  }}|}t          ||t                    }|                     d          D ]2}t                              |          rt          d|d|d          3|}||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   r0   fragment_templatequery_templaterestpath_templatepath_resultsegmentresults	            r   r;   r;   N   s"   * %)!%ND
d{{"&**S!"4"4
d{{#zz#q11nM }f6NOOK $$S)) x x  )) 	xvvvV]vvvwww	x F!#^V=NOOOO$#%6@TUUUUMr   )r	   r
   r   r
   )r   r
   r   r   r   r   r   r
   )r   r
   r0   r   r   r
   )
__future__r   retypingr   r   r   urllib.parser   compiler5   r#   r   r   r   r/   r;    r   r   <module>rE      s    " " " " " " 				         
       "*455"*\**	. 	. 	. 	.. . . .0 0 0 0   >1 1 1 1 1 1r   