o
    ØRWj]  ã                   @  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   úb/home/esfera/Documents/content_generation/venv/lib/python3.10/site-packages/openai/_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 )
zÍReplace {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-   Úfragment_templateÚquery_templateÚrestÚpath_templateÚpath_resultÚsegmentÚresultr   r   r   r7   N   s&   
ÿr7   )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,   r7   r   r   r   r   Ú<module>   s    




	
	