L iSCUddlmZddlZddlZddlZddlZddlZddlmZm Z m Z m Z m Z m Z mZmZmZmZddlmZmZmZmZmZddlZddlZddlZddlmZddlmZmZm Z m!Z!ddl"m#Z#m$Z$m%Z%dd l&m'Z'dd l(m)Z)m*Z*m+Z+m,Z,dd l-m.Z.dd l/m0Z0m1Z1er dd l"m2Z2ddl3m4Z4edZ5e dZ6e dZ7e ddZ8ejre:Z;deZ?ddZ@d dZAGddZBy)!) annotationsN) TYPE_CHECKINGAnyUnionGenericTypeVarCallableIterator AsyncIteratorcastoverload) Awaitable ParamSpecoverride deprecated get_origin)NoneType)is_givenextract_type_argis_annotated_typeis_type_alias_type) BaseModel is_basemodeladd_request_id)RAW_RESPONSE_HEADER)Stream AsyncStreamis_stream_class_typeextract_stream_chunk_type)APIResponseValidationError) JSONLDecoderAsyncJSONLDecoder)FinalRequestOptions) BaseClientPR_T_T_coT) covariantzlogging.LoggerlogceZdZUdZded<ded<ded<ded <d ed <d ed <ded<ded< dd d'dZed(dZed)dZ ed*dZ ddd+dZ ed,dZ ed-dZ ed.dZ ed/dZ ed0dZed1d Zed0d!Zed0d"Zed2d#Zed3d$Zddd+d%Zed0d&Zy)4LegacyAPIResponseaThis is a legacy class as it will be replaced by `APIResponse` and `AsyncAPIResponse` in the `_response.py` file in the next major release. For the sync client this will mostly be the same with the exception of `content` & `text` will be methods instead of properties. In the async client, all methods will be async. A migration script will be provided & the migration in general should be smooth. type[R]_cast_toBaseClient[Any, Any]_clientzdict[type[Any], Any]_parsed_by_typebool_stream1type[Stream[Any]] | type[AsyncStream[Any]] | None _stream_clsr$_optionshttpx.Response http_responseint retries_takenr)r;ct||_||_i|_||_||_||_||_||_yN)r/r1r2r4r6r7r9r;)selfrawcast_toclientstream stream_clsoptionsr;s `/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/anthropic/_legacy_response.py__init__zLegacyAPIResponse.__init__Hs@   ! %  *cL|jjjdS)Nz request-id)r9headersgetr>s rE request_idzLegacyAPIResponse.request_id\s!!))--l;;rGcyr=)r>tos rEparsezLegacyAPIResponse.parse`s,/rGcyr=rNrKs rErPzLegacyAPIResponse.parsecsrGNrOc||n |j}|jj|}||S|j|}t |j j r|j j |}t|trt||j||j|<tt|S)aReturns the rich python representation of this response's data. NOTE: For the async client: this will become a coroutine in the next major version. For lower-level control, see `.read()`, `.json()`, `.iter_bytes()`. You can customise the type that the response is parsed into through the `to` argument, e.g. ```py from anthropic import BaseModel class MyModel(BaseModel): foo: str obj = response.parse(to=MyModel) print(obj.foo) ``` We support parsing: - `BaseModel` - `dict` - `list` - `Union` - `str` - `int` - `float` - `httpx.Response` rR) r/r2rJ_parserr7 post_parser isinstancerrrLr r')r>rO cache_keycachedparseds rErPzLegacyAPIResponse.parsefs@.Bdmm %%)))4  M# DMM-- .]]..v6F fi ( 64?? 3*0Y'AvrGc.|jjSr=)r9rIrKs rErIzLegacyAPIResponse.headers!!)))rGc.|jjSr=)r9requestrKs rE http_requestzLegacyAPIResponse.http_requestr[rGc.|jjSr=)r9 status_coderKs rEr`zLegacyAPIResponse.status_codes!!---rGc.|jjSr=)r9urlrKs rErbzLegacyAPIResponse.urls!!%%%rGc.|jjSr=)r^methodrKs rErdzLegacyAPIResponse.methods  '''rGc.|jjS)zReturn the binary response content. NOTE: this will be removed in favour of `.read()` in the next major version. )r9contentrKs rErfzLegacyAPIResponse.contents!!)))rGc.|jjS)zyReturn the decoded response content. NOTE: this will be turned into a method in the next major version. )r9textrKs rErhzLegacyAPIResponse.texts !!&&&rGc.|jjSr=)r9 http_versionrKs rErjzLegacyAPIResponse.http_versions!!...rGc.|jjSr=)r9 is_closedrKs rErlzLegacyAPIResponse.is_closeds!!+++rGc.|jjS)zCThe time taken for the complete request/response cycle to complete.)r9elapsedrKs rErnzLegacyAPIResponse.elapseds!!)))rGc ||n |j}t|r |j}|rt|r t |d}t |xs|}t j|rttt|trQtttd||jjdt |d|jSttt|trQtttd||jj!dt |d|jS|j"r6|rjt%|st'dt(dt*tt,|t/|d |jtt|j0 S|j2rWtt|j3t/|j2|jtt|j0 Std |j0j4}| t7tt|||jtt|j0 S|t8urttdS|j}|t:k(rtt|j<S|t>k(r#ttt?|j<S|t@k(r#tttA|j<S|tBk(r+tt|j<jEd k(St j|r&t|tFrtt||S|tHk(r tKdt j|rHt|tLjNr.|tLjNk7r tQdtt|St j|r5t|tRs%t|tTjRr t'd|tVurr|tXurj|tZurb|t\urZt|tRsJtKd|dtRdtZdtXdt\dt8dt:dtLjNd|j^jaddjcd^}}|jedsxtg|r/ |ji}|j0jk|||S|j0jtrtw|d|d|j<|j<S|ji}|j0jk|||S#tl$r*} tnjqdts| | Yd} ~ d} ~ wwxYw)Nrztype[JSONLDecoder[Any]]@ chunk_size) raw_iterator line_typer9ztype[AsyncJSONLDecoder[Any]]z/Expected custom parse type to be a subclass of z or zUExpected custom stream type to be passed with a type argument, e.g. Stream[ChunkType])failure_message)r@responserAr5truez+Unexpected state - cast_to is `APIResponse`z:Subclasses of httpx.Response cannot be passed to `cast_to`zYPydantic models must subclass our base model type, e.g. `from anthropic import BaseModel`zUnsupported type, expected z to be a subclass of z, .z content-type*;json)datar@rvz5Could not read JSON from response data due to %s - %szMExpected Content-Type response header to be `application/json` but received `z ` instead.)rvmessagebody)rOr@originrCrv content_type_r|excs rErTzLegacyAPIResponse._parsesW"DMM g &''G (1&w2GG$/ ??6 "$sF+\:&*&8&8$sF+->?AD7A%)%7%7%C%Cr%C%R"27A">&*&8&8 <<+B/#&UV\U]]abman$opp 9-D!"&!3!3#C6   $$ 9$:J:J K!%!3!3#C6%QSWS_S_SsSstJ!-//#!//T\\2  h 4= %% c>8==) ) c>3x}}-. . e 5/0 0 d?8==..0F:; ; ??6 "z&:T'U78,- - & &LM M ??  0 %..( #]__8$ $ OO vy168#5#56wx x 6 !dNdNeOvy1-gY6KI;VXY]X^^`ae`ffhinhooqrzq{{}B~CCGHMHVHVGWWXY  $++//DJJ3O q$$V,G$ #==?D <<>>! '!)? ||770%klxkyzDE!== }}||223  /!gIIUW[\_W`beffgsV-- W 6 WW cjd|jd|jjd|jdS)Nz)r`r9 reason_phraser/rKs rE__repr__zLegacyAPIResponse.__repr__ks; 0 0143E3E3S3S2TT[\`\i\i[jjkllrG)r?r8r@r.rAr0rBr3rCr5rDr$r;r:returnNonerz str | None)rOztype[_T]rr()rr')rOztype[_T] | NonerzR | _T)rz httpx.Headers)rz httpx.Request)rr:)rz httpx.URLrrrbytes)rr3)rzdatetime.timedelta)__name__ __module__ __qualname____doc____annotations__rFpropertyrLr rPrIr^r`rbrdrfrhrjrlrnrTrrrNrGrEr-r-/s  !!)) MBB!!!!M++ + % +  +F+%++ +(<<// -1-^****..&&((**''//,,**/3b HmmrGr-c eZdZdfd ZxZS)rc$t|dy)Nz}The `stream` argument was set to `True` but the `stream_cls` argument was not given. See `anthropic._streaming` for reference)superrF)r> __class__s rErFz MissingStreamClassError.__init__qs  L rGrr)rrrrF __classcell__)rs@rErrps   rGrcDtjdfd }|S)Higher order function that takes one of our bound API methods and wraps it to support returning the raw `APIResponse` object directly. citt|jdxsi}d|t<||d<ttt |i|SN extra_headersrwr rrJrr-r'argskwargsrfuncs rEwrappedz(to_raw_response_wrapper..wrapped|sU(ZDfjj6Q,R,XVX(Z -3 )*"/%a($*?*?@@rGrzP.argsrzP.kwargsrzLegacyAPIResponse[R] functoolswrapsrrs` rEto_raw_response_wrapperrws) __TAA NrGcDtjdfd }|S)rcKitt|jdxsi}d|t<||d<ttt |i|d{S7wrrrs rErz.async_to_raw_response_wrapper..wrappeds_(ZDfjj6Q,R,XVX(Z -3 )*"/%a(d0Ef0E*EFF*EsAAA  Arrrs` rEasync_to_raw_response_wrapperrs) __TGG NrGcHeZdZUded<ddZeddZeddZeddZeddZ ddZ dd Z d d!d Z d d"d Z d#d Zd d!dZ d$dZedd d d%dZd&dZddZd d'dZd d(dZd)dZd d'dZedd d d%dZd&dZy )*rr8rvc||_yr=)rv)r>rvs rErFz#HttpxBinaryResponseContent.__init__s   rGc.|jjSr=)rvrfrKs rErfz"HttpxBinaryResponseContent.contents}}$$$rGc.|jjSr=)rvrhrKs rErhzHttpxBinaryResponseContent.texts}}!!!rGc.|jjSr=)rvencodingrKs rErz#HttpxBinaryResponseContent.encodings}}%%%rGc.|jjSr=)rvcharset_encodingrKs rErz+HttpxBinaryResponseContent.charset_encodings}}---rGc :|jjdi|S)NrN)rvr{)r>rs rEr{zHttpxBinaryResponseContent.jsons!t}}!!+F++rGc6|jjSr=)rvreadrKs rErzHttpxBinaryResponseContent.reads}}!!##rGNc8|jj|Sr=)rvrr>rrs rErz%HttpxBinaryResponseContent.iter_bytess}}'' 33rGc8|jj|Sr=)rv iter_textrs rErz$HttpxBinaryResponseContent.iter_texts}}&&z22rGc6|jjSr=)rv iter_linesrKs rErz%HttpxBinaryResponseContent.iter_liness}}''))rGc8|jj|Sr=)rviter_rawrs rErz#HttpxBinaryResponseContent.iter_raws}}%%j11rGct|d5}|jjD]}|j| dddy#1swYyxYw)avWrite the output to the given file. Accepts a filename or any path-like object, e.g. pathlib.Path Note: if you want to stream the data to the file instead of writing all at once then you should use `.with_streaming_response` when making the API request, e.g. `client.with_streaming_response.foo().stream_to_file('my_filename.txt')` wbmodeNopenrvrwrite)r>filefr|s rE write_to_filez(HttpxBinaryResponseContent.write_to_filesL$T " a 002      s 1A  AzDue to a bug, this method doesn't actually stream the response content, `.with_streaming_response.method()` should be used insteadrqct|d5}|jj|D]}|j| dddy#1swYyxYwNrrr)r>rrrrr|s rEstream_to_filez)HttpxBinaryResponseContent.stream_to_filesN$T " a 00<      s 2A  Ac6|jjSr=)rvcloserKs rErz HttpxBinaryResponseContent.closes}}""$$rGcRK|jjd{S7wr=)rvareadrKs rErz HttpxBinaryResponseContent.areads]]((**** '%'c@K|jj|Swr=)rvrrs rErz&HttpxBinaryResponseContent.aiter_bytess}}((44c@K|jj|Swr=)rv aiter_textrs rErz%HttpxBinaryResponseContent.aiter_texts}}'' 33rc>K|jjSwr=)rv aiter_linesrKs rErz&HttpxBinaryResponseContent.aiter_liness}}((**sc@K|jj|Swr=)rv aiter_rawrs rErz$HttpxBinaryResponseContent.aiter_raws}}&&z22rcVKtj|}|jdd{4d{}|jj |23d{}|j |d{#7K7D7"7 6dddd{7y#1d{7swYyxYwwr)anyioPathrrvrr)r>rrrpathrr|s rEastream_to_filez*HttpxBinaryResponseContent.astream_to_fileszz$-- $ $"mm77 C $ $dggdm##. $ $#D $ $ $ $ $s+B)A9B)A;B)BBA=BB3A?4B9B);B)=B?BB B) BB)B&B B&"B)cRK|jjd{S7wr=)rvacloserKs rErz!HttpxBinaryResponseContent.acloses]]))++++r)rvr8rrrrr)rrrrr=)rr int | NonerzIterator[bytes])rrrr Iterator[str])rr)rstr | os.PathLike[str]rr)rrrrrrrr)rrrrzAsyncIterator[bytes])rrrrAsyncIterator[str])rr)rrrrrFrrfrhrrr{rrrrrrrrrrrrrrrrrNrGrErrs5!%%""&&..,$43*2$   M"& $   %+54+3 M"& $$ $ $  $ $,rGr)rzCallable[P, R]rz!Callable[P, LegacyAPIResponse[R]])rzCallable[P, Awaitable[R]]rz,Callable[P, Awaitable[LegacyAPIResponse[R]]])C __future__rosrloggingdatetimertypingrrrrrr r r r r typing_extensionsrrrrrrrr_typesr_utilsrrrr_modelsrrr _constantsr _streamingrrrr _exceptionsr!_decoders.jsonlr"r#r$ _base_clientr%r&r'r(r) getLoggerrr+rr-rrrrrrNrGrErs"    UT UU<<+\\3<,(cN CL T]4('g''1^1~m ~mB  i ""f,f,rG