o
    i]                     @  s~   d dl mZ d dlZd dlmZmZmZ d dlmZ e	dZ
e	dZdd
dZdddZdddZdddZdddZdS )    )annotationsN)AnyMappingCallablequotez^(?:\.|%2[eE]){1,2}$z	\{(\w+)\}valuestrreturnc                 C     t | d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    r   K/home/kim/smarthome/.venv/lib/python3.10/site-packages/groq/_utils/_path.py_quote_path_segment_part   s   	r   c                 C  r   )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   r   r   r   _quote_query_part      r   c                 C  r   )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   r   r   r   _quote_fragment_part&   r   r   templatevaluesMapping[str, Any]quoterCallable[[str], str]c                 C  s   t | }tdt|dD ]7}|| }||vrtd| d|| }|du r,d||< qt|tr:|r5dnd||< q|t|| ||< qd	|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valr   r   r   _interpolate/   s   



r,   kwargsr   c          	      K  s   d}d}| }d|v r| dd\}}d|v r| dd\}}|}t||t}| dD ]}t|r=td|d|dq+|}|durN|dt||t 7 }|dur\|dt||t 7 }|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   r-   Zfragment_templateZquery_templaterestpath_templateZpath_resultsegmentresultr   r   r   r5   N   s&   
r5   )r   r	   r
   r	   )r   r	   r   r   r   r   r
   r	   )r   r	   r-   r   r
   r	   )
__future__r   retypingr   r   r   urllib.parser   compiler1   r    r   r   r   r,   r5   r   r   r   r   <module>   s    




	
	