o
    ùT·j~  ã                   @  sH  d dl mZ d dlZd dlZd dlZd dlmZmZmZ d dl	m
Z
mZ d dlZddlmZmZmZmZmZmZmZ ddlmZmZmZmZmZ e
dƒZd;dd„Zd<dd„Zddœd=dd„Zed>dd„ƒZed?dd„ƒZd@d d„ZdAd$d%„Z dBd(d)„Z!ed>d*d+„ƒZ"ed?d,d+„ƒZ"d@d-d+„Z"dAd.d/„Z#dBd0d1„Z$dCd5d6„Z%dDd9d:„Z&dS )Eé    )ÚannotationsN)ÚSequenceÚcastÚoverload)ÚTypeVarÚ	TypeGuardé   )Ú	FileTypesÚFileContentÚRequestFilesÚHttpxFileTypesÚBase64FileInputÚHttpxFileContentÚHttpxRequestFiles)Úis_listÚ
is_mappingÚ
is_tuple_tÚis_mapping_tÚis_sequence_tÚ_TÚobjÚobjectÚreturnúTypeGuard[Base64FileInput]c                 C  s   t | tjƒpt | tjƒS ©N)Ú
isinstanceÚioÚIOBaseÚosÚPathLike©r   © r!   úP/home/dinkstrade/pdmp-scanner/venv/lib/python3.10/site-packages/openai/_files.pyÚis_base64_file_input   s   r#   úTypeGuard[FileContent]c                 C  s"   t | tƒpt | tjƒpt | tjƒS r   )r   Úbytesr   r   r   r   r    r!   r!   r"   Úis_file_content   s   "r&   )Úkeyr'   ú
str | NoneÚNonec                C  sR   t | ƒs%t| ƒs'|d urd|› d�nd| ›d�}t|› dt| ƒ› d�ƒd ‚d S d S )NzExpected entry at `ú`zExpected file input `zF to be bytes, an io.IOBase instance, PathLike or a tuple but received zL instead. See https://github.com/openai/openai-python/tree/main#file-uploads)r&   r   ÚRuntimeErrorÚtype)r   r'   Úprefixr!   r!   r"   Úassert_is_file_content!   s    ÿþþr.   Úfilesc                 C  ó   d S r   r!   ©r/   r!   r!   r"   Úto_httpx_files)   ó   r2   r   r   c                 C  r0   r   r!   r1   r!   r!   r"   r2   -   r3   úRequestFiles | NoneúHttpxRequestFiles | Nonec                 C  sX   | d u rd S t | ƒrdd„ |  ¡ D ƒ} | S t| ƒr"dd„ | D ƒ} | S tdt| ƒ› d�ƒ‚)Nc                 S  s   i | ]	\}}|t |ƒ“qS r!   ©Ú_transform_file©Ú.0r'   Úfiler!   r!   r"   Ú
<dictcomp>6   s    z"to_httpx_files.<locals>.<dictcomp>c                 S  s   g | ]
\}}|t |ƒf‘qS r!   r6   r8   r!   r!   r"   Ú
<listcomp>8   ó    z"to_httpx_files.<locals>.<listcomp>úUnexpected file type input ú, expected mapping or sequence©r   Úitemsr   Ú	TypeErrorr,   r1   r!   r!   r"   r2   1   s   ûþr:   r	   r   c                 C  sb   t | ƒrt| tjƒrt | ¡}|j| ¡ fS | S t| ƒr-| d t	| d ƒg| dd … ¢R S t
dƒ‚©Nr   r   é   zCExpected file types input to be a FileContent type or to be a tuple)r&   r   r   r   ÚpathlibÚPathÚnameÚ
read_bytesr   Úread_file_contentrB   ©r:   Úpathr!   r!   r"   r7   ?   s   
"r7   r
   r   c                 C  s   t | tjƒrt | ¡ ¡ S | S r   )r   r   r   rE   rF   rH   ©r:   r!   r!   r"   rI   M   s   rI   c                 Ã  ó   �d S r   r!   r1   r!   r!   r"   Úasync_to_httpx_filesS   ó   €rN   c                 Ã  rM   r   r!   r1   r!   r!   r"   rN   W   rO   c                 Ã  sf   �| d u rd S t | ƒrdd„ |  ¡ D ƒI d H } | S t| ƒr)dd„ | D ƒI d H } | S tdt| ƒ› d�ƒ‚)Nc                 Ó  s"   �i | ]\}}|t |ƒI d H “qS r   ©Ú_async_transform_filer8   r!   r!   r"   r;   `   s   €  z(async_to_httpx_files.<locals>.<dictcomp>c                 Ó  s$   �g | ]\}}|t |ƒI d H f‘qS r   rP   r8   r!   r!   r"   r<   b   s   €" z(async_to_httpx_files.<locals>.<listcomp>r>   r?   r@   r1   r!   r!   r"   rN   [   s   €ûþc                 Ã  sp   �t | ƒrt| tjƒrt | ¡}|j| ¡ I d H fS | S t| ƒr4| d t	| d ƒI d H g| dd … ¢R S t
