
    ̺iC                       % S SK Jr  S SKrS SKrS SKrS SKrS SKrS SKJrJ	r	J
r
JrJrJrJrJrJrJr  S SKJrJrJrJrJr  S SKrS SKrS SKrSSKJr  SSKJrJrJ r J!r!  SSK"J#r#J$r$J%r%  SS	K&J'r'  SS
K(J)r)J*r*J+r+J,r,  SSK-J.r.  SSK/J0r0J1r1  \(       a  SSK"J2r2  SSK3J4r4  \" S5      r5\" S5      r6\" S5      r7\" SSS9r8\Rr                  " \:5      r;S\<S'    " S S\\6   5      r= " S S\>5      r?SS jr@S S jrA " S S5      rBg)!    )annotationsN)
TYPE_CHECKINGAnyUnionGenericTypeVarCallableIteratorAsyncIteratorcastoverload)	Awaitable	ParamSpecoverride
deprecated
get_origin   )NoneType)is_givenextract_type_argis_annotated_typeis_type_alias_type)	BaseModelis_basemodeladd_request_id)RAW_RESPONSE_HEADER)StreamAsyncStreamis_stream_class_typeextract_stream_chunk_type)APIResponseValidationError)JSONLDecoderAsyncJSONLDecoder)FinalRequestOptions)
BaseClientPR_T_T_coT)	covariantzlogging.Loggerlogc                     \ rS rSr% SrS\S'   S\S'   S\S'   S	\S
'   S\S'   S\S'   S\S'   S\S'    SS.               S)S jjr\S*S j5       r\	S+S j5       r
\	S,S j5       r
SS.S-S jjr
\S.S j5       r\S/S j5       r\S0S j5       r\S1S j5       r\S2S  j5       r\S3S! j5       r\S2S" j5       r\S2S# j5       r\S4S$ j5       r\S5S% j5       rSS.S-S& jjr\S2S' j5       rS(rg)6LegacyAPIResponse/   a  This 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_toBaseClient[Any, Any]_clientzdict[type[Any], Any]_parsed_by_typebool_stream1type[Stream[Any]] | type[AsyncStream[Any]] | None_stream_clsr$   _optionshttpx.Responsehttp_responseintretries_takenr   )r<   c               f    X l         X0l        0 U l        X@l        XPl        X`l        Xl        Xpl        g N)r0   r2   r3   r5   r7   r8   r:   r<   )selfrawcast_toclientstream
stream_clsoptionsr<   s           Y/var/www/piano.thomer.com/venv/lib/python3.13/site-packages/anthropic/_legacy_response.py__init__LegacyAPIResponse.__init__H   s2      !% *    c                L    U R                   R                  R                  S5      $ )Nz
request-id)r:   headersgetr?   s    rF   
request_idLegacyAPIResponse.request_id\   s    !!))--l;;rI   c                   g r>    )r?   tos     rF   parseLegacyAPIResponse.parse`   s    ,/rI   c                    g r>   rQ   rM   s    rF   rS   rT   c   s    rI   NrR   c                  Ub  UOU R                   nU R                  R                  U5      nUb  U$ U R                  US9n[	        U R
                  R                  5      (       a  U R
                  R                  U5      n[        U[        5      (       a  [        X@R                  5        X@R                  U'   [        [        U5      $ )a9  Returns 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`
