
    gv                    t   U d dl mZ d dlZd dlZd dlZd dlZd dlZd dlmZ d dl	m
Z
mZmZ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 d dlZd dlZd dlZddlmZ ddlmZm Z m!Z!m"Z"m#Z# dd	l$m%Z%m&Z&m'Z' dd
l(m)Z)m*Z* ddl+m,Z,m-Z-m.Z.m/Z/ ddl0m1Z1m2Z2 ddl3m4Z4m5Z5 e
rddl$m6Z6 ddl7m8Z8  ed      Z9 ed      Z: ed      Z; edd      Z< edd      Z= ej|                  e?      Z@deAd<    G d dee:         ZB G d deBe:         ZC G d deBe:         ZD G d  d!eCeE         ZF G d" d#eDeE         ZG G d$ d%eCeE         ZH G d& d'eDeE         ZI G d( d)eJ      ZK G d* d+e1      ZL G d, d-ee<         ZM G d. d/ee=         ZNd9d0ZO	 	 	 	 d:d1ZP	 	 	 	 	 	 d;d2ZQ	 	 	 	 	 	 d<d3ZRd=d4ZSd>d5ZT	 	 	 	 	 	 d?d6ZU	 	 	 	 	 	 d@d7ZVdAd8ZWy)B    )annotationsN)TracebackType)
TYPE_CHECKINGAnyUnionGenericTypeVarCallableIteratorAsyncIteratorcastoverload)	Awaitable	ParamSpecoverride
get_origin   )NoneType)is_givenextract_type_argis_annotated_typeis_type_alias_typeextract_type_var_from_base)	BaseModelis_basemodeladd_request_id)RAW_RESPONSE_HEADEROVERRIDE_CAST_TO_HEADER)StreamAsyncStreamis_stream_class_typeextract_stream_chunk_type)AnthropicErrorAPIResponseValidationError)JSONLDecoderAsyncJSONLDecoder)FinalRequestOptions)
BaseClientPR_T_APIResponseTzAPIResponse[Any])bound_AsyncAPIResponseTzAsyncAPIResponse[Any]zlogging.Loggerlogc                  <   e Zd ZU ded<   ded<   ded<   ded<   d	ed
<   ded<   ded<   ded<   	 dd	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d dZed!d       Zed"d       Zed#d       Zed$d       Z	ed%d       Z
ed%d       Zed&d       Zed'd       Zed%d       Zddd(dZy))BaseAPIResponsetype[R]_cast_toBaseClient[Any, Any]_clientzdict[type[Any], Any]_parsed_by_typebool_is_sse_stream1type[Stream[Any]] | type[AsyncStream[Any]] | None_stream_clsr'   _optionshttpx.Responsehttp_responseintretries_takenr   )r?   c               t    || _         || _        i | _        || _        || _        || _        || _        || _        y N)r3   r5   r6   r8   r:   r;   r=   r?   )selfrawcast_toclientstream
stream_clsoptionsr?   s           H/var/www/openai/venv/lib/python3.12/site-packages/anthropic/_response.py__init__zBaseAPIResponse.__init__>   sA      !$% *    c                .    | j                   j                  S rA   )r=   headersrB   s    rI   rM   zBaseAPIResponse.headersR   s    !!)))rK   c                .    | j                   j                  S )zHReturns the httpx Request instance associated with the current response.)r=   requestrN   s    rI   http_requestzBaseAPIResponse.http_requestV        !!)))rK   c                .    | j                   j                  S rA   )r=   status_coderN   s    rI   rT   zBaseAPIResponse.status_code[   s    !!---rK   c                .    | j                   j                  S )z/Returns the URL for which the request was made.)r=   urlrN   s    rI   rV   zBaseAPIResponse.url_   s     !!%%%rK   c                .    | j                   j                  S rA   )rQ   methodrN   s    rI   rX   zBaseAPIResponse.methodd   s      '''rK   c                .    | j                   j                  S rA   )r=   http_versionrN   s    rI   rZ   zBaseAPIResponse.http_versionh   s    !!...rK   c                .    | j                   j                  S )zCThe time taken for the complete request/response cycle to complete.)r=   elapsedrN   s    rI   r\   zBaseAPIResponse.elapsedl   rR   rK   c                .    | j                   j                  S )a  Whether or not the response body has been closed.

        If this is False then there is response data that has not been read yet.
        You must either fully consume the response body or call `.close()`
        before discarding the response to prevent resource leaks.
        )r=   	is_closedrN   s    rI   r^   zBaseAPIResponse.is_closedq   s     !!+++rK   c           	         d| j                   j                   d| j                   d| j                  j                   d| j
                   d	S )N<z [ z] type=>)	__class____name__rT   r=   reason_phraser3   rN   s    rI   __repr__zBaseAPIResponse.__repr__{   sP     ''(4+;+;*<Ad>P>P>^>^=__fgkgtgtfuuvw	
rK   Ntoc                  ||n| j                   }t        |      r|j                  }|rt        |      rt	        |d      }t        |      xs |}t        j                  |      rt        |t              rQt        t         t        d|      | j                  j                  d      t	        |d      | j                              S t        |t              rQt        t         t        d|      | j                  j                  d      t	        |d      | j                              S | j                   r6|rjt#        |      st%        dt&         dt(               t        t*         |t-        |d	
      | j                  t        t.        | j0                                    S | j2                  rWt        t        | j3                  t-        | j2                        | j                  t        t.        | j0                                    S t        d| j0                  j4                        }|
t7               t        t         ||| j                  t        t.        | j0                                    S |t8        u rt        t        d       S | j                  }|t:        k(  rt        t        |j<                        S |t>        k(  rt        t        |j@                        S |tB        k(  r#t        t        tC        |j<                              S |tD        k(  r#t        t        tE        |j<                              S |tF        k(  r+t        t        |j<                  jI                         dk(        S t        j                  |      r%|jJ                  dk(  rt        t         ||            S |tL        k(  rtO        d      t        j                  |      rHt        |tP        jR                        r.|tP        jR                  k7  rtU        d      t        t        |      S t        j                  |      r5t        |tV              s%t        |tX        jV                        rt%        d      |tZ        urr|t\        urj|t^        urb|t`        urZt        |tV              sJtO        d| dtV         dt^         dt\         dt`         dt8         dt:         dtP        jR                   d      |jb                  je                  dd      jg                  d      ^}}|dk7  rxti        |      r/	 |jk                         }| j0                  jm                  |||      S | j0                  jv                  rty        |d| d|j<                        |j<                  S |jk                         }| j0                  jm                  |||      S # tn        $ r*}	tp        js                  dtu        |	      |	       Y d }	~	d }	~	ww xY w)Nr   ztype[JSONLDecoder[Any]]i   
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)rD   responserE   r9   trueHttpxBinaryResponseContentz+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*;zapplication/json)datarD   ro   z5Could not read JSON from response data due to %s - %szMExpected Content-Type response header to be `application/json` but received `z
` instead.)ro   messagebody)=r3   r   	__value__r   r   r   inspectisclass
issubclassr%   r   r*   r=   
iter_bytesr&   aiter_bytesr8   r!   	TypeErrorr   r    r+   r"   r   r5   r:   _default_stream_clsMissingStreamClassErrorr   strtextbytescontentr>   floatr7   lowerrd   APIResponseRuntimeErrorhttpxResponse
ValueErrorr   pydanticobjectlistdictr   rM   getsplitr   json_process_response_data	Exceptionr/   debugtype_strict_response_validationr$   )
rB   rh   rD   originrG   ro   content_type_ru   excs
             rI   _parsezBaseAPIResponse._parse   s[   "DMM g&''G (1&w2GG$/??6"&<1<D2G<%)%7%7%B%Bd%B%S"27A">&*&8&8  &"34AD7A%)%7%7%C%Ct%C%T"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  h4= %%c>8==))e8++,,c>3x}}-..e5/00d?8==..0F:;; ??7#(8(8<X(X78,--[ LMM??6"z&%..'I %..( #]__8$$??6":fi+HZX^`h`r`rMswxx 6!dNdNeOvy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q--G$	#==?D  <<>>! '!) ?   ||770%klxky  zD  E!  == }}||22 3 
 	
/ ! gIIUW[\_W`beffgs   V' '	W0 WW)rC   r<   rD   r2   rE   r4   rF   r7   rG   r9   rH   r'   r?   r>   returnNone)r   zhttpx.Headers)r   zhttpx.Request)r   r>   )r   z	httpx.URLr   r   )r   zdatetime.timedelta)r   r7   rh   ztype[_T] | Noner   zR | _T)rd   
__module____qualname____annotations__rJ   propertyrM   rQ   rT   rV   rX   rZ   r\   r^   r   rf   r    rK   rI   r1   r1   1   sO   !!))BB!!!!M + + 	+
 %+ + F+ %+ + 
+( * * * * . . & & ( ( / / * * , , 
 

 /3 ^
rK   r1   c                      e Zd Zedd       Zedd       Zedd       ZddddZddZddZdd	Z	dd
Z
dddZdddZddZy)r   c                L    | j                   j                  j                  d      S Nz
request-idr=   rM   r   rN   s    rI   
request_idzAPIResponse.request_id#      !!))--l;;rK   c                    y rA   r   rB   rh   s     rI   parsezAPIResponse.parse'  s    ,/rK   c                     y rA   r   rN   s    rI   r   zAPIResponse.parse*  s    rK   Nrg   c                  ||n| j                   }| j                  j                  |      }||S | j                  s| j	                          | j                  |      }t        | j                  j                        r| j                  j                  |      }t        |t              rt        || j                         || j                  |<   t        t        |      S )a  Returns the rich python representation of this response's data.

        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`
        rg   r3   r6   r   r8   readr   r   r;   post_parser
isinstancer   r   r   r   r*   rB   rh   	cache_keycachedparseds        rI   r   zAPIResponse.parse-  s    < .Bdmm	%%)))4M""IIK#DMM--.]]..v6Ffi(64??3*0Y'AvrK   c                    	 | j                   j                         S # t        j                  $ r}t	               |d}~ww xY wz,Read and return the binary response content.N)r=   r   r   StreamConsumedStreamAlreadyConsumedrB   r   s     rI   r   zAPIResponse.read]  s?    	3%%**,,## 	3 ()s2		3s    ?:?c                N    | j                          | j                  j                  S )3Read and decode the response content into a string.r   r=   r   rN   s    rI   r   zAPIResponse.textg  s    		!!&&&rK   c                V    | j                          | j                  j                         S )*Read and decode the JSON response content.r   r=   r   rN   s    rI   r   zAPIResponse.jsonl  s     		!!&&((rK   c                8    | j                   j                          yzClose the response and release the connection.

        Automatically called if the response body is read to completion.
        N)r=   closerN   s    rI   r   zAPIResponse.closeq  s    
 	  "rK   c              #  T   K   | j                   j                  |      D ]  }|  ywz
        A byte-iterator over the decoded response content.

        This automatically handles gzip, deflate and brotli encoded responses.
        N)r=   r|   rB   rk   chunks      rI   r|   zAPIResponse.iter_bytesx  s(      ''22:>EK ?   &(c              #  T   K   | j                   j                  |      D ]  }|  ywzA str-iterator over the decoded response content
        that handles both gzip, deflate, etc but also detects the content's
        string encoding.
        N)r=   	iter_textr   s      rI   r   zAPIResponse.iter_text  s(     
 ''11*=EK >r   c              #  R   K   | j                   j                         D ]  }|  ywz;Like `iter_text()` but will only yield chunks for each lineN)r=   
iter_linesrB   r   s     rI   r   zAPIResponse.iter_lines  s$     ''224EK 5s   %'r   z
str | Nonerh   ztype[_T]r   r+   r   r*   r   r   r   r   r   r   r   r   rA   )rk   
int | Noner   zIterator[bytes])rk   r   r   Iterator[str])r   r   rd   r   r   r   r   r   r   r   r   r   r   r|   r   r   r   rK   rI   r   r   "  s^    < < / / -1 .`3'
)
#rK   r   c                      e Zd Zedd       Zedd       Zedd       ZddddZddZddZdd	Z	dd
Z
dddZdddZddZy)AsyncAPIResponsec                L    | j                   j                  j                  d      S r   r   rN   s    rI   r   zAsyncAPIResponse.request_id  r   rK   c                  K   y wrA   r   r   s     rI   r   zAsyncAPIResponse.parse  s	     25   c                   K   y wrA   r   rN   s    rI   r   zAsyncAPIResponse.parse  s	      #r   Nrg   c                 K   ||n| j                   }| j                  j                  |      }||S | j                  s| j	                          d{    | j                  |      }t        | j                  j                        r| j                  j                  |      }t        |t              rt        || j                         || j                  |<   t        t        |      S 7 w)a^  Returns the rich python representation of this response's data.

        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`
          - `httpx.Response`
        Nrg   r   r   s        rI   r   zAsyncAPIResponse.parse  s     8 .Bdmm	%%)))4M""))+#DMM--.]]..v6Ffi(64??3*0Y'Av s   AC)C'BC)c                   K   	 | j                   j                          d{   S 7 # t        j                  $ r}t	               |d}~ww xY wwr   )r=   areadr   r   r   r   s     rI   r   zAsyncAPIResponse.read  sH     	3++113333## 	3 ()s2		3s0   A( &( A( AAAAc                j   K   | j                          d{    | j                  j                  S 7 w)r   Nr   rN   s    rI   r   zAsyncAPIResponse.text  s,     iik!!&&& 	s   313c                r   K   | j                          d{    | j                  j                         S 7 w)r   Nr   rN   s    rI   r   zAsyncAPIResponse.json  s/     iik!!&&(( 	s   757c                T   K   | j                   j                          d{    y7 wr   )r=   acloserN   s    rI   r   zAsyncAPIResponse.close  s      
   '')))s   (&(c               f   K   | j                   j                  |      2 3 d{   }| 7 
6 ywr   )r=   r}   r   s      rI   r|   zAsyncAPIResponse.iter_bytes  s1       --99*E 	%K	E   1/-/1/1c               f   K   | j                   j                  |      2 3 d{   }| 7 
6 ywr   )r=   
aiter_textr   s      rI   r   zAsyncAPIResponse.iter_text  s1     
  --88D 	%K	Dr   c               d   K   | j                   j                         2 3 d{   }| 7 
6 ywr   )r=   aiter_linesr   s     rI   r   zAsyncAPIResponse.iter_lines  s-     --99; 	%K	;s   0.,.0.0r   r   r   r   r   r   r   r   rA   )rk   r   r   zAsyncIterator[bytes])rk   r   r   AsyncIterator[str])r   r   r   r   rK   rI   r   r     s^    < < 5 5# #37 ,\3'
)
*rK   r   c                       e Zd ZdZ	 	 	 	 ddZy)BinaryAPIResponse3  Subclass of APIResponse providing helpers for dealing with binary data.

    Note: If you want to stream the response data instead of eagerly reading it
    all at once then you should use `.with_streaming_response` when making
    the API request, e.g. `.with_streaming_response.get_binary_response()`
    c                    t        |d      5 }| j                         D ]  }|j                  |        	 ddd       y# 1 sw Y   yxY wa^  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. `.with_streaming_response.get_binary_response()`
        wbmodeNopenr|   write)rB   filefru   s       rI   write_to_filezBinaryAPIResponse.write_to_file  s8     $T"a) * #""s	   '?ANr   str | os.PathLike[str]r   r   rd   r   r   __doc__r   r   rK   rI   r   r     s    $ 
rK   r   c                       e Zd ZdZ	 	 	 	 ddZy)AsyncBinaryAPIResponser   c                @  K   t        j                  |      }|j                  d       d{   4 d{   }| j                         2 3 d{   }|j	                  |       d{    #7 @7 97 "7 6 ddd      d{  7   y# 1 d{  7  sw Y   yxY wwr   anyioPathr   r|   r   )rB   r   pathr   ru   s        rI   r   z$AsyncBinaryAPIResponse.write_to_file  s{      zz$----"oo/ $dggdm## .-$# 0 .----s   +BA.BA0BB	A6A2A6B	(A4)B	.B0B2A64B	6B	7BBB	BBBBNr   r   r   rK   rI   r  r    s    $$$ 
$rK   r  c                  $    e Zd Zdd	 	 	 	 	 ddZy)StreamedBinaryAPIResponseNrj   c                   t        |d      5 }| j                  |      D ]  }|j                  |        	 ddd       y# 1 sw Y   yxY wzuStreams the output to the given file.

        Accepts a filename or any path-like object, e.g. pathlib.Path
        r   r   Nr   )rB   r   rk   r   ru   s        rI   stream_to_filez(StreamedBinaryAPIResponse.stream_to_file.  s:     $T"a
3 4 #""s   (A  A	r   r   rk   r   r   r   rd   r   r   r  r   rK   rI   r
  r
  -  s(    
 "&	$ 	
 
rK   r
  c                  $    e Zd Zdd	 	 	 	 	 ddZy)AsyncStreamedBinaryAPIResponseNrj   c               B  K   t        j                  |      }|j                  d       d{   4 d{   }| j                  |      2 3 d{   }|j	                  |       d{    #7 A7 :7 "7 6 ddd      d{  7   y# 1 d{  7  sw Y   yxY wwr  r  )rB   r   rk   r  r   ru   s         rI   r  z-AsyncStreamedBinaryAPIResponse.stream_to_file>  s}      zz$----"ooj9 $dggdm## .-$# : .----s   +BA/BA1BB
A7A3A7B
)A5*B
/B1B3A75B
7B
8BBB
BBBBr  r  r   rK   rI   r  r  =  s(    
 "&	$$$ 	$
 
$rK   r  c                        e Zd Zd fdZ xZS )r   c                $    t         |   d       y )Nz}The `stream` argument was set to `True` but the `stream_cls` argument was not given. See `anthropic._streaming` for referencesuperrJ   )rB   rc   s    rI   rJ   z MissingStreamClassError.__init__O  s     L	
rK   r   )rd   r   r   rJ   __classcell__rc   s   @rI   r   r   N  s    
 
rK   r   c                  $     e Zd ZdZd fdZ xZS )r   aG  
    Attempted to read or stream content, but the content has already
    been streamed.

    This can happen if you use a method like `.iter_lines()` and then attempt
    to read th entire response body afterwards, e.g.

    ```py
    response = await client.post(...)
    async for line in response.iter_lines():
        ...  # do something with `line`

    content = await response.read()
    # ^ error
    ```

    If you want this behaviour you'll need to either manually accumulate the response
    content or call `await response.read()` before iterating over the stream.
    c                (    d}t         |   |       y )Na&  Attempted to read or stream some content, but the content has already been streamed. This could be due to attempting to stream the response content more than once.

You can fix this by manually accumulating the response content while streaming or by calling `.read()` before starting to stream.r  )rB   rv   rc   s     rI   rJ   zStreamAlreadyConsumed.__init__j  s    A 	 	!rK   r   )rd   r   r   r  rJ   r  r  s   @rI   r   r   U  s    (
" 
"rK   r   c                  8    e Zd ZdZddZddZ	 	 	 	 	 	 	 	 ddZy)	ResponseContextManagerContext manager for ensuring that a request is not made
    until it is entered and that the response will always be closed
    when the context manager exits
    c                     || _         d | _        y rA   _request_func!_ResponseContextManager__response)rB   request_funcs     rI   rJ   zResponseContextManager.__init__}  s    )04rK   c                D    | j                         | _        | j                  S rA   r  rN   s    rI   	__enter__z ResponseContextManager.__enter__  s    ,,.rK   c                R    | j                   | j                   j                          y y rA   )r!  r   rB   exc_typer   exc_tbs       rI   __exit__zResponseContextManager.__exit__  s#     ??&OO!!# 'rK   N)r"  zCallable[[], _APIResponseT]r   r   )r   r,   r'  ztype[BaseException] | Noner   zBaseException | Noner(  zTracebackType | Noner   r   )rd   r   r   r  rJ   r$  r)  r   rK   rI   r  r  w  s<    
5$,$ "$ %	$
 
$rK   r  c                  8    e Zd ZdZddZddZ	 	 	 	 	 	 	 	 ddZy)	AsyncResponseContextManagerr  c                     || _         d | _        y rA   _api_request&_AsyncResponseContextManager__response)rB   api_requests     rI   rJ   z$AsyncResponseContextManager.__init__  s    '59rK   c                X   K   | j                    d {   | _        | j                  S 7 wrA   r.  rN   s    rI   
__aenter__z&AsyncResponseContextManager.__aenter__  s%      $ 1 11 2s   *(*c                n   K   | j                   #| j                   j                          d {    y y 7 wrA   )r0  r   r&  s       rI   	__aexit__z%AsyncResponseContextManager.__aexit__  s0      ??&//''))) ')s   *535N)r1  Awaitable[_AsyncAPIResponseT]r   r   )r   r.   r*  )rd   r   r   r  rJ   r3  r5  r   rK   rI   r,  r,    s<    
:*,* "* %	*
 
*rK   r,  c                D     t        j                         d fd       }|S )Higher order function that takes one of our bound API methods and wraps it
    to support streaming and returning the raw `APIResponse` object directly.
    c                     i t        t        |j                  d            xs i }d|t        <   ||d<   t	        j
                  g| i |}t        t        t        g t        t           f   |            S Nextra_headersrF   )
r   r   r   r   	functoolspartialr  r
   r   r*   argskwargsr;  make_requestfuncs       rI   wrappedz-to_streamed_response_wrapper.<locals>.wrapped  sr    (ZDfjj6Q,R,XVX(Z-5)*"/ ((???%d8BA4F+G&VWWrK   )r?  P.argsr@  P.kwargsr   z&ResponseContextManager[APIResponse[R]]r<  wrapsrB  rC  s   ` rI   to_streamed_response_wrapperrI    s)    
 __TX X NrK   c                D     t        j                         d fd       }|S )r8  c                     i t        t        |j                  d            xs i }d|t        <   ||d<    | i |}t	        t        t
        t        t              |            S r:  )r   r   r   r   r,  r   r   r*   r>  s       rI   rC  z3async_to_streamed_response_wrapper.<locals>.wrapped  se    (ZDfjj6Q,R,XVX(Z-5)*"/T,V,*4	:J1:M0NP\+]^^rK   )r?  rD  r@  rE  r   z0AsyncResponseContextManager[AsyncAPIResponse[R]]rF  rH  s   ` rI   "async_to_streamed_response_wrapperrL    s)     __T_ _ NrK   c                H     t        j                         d fd       }|S )'  Higher order function that takes one of our bound API methods and an `APIResponse` class
    and wraps the method to support streaming and returning the given response class directly.

    Note: the given `response_cls` *must* be concrete, e.g. `class BinaryAPIResponse(APIResponse[bytes])`
    c                     i t        t        |j                  d            xs i }d|t        <   |t        <   ||d<   t        j                  g| i |}t        t        t        g t        f   |            S r:  )
r   r   r   r   r   r<  r=  r  r
   r,   r?  r@  r;  rA  rB  response_clss       rI   rC  z4to_custom_streamed_response_wrapper.<locals>.wrapped  sy    (ZDfjj6Q,R,XVX(Z-5)*1=-."/ ((???%d8B4E+F&UVVrK   )r?  rD  r@  rE  r   z%ResponseContextManager[_APIResponseT]rF  rB  rQ  rC  s   `` rI   #to_custom_streamed_response_wrapperrS    s)     __T	W 	W NrK   c                H     t        j                         d fd       }|S )rN  c                     i t        t        |j                  d            xs i }d|t        <   |t        <   ||d<    | i |}t        t        t        t           |            S r:  )r   r   r   r   r   r,  r   r.   rP  s       rI   rC  z:async_to_custom_streamed_response_wrapper.<locals>.wrapped  sj    (ZDfjj6Q,R,XVX(Z-5)*1=-."/T,V,*4	:L0M|+\]]rK   )r?  rD  r@  rE  r   z/AsyncResponseContextManager[_AsyncAPIResponseT]rF  rR  s   `` rI   )async_to_custom_streamed_response_wrapperrV    s)     __T	^ 	^ NrK   c                D     t        j                         d fd       }|S )Higher order function that takes one of our bound API methods and wraps it
    to support returning the raw `APIResponse` object directly.
    c                     i t        t        |j                  d            xs i }d|t        <   ||d<   t        t        t
            | i |      S Nr;  rC   )r   r   r   r   r   r*   r?  r@  r;  rB  s      rI   rC  z(to_raw_response_wrapper.<locals>.wrapped  sS    (ZDfjj6Q,R,XVX(Z-2)*"/KND$$9&$9::rK   )r?  rD  r@  rE  r   zAPIResponse[R]rF  rH  s   ` rI   to_raw_response_wrapperr\    s'    
 __T; ; NrK   c                D     t        j                         d fd       }|S )rX  c                    K   i t        t        |j                  d            xs i }d|t        <   ||d<   t        t        t
            | i | d {         S 7 wrZ  )r   r   r   r   r   r*   r[  s      rI   rC  z.async_to_raw_response_wrapper.<locals>.wrapped  s_     (ZDfjj6Q,R,XVX(Z-2)*"/$Q'tT/DV/D)DEE)Ds   AAA
	A)r?  rD  r@  rE  r   zAsyncAPIResponse[R]rF  rH  s   ` rI   async_to_raw_response_wrapperr_    s)    
 __TF F NrK   c                H     t        j                         d fd       }|S )  Higher order function that takes one of our bound API methods and an `APIResponse` class
    and wraps the method to support returning the given response class directly.

    Note: the given `response_cls` *must* be concrete, e.g. `class BinaryAPIResponse(APIResponse[bytes])`
    c                     i t        t        |j                  d            xs i }d|t        <   |t        <   ||d<   t        t
         | i |      S rZ  )r   r   r   r   r   r,   r?  r@  r;  rB  rQ  s      rI   rC  z/to_custom_raw_response_wrapper.<locals>.wrapped-  sZ    (ZDfjj6Q,R,XVX(Z-2)*1=-."/M4#8#899rK   )r?  rD  r@  rE  r   r,   rF  rR  s   `` rI   to_custom_raw_response_wrapperrd  #  s'     __T: : NrK   c                H     t        j                         d fd       }|S )ra  c                     i t        t        |j                  d            xs i }d|t        <   |t        <   ||d<   t        t
        t            | i |      S rZ  )r   r   r   r   r   r   r.   rc  s      rI   rC  z5async_to_custom_raw_response_wrapper.<locals>.wrappedD  s`    (ZDfjj6Q,R,XVX(Z-2)*1=-."/I0143H3HIIrK   )r?  rD  r@  rE  r   r6  rF  rR  s   `` rI   $async_to_custom_raw_response_wrapperrg  :  s)     __TJ J NrK   c           	     P    t        | t        dt        t        t        f      d      S )a  Given a type like `APIResponse[T]`, returns the generic type variable `T`.

    This also handles the case where a concrete subclass is given, e.g.
    ```py
    class MyResponse(APIResponse[bytes]):
        ...

    extract_response_type(MyResponse) -> bytes
    ```
    ztuple[type, ...]r   )generic_basesindex)r   r   r1   r   r   )typs    rI   extract_response_typerl  Q  s*     &-N^/_` rK   )rB  Callable[P, R]r   z3Callable[P, ResponseContextManager[APIResponse[R]]])rB  Callable[P, Awaitable[R]]r   z=Callable[P, AsyncResponseContextManager[AsyncAPIResponse[R]]])rB  Callable[P, object]rQ  type[_APIResponseT]r   z2Callable[P, ResponseContextManager[_APIResponseT]])rB  Callable[P, Awaitable[object]]rQ  type[_AsyncAPIResponseT]r   z<Callable[P, AsyncResponseContextManager[_AsyncAPIResponseT]])rB  rm  r   zCallable[P, APIResponse[R]])rB  rn  r   z+Callable[P, Awaitable[AsyncAPIResponse[R]]])rB  ro  rQ  rp  r   zCallable[P, _APIResponseT])rB  rq  rQ  rr  r   z*Callable[P, Awaitable[_AsyncAPIResponseT]])rk  ztype[BaseAPIResponse[Any]]r   r   )X
__future__r   osry   loggingdatetimer<  typesr   typingr   r   r   r   r	   r
   r   r   r   r   typing_extensionsr   r   r   r   r  r   r   _typesr   _utilsr   r   r   r   r   _modelsr   r   r   
_constantsr   r   
_streamingr   r    r!   r"   _exceptionsr#   r$   _decoders.jsonlr%   r&   r'   _base_clientr(   r)   r*   r+   r,   r.   	getLoggerrd   r/   r   r1   r   r   r   r   r  r
  r  r~   r   r   r  r,  rI  rL  rS  rV  r\  r_  rd  rg  rl  r   rK   rI   <module>r     s   " 	        I H     q q < < D \ \ C <,( cNCLT]/AB19PQ 'g''1^ 1n
gaj n
bj/!$ jZhq) hVE* 2$-e4 $4E 2  $%5e%< $"
i 
"N "D$W]3 $0*'*<"= *0&
#B*
% 82
(* B2""
%  .
(* 0.rK   