dƒ‚rC   )r&   r   r   r   ÚanyiorF   rG   rH   r   Úasync_read_file_contentrB   rJ   r!   r!   r"   rQ   i   s   €
(rQ   c                 Ã  s&   �t | tjƒrt | ¡ ¡ I d H S | S r   )r   r   r   rR   rF   rH   rL   r!   r!   r"   rS   w   s   €rS   ÚitemÚpathsúSequence[Sequence[str]]c                 C  s   t | |dƒS )aP  Copy only the containers along the given paths.

    Used to guard against mutation by extract_files without copying the entire structure.
    Only dicts and lists that lie on a path are copied; everything else
    is returned by reference.

    For example, given paths=[["foo", "files", "file"]] and the structure:
        {
            "foo": {
                "bar": {"baz": {}},
                "files": {"file": <content>}
            }
        }
    The root dict, "foo", and "files" are copied (they lie on the path).
    "bar" and "baz" are returned by reference (off the path).
    r   ©Ú_deepcopy_with_paths)rT   rU   r!   r!   r"   Údeepcopy_with_paths~   s   rY   ÚindexÚintc                   sÒ   |s| S t | ƒrFi }|D ]}ˆt|ƒk r| |ˆ g ¡ |¡ q|s$| S t| ƒ}| ¡ D ]\}}||v r@t|| |ˆd ƒ||< q,tt|ƒS t	| ƒrg‡fdd„|D ƒ‰ ˆ sZtt| ƒS tt‡ ‡fdd„| D ƒƒS | S )Nr   c                   s(   g | ]}ˆ t |ƒk r|ˆ  d kr|‘qS )z<array>)Úlen)r9   rK   )rZ   r!   r"   r<   ¥   s   ( z(_deepcopy_with_paths.<locals>.<listcomp>c                   s   g | ]
}t |ˆ ˆd  ƒ‘qS )r   rW   )r9   Úentry©Úarray_pathsrZ   r!   r"   r<   ª   r=   )
r   r\   Ú
setdefaultÚappendÚdictrA   rX   r   r   r   )rT   rU   rZ   Úkey_to_pathsrK   Úresultr'   Úsubpathsr!   r^   r"   rX   ’   s,   €€

rX   )r   r   r   r   )r   r   r   r$   )r   r   r'   r(   r   r)   )r/   r)   r   r)   )r/   r   r   r   )r/   r4   r   r5   )r:   r	   r   r   )r:   r
   r   r   )rT   r   rU   rV   r   r   )rT   r   rU   rV   rZ   r[   r   r   )'Ú
__future__r   r   r   rE   Útypingr   r   r   Útyping_extensionsr   r   rR   Ú_typesr	   r
   r   r   r   r   r   Ú_utilsr   r   r   r   r   r   r#   r&   r.   r2   r7   rI   rN   rQ   rS   rY   rX   r!   r!   r!   r"   Ú<module>   s:    $	