rV   )r0   r3   rL   _parser   r8   post_parser
isinstancer   r   rN   r   r'   )r?   rR   	cache_keycachedparseds        rF   rS   rT   f   s    @ .Bdmm	%%)))4M#DMM--..]]..v6Ffi((6??3*0Y'AvrI   c                .    U R                   R                  $ r>   )r:   rK   rM   s    rF   rK   LegacyAPIResponse.headers       !!)))rI   c                .    U R                   R                  $ r>   )r:   requestrM   s    rF   http_requestLegacyAPIResponse.http_request   r`   rI   c                .    U R                   R                  $ r>   )r:   status_coderM   s    rF   rf   LegacyAPIResponse.status_code   s    !!---rI   c                .    U R                   R                  $ r>   )r:   urlrM   s    rF   ri   LegacyAPIResponse.url   s    !!%%%rI   c                .    U R                   R                  $ r>   )rc   methodrM   s    rF   rl   LegacyAPIResponse.method   s      '''rI   c                .    U R                   R                  $ )zrReturn the binary response content.

NOTE: this will be removed in favour of `.read()` in the
next major version.
)r:   contentrM   s    rF   ro   LegacyAPIResponse.content   s     !!)))rI   c                .    U R                   R                  $ )ziReturn the decoded response content.

NOTE: this will be turned into a method in the next major version.
)r:   textrM   s    rF   rr   LegacyAPIResponse.text   s     !!&&&rI   c                .    U R                   R                  $ r>   )r:   http_versionrM   s    rF   ru   LegacyAPIResponse.http_version   s    !!...rI   c                .    U R                   R                  $ r>   )r:   	is_closedrM   s    rF   rx   LegacyAPIResponse.is_closed   s    !!+++rI   c                .    U R                   R                  $ )zCThe time taken for the complete request/response cycle to complete.)r:   elapsedrM   s    rF   r{   LegacyAPIResponse.elapsed   s     !!)))rI   c                  Ub  UOU R                   n[        U5      (       a  UR                  nU(       a  [        U5      (       a  [	        US5      n[        U5      =(       d    Un[        R                  " U5      (       a  [        [        [        U5      [        5      (       aK  [        [        [        SU5      " U R                  R                  SS9[	        US5      U R                  S95      $ [        [        [        U5      [        5      (       aK  [        [        [        SU5      " U R                  R!                  SS9[	        US5      U R                  S95      $ U R"                  (       Ga[  U(       at  [%        U5      (       d  ['        S[(         S[*         35      e[        [,        U" [/        US	S
9U R                  [        [        U R0                  5      U R2                  S95      $ U R4                  (       a_  [        [        U R5                  [/        U R4                  5      U R                  [        [        U R0                  5      U R2                  S95      $ [        SU R0                  R6                  5      nUc
  [9        5       e[        [        U" UU R                  [        [        U R0                  5      U R2                  S95      $ U[:        L a  [        [        S 5      $ U R                  nU[<        :X  a  [        [        UR>                  5      $ U[@        :X  a#  [        [        [A        UR>                  5      5      $ U[B        :X  a#  [        [        [C        UR>                  5      5      $ U[D        :X  a+  [        [        UR>                  RG                  5       S:H  5      $ [        R                  " U5      (       a+  [        U[H        5      (       a  [        [        U" U5      5      $ U[J        :X  a  [M        S5      e[        R                  " U5      (       aN  [        U[N        RP                  5      (       a/  U[N        RP                  :w  a  [S        S5      e[        [        U5      $ [        R                  " U5      (       a?  [        U[T        5      (       d*  [        U[V        RT                  5      (       a  ['        S5      eU[X        Laz  U[Z        Laq  U[\        Lah  U[^        La_  [        U[T        5      (       dJ  [M        SU S[T         S[\         S[Z         S[^         S[:         S[<         S[N        RP                   S35      eUR`                  Rc                  SS5      Re                  S5      tpgURg                  S5      (       d|  [i        U5      (       a,   URk                  5       nU R0                  Rm                  UUUS9$ U R0                  Rv                  (       a  [y        USU S3UR>                  S9eUR>                  $ URk                  5       nU R0                  Rm                  UUUS9$ ! [n         a*  n	[p        Rs                  S[u        U	5      U	5         S n	A	NS n	A	ff = f)Nr   ztype[JSONLDecoder[Any]]@   
chunk_size)raw_iterator	line_typer:   ztype[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)rA   responserB   rE   r6   truez+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`zUnsupported type, expected z to be a subclass of z, .zcontent-type*;json)datarA   r   z5Could not read JSON from response data due to %s - %szMExpected Content-Type response header to be `application/json` but received `z
` instead.)r   messagebody)=r0   r   	__value__r   r   r   inspectisclass
issubclassr   r   r"   r'   r:   
iter_bytesr#   aiter_bytesr5   r   	TypeErrorr   r   r(   r    r2   r8   r7   _default_stream_clsMissingStreamClassErrorr   strrr   r;   floatr4   lowerHttpxBinaryResponseContentr-   RuntimeErrorhttpxResponse
ValueErrorr   pydanticobjectlistdictr   rK   rL   splitendswithr   r   _process_response_data	Exceptionr+   debugtype_strict_response_validationr!   )
r?   rR   rA   originrD   r   content_type_r   excs
             rF   rX   LegacyAPIResponse._parse   s   "DMM g&&''G (11&w2GG$/??6""$sF+\::2G<%)%7%7%B%Bb%B%Q"27A">&*&8&8  $sF+->??7A%)%7%7%C%Cr%C%R"27A">&*&8&8  <<<+B//#&UV\U]]abman$opp 9 -D! "&!3!3#C6 $  $$ 9$:J:J K!%!3!3#C6 $	 %   QSWS_S_SsSstJ!-//#!//T\\2 MM	  h4= %%c>8==))c>3x}}-..e5/00d?8==..0F:;;??6""z&:T'U'U78,--&&LMM??
 
00 %..( #]__8$$ OO  vy1168#5#566wxx 6!dNdNeOvy11-gY6KI;VXY]X^^`ae`ffhinhooqrzq{{}  B  ~C  CG  HM  HV  HV  GW  WX  Y  $++//DJJ3O$$V,,G$$	#==?D  <<>>! '!) ?   ||770%klxky  zD  E!  == }}||22 3 
 	
/ ! gIIUW[\_W`beffgs   X+ +
Y5 YYc                j    SU R                    SU R                  R                   SU R                   S3$ )Nz<APIResponse [ z] type=>)rf   r:   reason_phraser0   rM   s    rF   __repr__LegacyAPIResponse.__repr__n  s;     0 0143E3E3S3S2TT[\`\i\i[jjkllrI   )r0   r2   r8   r3   r5   r7   r:   r<   )r@   r9   rA   r/   rB   r1   rC   r4   rD   r6   rE   r$   r<   r;   returnNoner   z
str | None)rR   ztype[_T]r   r(   )r   r'   )rR   ztype[_T] | Noner   zR | _T)r   zhttpx.Headers)r   zhttpx.Request)r   r;   )r   z	httpx.URLr   r   r   bytes)r   r4   )r   zdatetime.timedelta)__name__
__module____qualname____firstlineno____doc____annotations__rG   propertyrN   r   rS   rK   rc   rf   ri   rl   ro   rr   ru   rx   r{   rX   r   r   __static_attributes__rQ   rI   rF   r-   r-   /   s   
 !!))MBB!!!!M + + 	+
 %+ + F+ %+ + 
+( < < / / -1 -^ * * * * . . & & ( ( * * ' ' / / , , * * /3 e
N m mrI   r-   c                  ,   ^  \ rS rSrSU 4S jjrSrU =r$ )r   is  c                $   > [         TU ]  S5        g )Nz}The `stream` argument was set to `True` but the `stream_cls` argument was not given. See `anthropic._streaming` for reference)superrG   )r?   	__class__s    rF   rG    MissingStreamClassError.__init__t  s     L	
rI   rQ   r   r   )r   r   r   r   rG   r   __classcell__)r   s   @rF   r   r   s  s    
 
rI   r   c                J   ^  [         R                  " T 5      SU 4S jj5       nU$ )Higher order function that takes one of our bound API methods and wraps it
to support returning the raw `APIResponse` object directly.
c                    > 0 [        [        UR                  S5      5      =(       d    0 EnSU[        '   X!S'   [        [        [
           T" U 0 UD65      $ Nextra_headersr   r   r   rL   r   r-   r'   argskwargsr   funcs      rF   wrapped(to_raw_response_wrapper.<locals>.wrapped  sS    (ZDfjj6Q,R,XVX(Z-3)*"/%a($*?*?@@rI   r   zP.argsr   zP.kwargsr   zLegacyAPIResponse[R]	functoolswrapsr   r   s   ` rF   to_raw_response_wrapperr   z  s)    
 __TA A NrI   c                J   ^  [         R                  " T 5      SU 4S jj5       nU$ )r   c                    >#    0 [        [        UR                  S5      5      =(       d    0 EnSU[        '   X!S'   [        [        [
           T" U 0 UD6I S h  vN 5      $  N7fr   r   r   s      rF   r   .async_to_raw_response_wrapper.<locals>.wrapped  s\     (ZDfjj6Q,R,XVX(Z-3)*"/%a(d0Ef0E*EFF*Es   AA"A 
	A"r   r   r   s   ` rF   async_to_raw_response_wrapperr     s)    
 __TG G NrI   c                     \ rS rSr% S\S'   SS jr\SS j5       r\SS j5       r\S S j5       r	\S S j5       r
S!S	 jrSS
 jrS"S#S jjrS"S$S jjrS%S jrS"S#S jjr    S&S jr\" S5      SS.     S'S jj5       rS(S jrSS jrS"S)S jjrS"S*S jjrS+S jrS"S)S jjr\" S5      SS.     S'S jj5       rS(S jrSrg),r   i  r9   r   c                    Xl         g r>   r   )r?   r   s     rF   rG   #HttpxBinaryResponseContent.__init__  s     rI   c                .    U R                   R                  $ r>   )r   ro   rM   s    rF   ro   "HttpxBinaryResponseContent.content  s    }}$$$rI   c                .    U R                   R                  $ r>   )r   rr   rM   s    rF   rr   HttpxBinaryResponseContent.text  s    }}!!!rI   c                .    U R                   R                  $ r>   )r   encodingrM   s    rF   r   #HttpxBinaryResponseContent.encoding  s    }}%%%rI   c                .    U R                   R                  $ r>   )r   charset_encodingrM   s    rF   r   +HttpxBinaryResponseContent.charset_encoding  s    }}---rI   c                :    U R                   R                  " S0 UD6$ )NrQ   )r   r   )r?   r   s     rF   r   HttpxBinaryResponseContent.json  s    }}!!+F++rI   c                6    U R                   R                  5       $ r>   )r   readrM   s    rF   r   HttpxBinaryResponseContent.read  s    }}!!##rI   Nc                8    U R                   R                  U5      $ r>   )r   r   r?   r   s     rF   r   %HttpxBinaryResponseContent.iter_bytes  s    }}''
