B
    f                 @  sh  d dl mZ d dlZd dlZd dlZd dlmZ d dl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 dd	d
ddZddd
ddZddddddddZedddddZedddddZdddddZdd d!d"d#Zd$d%d!d&d'Zedddd(d)Zedddd*d)Zdddd+d)Zdd d!d,d-Zd$d%d!d.d/ZdS )0    )annotationsN)overload)	TypeGuard   )	FileTypesFileContentRequestFilesHttpxFileTypesBase64FileInputHttpxFileContentHttpxRequestFiles)
is_tuple_tis_mapping_tis_sequence_tobjectzTypeGuard[Base64FileInput])objreturnc             C  s   t | tjpt | tjS )N)
isinstanceioIOBaseosPathLike)r    r   S/home/ankuromar296_gmail_com/.local/lib/python3.7/site-packages/anthropic/_files.pyis_base64_file_input   s    r   zTypeGuard[FileContent]c             C  s,   t | tp*t | tp*t | tjp*t | tjS )N)r   bytestupler   r   r   r   )r   r   r   r   is_file_content   s    r   )keyz
str | NoneNone)r   r   r   c            C  sF   t | sB|d k	rd| dn
d| d}t| dt|  dd d S )NzExpected entry at ``zExpected file input `zF to be bytes, an io.IOBase instance, PathLike or a tuple but received z	 instead.)r   RuntimeErrortype)r   r   prefixr   r   r   assert_is_file_content!   s
     r$   )filesr   c             C  s   d S )Nr   )r%   r   r   r   to_httpx_files)   s    r&   r   r   c             C  s   d S )Nr   )r%   r   r   r   r&   .   s    zRequestFiles | NonezHttpxRequestFiles | Nonec             C  sX   | d krd S t | r(dd |  D } n,t| r@dd | D } ntdt|  d| S )Nc             S  s   i | ]\}}t ||qS r   )_transform_file).0r   filer   r   r   
<dictcomp>8   s    z"to_httpx_files.<locals>.<dictcomp>c             S  s   g | ]\}}|t |fqS r   )r'   )r(   r   r)   r   r   r   
<listcomp>:   s    z"to_httpx_files.<locals>.<listcomp>zUnexpected file type input z, expected mapping or sequence)r   itemsr   	TypeErrorr"   )r%   r   r   r   r&   3   s    r   r	   )r)   r   c             C  sd   t | r0t| tjr,t| }|j| fS | S t| rX| d t	| d f| dd  S t
dd S )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_contentr-   )r)   pathr   r   r   r'   A   s    
 r'   r   r   c             C  s   t | tjrt|  S | S )N)r   r   r   r/   r0   r2   )r)   r   r   r   r3   O   s    r3   c               s   d S )Nr   )r%   r   r   r   async_to_httpx_filesU   s    r5   c               s   d S )Nr   )r%   r   r   r   r5   Z   s    c               sX   | d krd S t | r.dd |  D I d H } n&t| rLdd | D I d H } ntd| S )Nc               s    i | ]\}}t |I d H |qS )N)_async_transform_file)r(   r   r)   r   r   r   r*   d   s    z(async_to_httpx_files.<locals>.<dictcomp>c               s"   g | ]\}}|t |I d H fqS )N)r6   )r(   r   r)   r   r   r   r+   f   s    z(async_to_httpx_files.<locals>.<listcomp>zFUnexpected file type input {type(files)}, expected mapping or sequence)r   r,   r   r-   )r%   r   r   r   r5   _   s    c               sp   t | r6t| tjr2t| }|j| I d H fS | S t| rd| d t	| d I d H f| dd  S t
dd S )Nr   r   r.   zCExpected file types input to be a FileContent type or to be a tuple)r   r   r   r   anyior0   r1   r2   r   _async_read_file_contentr-   )r)   r4   r   r   r   r6   m   s    
&r6   c               s$   t | tjr t|  I d H S | S )N)r   r   r   r7   r0   r2   )r)   r   r   r   r8   {   s    r8   )
__future__r   r   r   r/   typingr   typing_extensionsr   r7   _typesr   r   r   r	   r
   r   r   _utilsr   r   r   r   r   r$   r&   r'   r3   r5   r6   r8   r   r   r   r   <module>   s*   $	