
    i                    J   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	Zdd
ZddddZedd       Zedd       ZddZddZ d dZ!edd       Z"edd       Z"ddZ"ddZ#d dZ$d!dZ%d"dZ&y)#    )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_Tc                n    t        | t        j                        xs t        | t        j                        S N)
isinstanceioIOBaseosPathLikeobjs    I/home/work/apex_v16/venv/lib/python3.12/site-packages/anthropic/_files.pyis_base64_file_inputr!      s#    c299%EC)EE    c                    t        | t              xsH t        | t              xs6 t        | t        j                        xs t        | t
        j                        S r   )r   bytestupler   r   r   r   r   s    r    is_file_contentr&      sB    3v*S%"8vJsBII<VvZdehjljujuZvr"   )keyc               l    t        |       s)|d| dnd| d}t        | dt        |        d      d y )NzExpected entry at ``zExpected file input `zF to be bytes, an io.IOBase instance, PathLike or a tuple but received zW instead. See https://github.com/anthropics/anthropic-sdk-python/tree/main#file-uploads)r&   RuntimeErrortype)r   r'   prefixs      r    assert_is_file_contentr-   #   sb    314&se1-H]^a]ddeFfh\]abe]f\g  h  @
	  r"   c                     y r    filess    r    to_httpx_filesr2   +   s    ),r"   c                     y r   r/   r0   s    r    r2   r2   /   s    >Ar"   c                   | y t        |       r.| j                         D ci c]  \  }}|t        |       } }}| S t        |       r!| D cg c]  \  }}|t        |      f } }}| S t	        dt        |        d      c c}}w c c}}w )NzUnexpected file type input z, expected mapping or sequence)r   items_transform_filer   	TypeErrorr+   r1   r'   files      r    r2   r2   3   s    }E=B[[]K	Tod++KK L 
u	?DE)#t#t,-EE L 5d5k]B`abb	 LEs   BBc                   t        |       rMt        | t        j                        r1t	        j
                  |       }|j                  |j                         fS | S t        |       r| d   t        | d         g| dd  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_contentr7   r9   paths     r    r6   r6   A   sy    tdBKK(<<%DIIt011$Q*473?d12h??
Y
[[r"   c                    t        | t        j                        r#t        j                  |       j                         S | S r   )r   r   r   r=   r>   r@   r9   s    r    rA   rA   O   s-    $$||D!,,..Kr"   c                   K   y wr   r/   r0   s    r    async_to_httpx_filesrG   U   s	     58   c                   K   y wr   r/   r0   s    r    rG   rG   Y   s	     JMrH   c                0  K   | y t        |       r6| j                         D ci c]  \  }}|t        |       d {    } }}| S t        |       r)| D cg c]  \  }}|t        |       d {   f } }}| S t	        d      7 Jc c}}w 7 c c}}w w)NzFUnexpected file type input {type(files)}, expected mapping or sequence)r   r5   _async_transform_filer   r7   r8   s      r    rG   rG   ]   s     }EINWIC1$777WW L 
u	KPQic4#24889QQ L `aa	 8W8QsJ   "BBBBBB.B/B6BBBBBc                @  K   t        |       rUt        | t        j                        r9t	        j
                  |       }|j                  |j                          d {   fS | S t        |       r!| d   t        | d          d {   g| dd  S t        d      7 >7 wr;   )r&   r   r   r   anyior>   r?   r@   r   async_read_file_contentr7   rB   s     r    rK   rK   k   s     tdBKK(::d#DIIT__%6677$Q6tAw??K$qr(KK
Y
[[  7
 @s$   ABB'BBBBc                   K   t        | t        j                        r+t        j                  |       j                          d {   S | S 7 wr   )r   r   r   rM   r>   r@   rE   s    r    rN   rN   y   s9     $$ZZ%00222K 3s   AAA
Ac                    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)itempathss     r    deepcopy_with_pathsrT      s    "  eQ//r"   c                4   |s| S t        |       ri }|D ]5  }|t        |      k  s|j                  ||   g       j                  |       7 |s| S t	        |       }|j                         D ]   \  }}||v st        ||   ||dz         ||<   " t        t        |      S t        |       re|D cg c]  }|t        |      k  s||   dk(  s| }}|st        t        |       S t        t        | D 	cg c]  }	t        |	||dz          c}	      S | S c c}w c c}	w )Nr	   z<array>)
r   len
setdefaultappenddictr5   rQ   r   r   r   )
rR   rS   indexkey_to_pathsrC   resultr'   subpathsarray_pathsentrys
             r    rQ   rQ      s0   $79 	FDs4y ''UR8??E	F
 Kd)//1 	UMCf}26#;%RS)Ts	U Bt}(-`T1BtE{V_G_t`` D>!BZ^_QV-e[%!)L_``K a
 `s   -DD
D0D
)r   objectreturnzTypeGuard[Base64FileInput])r   r`   ra   zTypeGuard[FileContent])r   r`   r'   z
str | Nonera   None)r1   rb   ra   rb   )r1   r   ra   r   )r1   zRequestFiles | Nonera   zHttpxRequestFiles | None)r9   r
   ra   r   )r9   r   ra   r   )rR   r   rS   Sequence[Sequence[str]]ra   r   )rR   r   rS   rc   rZ   intra   r   )'
__future__r   r   r   r=   typingr   r   r   typing_extensionsr   r   rM   _typesr
   r   r   r   r   r   r   _utilsr   r   r   r   r   r   r!   r&   r-   r2   r6   rA   rG   rK   rN   rT   rQ   r/   r"   r    <module>rj      s    " 	 	  + + 0    Q PT]F >B  
 , 
 , 
 A 
 A\ 
 8 
 8 
 M 
 M\0(r"   