33rI   c                8    U R                   R                  U5      $ r>   )r   	iter_textr   s     rF   r   $HttpxBinaryResponseContent.iter_text  s    }}&&z22rI   c                6    U R                   R                  5       $ r>   )r   
iter_linesrM   s    rF   r   %HttpxBinaryResponseContent.iter_lines  s    }}''))rI   c                8    U R                   R                  U5      $ r>   )r   iter_rawr   s     rF   r   #HttpxBinaryResponseContent.iter_raw  s    }}%%j11rI   c                    [        USS9 nU R                  R                  5        H  nUR                  U5        M     SSS5        g! , (       d  f       g= f)aN  Write 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')`
wbmodeNopenr   r   write)r?   filefr   s       rF   write_to_file(HttpxBinaryResponseContent.write_to_file  s>     $T"a002 3 #""s   3A
AzDue to a bug, this method doesn't actually stream the response content, `.with_streaming_response.method()` should be used insteadr   c                   [        USS9 nU R                  R                  U5       H  nUR                  U5        M     S S S 5        g ! , (       d  f       g = fNr   r   r  )r?   r  r   r  r   s        rF   stream_to_file)HttpxBinaryResponseContent.stream_to_file  s@     $T"a00< = #""s   4A
Ac                6    U R                   R                  5       $ r>   )r   closerM   s    rF   r   HttpxBinaryResponseContent.close  s    }}""$$rI   c                R   #    U R                   R                  5       I S h  vN $  N7fr>   )r   areadrM   s    rF   r   HttpxBinaryResponseContent.aread  s     ]]((****   '%'c                @   #    U R                   R                  U5      $ 7fr>   )r   r   r   s     rF   r   &HttpxBinaryResponseContent.aiter_bytes  s     }}((44   c                @   #    U R                   R                  U5      $ 7fr>   )r   
aiter_textr   s     rF   r  %HttpxBinaryResponseContent.aiter_text  s     }}''
33r  c                >   #    U R                   R                  5       $ 7fr>   )r   aiter_linesrM   s    rF   r  &HttpxBinaryResponseContent.aiter_lines  s     }}((**s   c                @   #    U R                   R                  U5      $ 7fr>   )r   	aiter_rawr   s     rF   r  $HttpxBinaryResponseContent.aiter_raw  s     }}&&z22r  c               ^  #    [         R                  " U5      nUR                  SS9I S h  vN  IS h  vN nU R                  R	                  U5        S h  vN nUR                  U5      I S h  vN   M$   NL NE N# N
 S S S 5      IS h  vN    g ! , IS h  vN  (       d  f       g = f7fr
  )anyioPathr  r   r   r  )r?   r  r   pathr  r   s         rF   astream_to_file*HttpxBinaryResponseContent.astream_to_file  s      zz$----"mm77
