L i/ddlmZddlZddlZddlZddlZddlmZmZm Z m Z m Z m Z m Z mZmZddlmZddlmZmZddlmZddlZddlmZmZmZmZe d Ze d eed f Ze d e eef Z e de e Z!e de d ef Z"d9dZ# d:dZ$ d;dZ%ddZ(d?dZ)d@dZ*dAdZ+dBdZ,dCdZ-dDdZ.dEdZ/dFdZ0ddd dGd!Z1dHd"Z2dId#Z3e d$Z4e d%Z5edJd&Z6edKd'Z6edLd(Z6dMd)Z6dNd*Z7dOd+Z8dPd,Z9dQd-Z:dRd.Z;dSd/ZdVd2Z?dWd3Z@dXd4ZAd5d6dYd7ZBdZd8ZCy)[) annotationsN) AnyTupleMappingTypeVarCallableIterableSequencecastoverload)Path)datedatetime) TypeGuard)OmitNotGiven FileTypes HeadersLike_T_TupleT.)bound _MappingT _SequenceT CallableTc@|Dcgc] }|D]}| c}}Scc}}wN)tsublistitems ]/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/anthropic/_utils/_utils.pyflattenr#!s" ! 6Wg 6dD 6D 66 6sc Tg}|D] }|jt||dd"|S)zRecursively extract files from the given dictionary based on specified paths. A path may look like this ['foo', 'files', '', 'data']. Note: this mutates the given dictionary. rNindex flattened_key)extend_extract_items)querypathsfilespaths r" extract_filesr.%s6*,EO ^E4qMNO Lc  ||}|dz }t|rC t||k(r|j|}n||}||}n |d|dz }t|||| St |r4|d k7rgSt|Dcgc]}t|||||dznd c}SgS#t$rt|sgcYSddlm}|Jt |rBg}|D]7}|||r|dznd|j |dzt t|f9|cYS||||t t|fgcYSwxYw#t$rgcYSwxYwcc}w) Nr)assert_is_file_contentz[])key[]r%z) IndexErroris_given_filesr1is_listappendr ris_dictlenpopKeyErrorr)r#) objr-r&r'r3r1r,entryr!s r"r)r)8s75k, QJEs| D e#wws|3x  M qQZ 'M  '    ) I   :G:S-$"6Y]     I{ 7}I 4((( 3<13E M&u--$2F]_` md2DE4JKL MLs 6Y 4566'7: I  ( s5B%D-5D>D*3AD* D*)D*- D;:D;cJt|t xrt|t Sr) isinstancerrr@s r"r8r8s!#x( ( FC1F-FFr/c"t|tSrrCtuplerDs r"is_tuplerH c5 !!r/c"t|tSrrFrDs r" is_tuple_trKrIr/c"t|tSrrCr rDs r" is_sequencerN c8 $$r/c"t|tSrrMrDs r" is_sequence_trQrOr/c"t|tSrrCrrDs r" is_mappingrT c7 ##r/c"t|tSrrSrDs r" is_mapping_trWrUr/c"t|tSr)rCdictrDs r"r<r< c4  r/c"t|tSr)rClistrDs r"r:r:rZr/c"t|tSr)rCr rDs r" is_iterabler^rOr/c  t|r;tt|jDcic]\}}|t |c}}St |r'tt|Dcgc] }t |c}S|Scc}}wcc}w)zMinimal reimplementation of copy.deepcopy() that will only copy certain object types: - mappings, e.g. `dict` - list This is done for performance reasons. )rTr ritemsdeepcopy_minimalr:)r!kvrAs r"rarasl$BDJJLIDAq,Q//IJJt}BdCU)%0CDD KJCs A; B z, or)delimfinalct|}|dk(ry|dk(r|dS|dk(r|dd|d|dS|j|ddd|d|dzS)Nrr2r4r )r=join)seqrerfsizes r" human_joinrmsv s8D qy qy1v  qya&5'3q6(++ ::c#2h AeWAc"gY"7 77r/cd|dS)zOAdd single quotation marks around the given string. Does *not* do any escaping.'r)strings r"quoterqs vha=r/cdfd }|S)a4Decorator to enforce a given set of arguments or variants of arguments are passed to the decorated function. Useful for enforcing runtime validation of overloaded functions. Example usage: ```py @overload def foo(*, a: str) -> str: ... @overload def foo(*, b: bool) -> str: ... # This enforces the same constraints that a static type checker would # i.e. that either a or b must be passed to the function @required_args(["a"], ["b"]) def foo(*, a: str | None = None, b: bool | None = None) -> str: ... ``` c$tjj}|jDcgc]+\}}|j|j |j hvr|-c}}tjdfd }|Scc}}w)Ncl t t|D]\}} j ||jD]} j|D]}t fd|D}|snt dkDrTtDcgc],}dt|Dcgc] }t|c}dzd z.c}}}d |d } t | t d kDsJttd  z } t | dkDr0d t| Dcgc] }t|c}} t | dt| d } t |  |i|S#t$r2t j dt dt |ddwxYwcc}wcc}}wcc}w)Nz () takes z argument(s) but z were givenc3&K|]}|v ywrr).0param given_paramss r" z@required_args..inner..wrapper..sJu 4Jsr4(and)rf)z,Missing required arguments; Expected either z arguments to be givenrzMissing required arguments: zMissing required argument: ) set enumerateaddr7 TypeError__name__r=keysallrmrqr\)argskwargsi_r3variantmatchesarg variationsmsgmissingrxfunc positionalvariantss @r"wrapperz-required_args..inner..wrappers%(UL!$ 1  $$Z]3 {{} &  % &$ %J'JK % x=1$!+muvbiz*I#5:*IQVWWZ]]v"JI TjkC n$x=1,,,#3x{#3l#BCG7|a' .inners""4(33 &||~ ezz%%++    ! ) ! )F] s0B )rrrrr)rrs` r" required_argsrs,0d Lr/_K_VcyrrrDs r"strip_not_givenr%s(+r/cyrrrDs r"rr)sFIr/cyrrrDs r"rr-s,/r/c|yt|s|S|jDcic]\}}t|tr||c}}Scc}}w)zHRemove all top-level keys where their values are instances of `NotGiven`N)rTr`rCr)r@r3values r"rr1sA { c? ), X:3Juhz%get_required_header..}s%#))A,STI[I[I]:]r/zCould not find z header) lowerrWr`rCstrresub capitalizerget ValueError)headersheader lower_headerrbrcintercaps_headernormalized_headerrs r"get_required_headerrts<<>LGMMO DAqwwyL(Z3-?  vvn.]_e_p_p_rs$lFLLNDTU -. L vhg6 77r/cJ tjS#t$rYywxYw)Nfalse)sniffiocurrent_async_library Exceptionrr/r"get_async_libraryrs(,,.. s  ""maxsizecNtj|}tt|S)zmA version of functools.lru_cache that retains the type signature for the wrapped function arguments. r)r lru_cacher r)rrs r"rrs&!!G W r/cht|r6|jDcic]\}}t|t|c}}St|r4t |t t tfs|Dcgc] }t|c}St |ttfr|jS|Scc}}wcc}w)zvTranslates a mapping / sequence recursively in the same fashion as `pydantic` v2's `model_dump(mode="json")`. ) rTr` json_safer^rCrbytes bytearrayrr isoformat)datar3rr!s r"rrs$CG::<PZS% # % 00PP4D3y2I!J,01D $11$4()~~ KQ2s B),B/)rzIterable[Iterable[_T]]rzlist[_T])r*zMapping[str, object]r+zSequence[Sequence[str]]rlist[tuple[str, FileTypes]]) r@rr- Sequence[str]r&rr' str | Nonerr)r@z_T | NotGiven | Omitrz TypeGuard[_T])r@rrzTypeGuard[tuple[object, ...]])r@z_TupleT | objectrzTypeGuard[_TupleT])r@rrzTypeGuard[Sequence[object]])r@z_SequenceT | objectrzTypeGuard[_SequenceT])r@rrzTypeGuard[Mapping[str, object]])r@z_MappingT | objectrzTypeGuard[_MappingT])r@rrzTypeGuard[dict[object, object]])r@rrzTypeGuard[list[object]])r@rrzTypeGuard[Iterable[object]])r!rrr)rkrrerrfrrr)rprrr)rrr Callable[[CallableT], CallableT])r@Nonerr)r@zMapping[_K, _V | NotGiven]rz dict[_K, _V])r@rrr)r@z object | Nonerr)rrrr)rrrr)rrrbool)rrr int | None)rrrz float | None)rrrz bool | None)rprrrrr)rprrrrr)r-rrr)rrrrrr)rr)rrrr)rrrr)D __future__rrrrrtypingrrrrrr r r r pathlibr rrtyping_extensionsrr_typesrrrrrrrrrrrr#r.r)r8rHrKrNrQrTrWr<r:r^rarmrqrrrrrrrrrrrrrrrrrrr/r"rs"    #';; T] )5#5 6 KwsF{'; < \&)9 : KxS'9 : 7  #  ! &F F F  F  F ! FRG""%%$$!!%  48d 8 HV T] T] + + I I / /Y6   ! 8&(+ r/