C $dggdm## .$# D .-----s   )B-A8B-A:B-BB A<B B1A>2B8B-:B-<B >B BB-BB-B*BB*&B-c                R   #    U R                   R                  5       I S h  vN $  N7fr>   )r   acloserM   s    rF   r'  !HttpxBinaryResponseContent.aclose  s     ]]))++++r  r   )r   r9   r   r   r   r   r   )r   r   r   r   r>   )r   
int | Noner   zIterator[bytes])r   r)  r   Iterator[str])r   r*  )r  str | os.PathLike[str]r   r   )r  r+  r   r)  r   r   r   )r   r)  r   zAsyncIterator[bytes])r   r)  r   AsyncIterator[str])r   r,  )r   r   r   r   r   rG   r   ro   rr   r   r   r   r   r   r   r   r   r  r   r  r  r  r   r  r  r  r$  r'  r   rQ   rI   rF   r   r     s5   ! % % " " & & . .,$43*2$ 
   	M "&	$ 	
 
%+54+3  	M "&		$$	$ 		$
 
	$	$,rI   r   )r   zCallable[P, R]r   z!Callable[P, LegacyAPIResponse[R]])r   zCallable[P, Awaitable[R]]r   z,Callable[P, Awaitable[LegacyAPIResponse[R]]])C
__future__r   osr   loggingdatetimer   typingr   r   r   r   r   r	   r
   r   r   r   typing_extensionsr   r   r   r   r   r!  r   r   _typesr   _utilsr   r   r   r   _modelsr   r   r   
_constantsr   
_streamingr   r   r   r    _exceptionsr!   _decoders.jsonlr"   r#   r$   _base_clientr%   r&   r'   r(   r)   	getLoggerr   r+   r   r-   r   r   r   r   r   rQ   rI   rF   <module>r<     s    " 	       U T     U U < < + \ \ 3 <,( cNCLT]4(''1^ 1Am
 AmH

i 
""f, f,rI   