
    hGs                    t   % 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  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  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"J#r#  SS	K$J%r%J&r&J'r'  SS
K(J)r)J*r*  SSK+J,r,J-r-J.r.J/r/  SSK0J1r1J2r2  \
(       a  SSK$J3r3  SSK4J5r5  \" S5      r6\" S5      r7\" S5      r8\" SSS9r9\" SSS9r:\Rv                  " \<5      r=S\>S'    " S S\\7   5      r? " S S\?\7   5      r@ " S S\?\7   5      rA " S S \@\B   5      rC " S! S"\A\B   5      rD " S# S$\@\B   5      rE " S% S&\A\B   5      rF " S' S(\G5      rH " S) S*\15      rI " S+ S,\\9   5      rJ " S- S.\\:   5      rKS8S/ jrL    S9S0 jrM      S:S1 jrN      S;S2 jrOS<S3 jrPS=S4 jrQ      S>S5 jrR      S?S6 jrSS@S7 jrTg)A    )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)OpenAIErrorAPIResponseValidationError)FinalRequestOptions)
BaseClientPR_T_APIResponseTzAPIResponse[Any])bound_AsyncAPIResponseTzAsyncAPIResponse[Any]zlogging.Loggerlogc                  ^   \ 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 j5       r
\S'S j5       r\S'S j5       r\S(S j5       r\S)S j5       r\S'S j5       rSS.S*S  jjrS!rg)+BaseAPIResponse0   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               f    X l         X0l        0 U l        X@l        XPl        X`l        Xl        Xpl        g N)r2   r4   r5   r7   r9   r:   r<   r>   )selfrawcast_toclientstream
stream_clsoptionsr>   s           B/var/www/html/env/lib/python3.13/site-packages/openai/_response.py__init__BaseAPIResponse.__init__=   s3      !$% *    c                .    U R                   R                  $ r@   )r<   headersrA   s    rH   rM   BaseAPIResponse.headersQ   s    !!)))rK   c                .    U R                   R                  $ )zHReturns the httpx Request instance associated with the current response.)r<   requestrN   s    rH   http_requestBaseAPIResponse.http_requestU        !!)))rK   c                .    U R                   R                  $ r@   )r<   status_coderN   s    rH   rV   BaseAPIResponse.status_codeZ   s    !!---rK   c                .    U R                   R                  $ )z/Returns the URL for which the request was made.)r<   urlrN   s    rH   rY   BaseAPIResponse.url^   s     !!%%%rK   c                .    U R                   R                  $ r@   )rR   methodrN   s    rH   r\   BaseAPIResponse.methodc   s      '''rK   c                .    U R                   R                  $ r@   )r<   http_versionrN   s    rH   r_   BaseAPIResponse.http_versiong   s    !!...rK   c                .    U R                   R                  $ )zCThe time taken for the complete request/response cycle to complete.)r<   elapsedrN   s    rH   rb   BaseAPIResponse.elapsedk   rT   rK   c                .    U R                   R                  $ )zWhether 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    rH   re   BaseAPIResponse.is_closedp   s     !!+++rK   c           	         SU R                   R                   SU R                   SU R                  R                   SU R
                   S3	$ )N<z [ z] type=>)	__class____name__rV   r<   reason_phraser2   rN   s    rH   __repr__BaseAPIResponse.__repr__z   sP     ''(4+;+;*<Ad>P>P>^>^=__fgkgtgtfuuvw	
rK   Ntoc               
   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U R                  (       Ga:  U(       ai  [        U5      (       d  [        S[         S[         35      e[        [        U" [        USS9U R                  [        [        U R                   5      S95      $ U R"                  (       aT  [        [$        U R#                  [        U R"                  5      U R                  [        [        U R                   5      S95      $ [        SU R                   R&                  5      nUc
  [)        5       e[        [$        U" UU R                  [        [        U R                   5      S95      $ U[*        L a  [        [$        S 5      $ U R                  nU[,        :X  a  [        [$        UR.                  5      $ U[0        :X  a  [        [$        UR2                  5      $ U[4        :X  a#  [        [$        [5        UR.                  5      5      $ U[6        :X  a#  [        [$        [7        UR.                  5      5      $ U[8        :X  a+  [        [$        UR.                  R;                  5       S:H  5      $ [<        R>                  " U5      (       a&  UR@                  S	:X  a  [        [$        U" U5      5      $ U[B        :X  a  [E        S
5      e[<        R>                  " U5      (       aN  [G        U[H        RJ                  5      (       a/  U[H        RJ                  :w  a  [M        S5      e[        [$        U5      $ [<        R>                  " U5      (       a?  [G        U[N        5      (       d*  [G        U[P        RN                  5      (       a  [        S5      eU[R        Laz  U[T        Laq  U[V        Lah  U[X        La_  [G        U[N        5      (       dJ  [E        SU S[N         S[V         S[T         S[X         S[*         S[,         S[H        RJ                   S35      eURZ                  R]                  SS5      R_                  S5      tpgUS:w  a|  [a        U5      (       a,   URc                  5       nU R                   Re                  UUUS9$ U R                   Rn                  (       a  [q        USU S3UR.                  S9eUR.                  $ URc                  5       nU R                   Re                  UUUS9$ ! [f         a*  n	[h        Rk                  S[m        U	5      U	5         S n	A	NS n	A	ff = f)Nr   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)rC   responserD   r8   trueHttpxBinaryResponseContentz+Unexpected state - cast_to is `APIResponse`z:Subclasses of httpx.Response cannot be passed to `cast_to`zVPydantic models must subclass our base model type, e.g. `from openai import BaseModel`zUnsupported type, expected z to be a subclass of z, .zcontent-type*;zapplication/json)datarC   rt   z5Could not read JSON from response data due to %s - %szMExpected Content-Type response header to be `application/json` but received `z
` instead.)rt   messagebody)9r2   r   	__value__r   r   r   r7   r!   	TypeErrorr   r    r   r)   r"   r<   r   r4   r9   r(   _default_stream_clsMissingStreamClassErrorr   strtextbytescontentr=   floatr6   lowerinspectisclassrl   APIResponseRuntimeError
issubclasshttpxResponse
ValueErrorr   pydanticobjectlistdictr   rM   getsplitr   json_process_response_data	Exceptionr-   debugtype_strict_response_validationr$   )
rA   rq   rC   originrF   rt   content_type_rz   excs
             rH   _parseBaseAPIResponse._parse   s   "DMM g&&''G (11&w2GG$/+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'I %..( #]__8$$ OO  vy1168#5#566tuu 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--G$$	#==?D  <<>>! '!) ?   ||770%klxky  zD  E!  == }}||22 3 
 	
/ ! gIIUW[\_W`beffgs   T" "
U, UU)r2   r4   r7   r:   r5   r9   r<   r>   )rB   r;   rC   r1   rD   r3   rE   r6   rF   r8   rG   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   r6   rq   ztype[_T] | Noner   zR | _T)rl   
__module____qualname____firstlineno____annotations__rI   propertyrM   rR   rV   rY   r\   r_   rb   re   r   rn   r   __static_attributes__ rK   rH   r/   r/   0   sU   !!))BB!!!!M + + 	+
 %+ + F+ %+ + 
+( * * * * . . & & ( ( / / * * , , 
 

 /3 O
 O
rK   r/   c                      \ rS rS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rSS	 j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rg)r   i  c                L    U R                   R                  R                  S5      $ Nzx-request-idr<   rM   r   rN   s    rH   
request_idAPIResponse.request_id      !!))--n==rK   c                   g r@   r   rA   rq   s     rH   parseAPIResponse.parse  s    ,/rK   c                    g r@   r   rN   s    rH   r   r     s    rK   Nrp   c                  Ub  UOU R                   nU R                  R                  U5      nUb  U$ U R                  (       d  U R	                  5         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      $ )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 openai 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`
rp   r2   r5   r   r7   readr   r   r:   post_parser
isinstancer   r   r   r   r(   rA   rq   	cache_keycachedparseds        rH   r   r     s    < .Bdmm	%%)))4M""IIK#DMM--..]]..v6Ffi((6??3*0Y'AvrK   c                     U R                   R                  5       $ ! [        R                   a  n[	        5       UeSnAff = fz,Read and return the binary response content.N)r<   r   r   StreamConsumedStreamAlreadyConsumedrA   r   s     rH   r   APIResponse.readM  s?    	3%%**,,## 	3 ()s2		3s    A ;A c                N    U R                  5         U R                  R                  $ )3Read and decode the response content into a string.r   r<   r   rN   s    rH   r   APIResponse.textW  s    		!!&&&rK   c                V    U R                  5         U R                  R                  5       $ )*Read and decode the JSON response content.r   r<   r   rN   s    rH   r   APIResponse.json\  s     		!!&&((rK   c                8    U R                   R                  5         gzqClose the response and release the connection.

Automatically called if the response body is read to completion.
N)r<   closerN   s    rH   r   APIResponse.closea  s    
 	  "rK   c              #  X   #    U R                   R                  U5       H  nUv   M	     g7fz|
A byte-iterator over the decoded response content.

This automatically handles gzip, deflate and brotli encoded responses.
N)r<   
iter_bytesrA   
chunk_sizechunks      rH   r   APIResponse.iter_bytesh  s'      ''22:>EK ?   (*c              #  X   #    U R                   R                  U5       H  nUv   M	     g7f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      rH   r   APIResponse.iter_textq  s'     
 ''11*=EK >r   c              #  V   #    U R                   R                  5        H  nUv   M	     g7fz;Like `iter_text()` but will only yield chunks for each lineN)r<   
iter_linesrA   r   s     rH   r   APIResponse.iter_linesy  s#     ''224EK 5s   ')r   r   z
str | Nonerq   ztype[_T]r   r)   r   r(   r   r   r   r   r   r   r   r   r@   )r   
int | Noner   zIterator[bytes])r   r   r   Iterator[str])r   r   rl   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rK   rH   r   r     s^    > > / / -1 .`3'
)
#rK   r   c                      \ rS rS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rSS	 j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rg)AsyncAPIResponsei  c                L    U R                   R                  R                  S5      $ r   r   rN   s    rH   r   AsyncAPIResponse.request_id  r   rK   c                  #    g 7fr@   r   r   s     rH   r   AsyncAPIResponse.parse  s     25   c                   #    g 7fr@   r   rN   s    rH   r   r     s      #r   Nrp   c                 #    Ub  UOU R                   nU R                  R                  U5      nUb  U$ U R                  (       d  U R	                  5       I Sh  vN   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      $  N7f)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 openai 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`
Nrp   r   r   s        rH   r   r     s     8 .Bdmm	%%)))4M""))+#DMM--..]]..v6Ffi((6??3*0Y'Av s   AC5C3BC5c                   #     U R                   R                  5       I Sh  vN $  N! [        R                   a  n[	        5       UeSnAff = f7fr   )r<   areadr   r   r   r   s     rH   r   AsyncAPIResponse.read  sG     	3++113333## 	3 ()s2		3s0   A( &( A( AAAAc                j   #    U R                  5       I Sh  vN   U R                  R                  $  N7f)r   Nr   rN   s    rH   r   AsyncAPIResponse.text  s+     iik!!&&& 	s   313c                r   #    U R                  5       I Sh  vN   U R                  R                  5       $  N7f)r   Nr   rN   s    rH   r   AsyncAPIResponse.json  s.     iik!!&&(( 	s   757c                T   #    U R                   R                  5       I Sh  vN   g N7fr   )r<   acloserN   s    rH   r   AsyncAPIResponse.close  s     
   '')))s   (&(c               h   #    U R                   R                  U5        Sh  vN nU7v   M   N
 g7fr   )r<   aiter_bytesr   s      rH   r   AsyncAPIResponse.iter_bytes  s/       --99*E 	%K	E   20.0202c               h   #    U R                   R                  U5        Sh  vN nU7v   M   N
 g7fr   )r<   
aiter_textr   s      rH   r   AsyncAPIResponse.iter_text  s/     
  --88D 	%K	Dr  c               f   #    U R                   R                  5         Sh  vN nU7v   M   N
 g7fr   )r<   aiter_linesr   s     rH   r   AsyncAPIResponse.iter_lines  s+     --99; 	%K	;s   1/-/1/1r   r   r   r   r   r   r   r   r   r@   )r   r   r   zAsyncIterator[bytes])r   r   r   AsyncIterator[str])r   r
  r   r   rK   rH   r   r     s^    > > 5 5# #37 ,\3'
)
*rK   r   c                  *    \ rS rSrSr    SS jrSrg)BinaryAPIResponsei  #  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                    [        USS9 nU R                  5        H  nUR                  U5        M     SSS5        g! , (       d  f       g= fa6  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)rA   filefrz   s       rH   write_to_fileBinaryAPIResponse.write_to_file  s8     $T"a) * #""s	   )=
Ar   Nr  str | os.PathLike[str]r   r   rl   r   r   r   __doc__r  r   r   rK   rH   r  r    s    $ 
rK   r  c                  *    \ rS rSrSr    SS jrSrg)AsyncBinaryAPIResponsei  r  c                H  #    [         R                  " U5      nUR                  SS9I Sh  vN  ISh  vN nU R                  5         Sh  vN nUR	                  U5      I Sh  vN   M$   NA N: 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  )rA   r  pathr  rz   s        rH   r  $AsyncBinaryAPIResponse.write_to_file  sv      zz$----"oo/ $dggdm## .$# 0 .-----s   )B"A-B"A/B"B	A5A1A5B&A3'B-B"/B"1A53B5B6B"BB"BBBB"r   Nr  r  r   rK   rH   r  r    s    $$$ 
$rK   r  c                  0    \ rS rSrSS.     SS jjrSrg)StreamedBinaryAPIResponsei  Nr   c                   [        USS9 nU R                  U5       H  nUR                  U5        M     SSS5        g! , (       d  f       g= fzeStreams the output to the given file.

Accepts a filename or any path-like object, e.g. pathlib.Path
r  r  Nr  )rA   r  r   r  rz   s        rH   stream_to_file(StreamedBinaryAPIResponse.stream_to_file  s:     $T"a
3 4 #""s	   *>
Ar   r  r  r   r   r   r   rl   r   r   r   r+  r   r   rK   rH   r'  r'    s-    
 "&	$ 	
 
 rK   r'  c                  0    \ rS rSrSS.     SS jjrSrg)AsyncStreamedBinaryAPIResponsei-  Nr(  c               J  #    [         R                  " U5      nUR                  SS9I Sh  vN  ISh  vN nU R                  U5        Sh  vN nUR	                  U5      I Sh  vN   M$   NB N; N# N
 SSS5      ISh  vN    g! , ISh  vN  (       d  f       g= f7fr*  r!  )rA   r  r   r$  r  rz   s         rH   r+  -AsyncStreamedBinaryAPIResponse.stream_to_file.  sx      zz$----"ooj9 $dggdm## .$# : .-----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#r   r-  r.  r   rK   rH   r0  r0  -  s-    
 "&	$$$ 	$
 
$ $rK   r0  c                  ,   ^  \ rS rSrSU 4S jjrSrU =r$ )r   i>  c                $   > [         TU ]  S5        g )NzzThe `stream` argument was set to `True` but the `stream_cls` argument was not given. See `openai._streaming` for referencesuperrI   )rA   rk   s    rH   rI    MissingStreamClassError.__init__?  s     I	
rK   r   r   )rl   r   r   r   rI   r   __classcell__rk   s   @rH   r   r   >  s    
 
rK   r   c                  0   ^  \ rS rSrSrSU 4S jjrSrU =r$ )r   iE  a  
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                (   > Sn[         TU ]  U5        g )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.r5  )rA   r{   rk   s     rH   rI   StreamAlreadyConsumed.__init__Z  s    A 	 	!rK   r   r   )rl   r   r   r   r  rI   r   r8  r9  s   @rH   r   r   E  s    (
" 
"rK   r   c                  F    \ rS rSrSrSS jrS	S jr        S
S jrSrg)ResponseContextManagerig  Context 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                    Xl         S U l        g r@   _request_func!_ResponseContextManager__response)rA   request_funcs     rH   rI   ResponseContextManager.__init__m  s    )04rK   c                D    U R                  5       U l        U R                  $ r@   rA  rN   s    rH   	__enter__ ResponseContextManager.__enter__q  s    ,,.rK   c                T    U R                   b  U R                   R                  5         g g r@   )rC  r   rA   exc_typer   exc_tbs       rH   __exit__ResponseContextManager.__exit__u  s#     ??&OO!!# 'rK   )
__responserB  N)rD  zCallable[[], _APIResponseT]r   r   )r   r*   rK  ztype[BaseException] | Noner   zBaseException | NonerL  zTracebackType | Noner   r   )	rl   r   r   r   r  rI   rG  rM  r   r   rK   rH   r>  r>  g  s<    
5$,$ "$ %	$
 
$rK   r>  c                  F    \ rS rSrSrSS jrS	S jr        S
S jrSrg)AsyncResponseContextManageri  r?  c                    Xl         S U l        g r@   _api_request&_AsyncResponseContextManager__response)rA   api_requests     rH   rI   $AsyncResponseContextManager.__init__  s    '59rK   c                X   #    U R                   I S h  vN U l        U R                  $  N7fr@   rT  rN   s    rH   
__aenter__&AsyncResponseContextManager.__aenter__  s$      $ 1 11 2s   *(*c                p   #    U R                   b#  U R                   R                  5       I S h  vN   g g  N7fr@   )rV  r   rJ  s       rH   	__aexit__%AsyncResponseContextManager.__aexit__  s/      ??&//''))) ')s   +646)rO  rU  N)rW  Awaitable[_AsyncAPIResponseT]r   r   )r   r,   rP  )	rl   r   r   r   r  rI   rZ  r]  r   r   rK   rH   rR  rR    s<    
:*,* "* %	*
 
*rK   rR  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 streaming and returning the raw `APIResponse` object directly.
c                    > 0 [        [        UR                  S5      5      =(       d    0 EnSU[        '   X!S'   [        R
                  " T/U Q70 UD6n[        [        [        / [        [           4   U5      5      $ Nextra_headersrE   )
r   r   r   r   	functoolspartialr>  r
   r   r(   argskwargsrd  make_requestfuncs       rH   wrapped-to_streamed_response_wrapper.<locals>.wrapped  sp    (ZDfjj6Q,R,XVX(Z-5)*"/ ((???%d8BA4F+G&VWWrK   )rh  P.argsri  P.kwargsr   z&ResponseContextManager[APIResponse[R]]re  wrapsrk  rl  s   ` rH   to_streamed_response_wrapperrs    s)    
 __TX X NrK   c                J   ^  [         R                  " T 5      SU 4S jj5       nU$ )ra  c                    > 0 [        [        UR                  S5      5      =(       d    0 EnSU[        '   X!S'   T" U 0 UD6n[	        [        [
        [        [              U5      5      $ rc  )r   r   r   r   rR  r   r   r(   rg  s       rH   rl  3async_to_streamed_response_wrapper.<locals>.wrapped  sc    (ZDfjj6Q,R,XVX(Z-5)*"/T,V,*4	:J1:M0NP\+]^^rK   )rh  rn  ri  ro  r   z0AsyncResponseContextManager[AsyncAPIResponse[R]]rp  rr  s   ` rH   "async_to_streamed_response_wrapperrw    s)     __T_ _ NrK   c                N   ^ ^ [         R                  " T 5      SU U4S jj5       nU$ )  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                    > 0 [        [        UR                  S5      5      =(       d    0 EnSU[        '   TU[        '   X!S'   [
        R                  " T/U Q70 UD6n[        [        [        / [        4   U5      5      $ rc  )
r   r   r   r   r   re  rf  r>  r
   r*   rh  ri  rd  rj  rk  response_clss       rH   rl  4to_custom_streamed_response_wrapper.<locals>.wrapped  sw    (ZDfjj6Q,R,XVX(Z-5)*1=-."/ ((???%d8B4E+F&UVVrK   )rh  rn  ri  ro  r   z%ResponseContextManager[_APIResponseT]rp  rk  r|  rl  s   `` rH   #to_custom_streamed_response_wrapperr    s)     __T	W 	W NrK   c                N   ^ ^ [         R                  " T 5      SU U4S jj5       nU$ )ry  c                    > 0 [        [        UR                  S5      5      =(       d    0 EnSU[        '   TU[        '   X!S'   T" U 0 UD6n[        [        [        [           U5      5      $ rc  )r   r   r   r   r   rR  r   r,   r{  s       rH   rl  :async_to_custom_streamed_response_wrapper.<locals>.wrapped  sh    (ZDfjj6Q,R,XVX(Z-5)*1=-."/T,V,*4	:L0M|+\]]rK   )rh  rn  ri  ro  r   z/AsyncResponseContextManager[_AsyncAPIResponseT]rp  r~  s   `` rH   )async_to_custom_streamed_response_wrapperr    s)     __T	^ 	^ NrK   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      $ Nrd  rB   )r   r   r   r   r   r(   rh  ri  rd  rk  s      rH   rl  (to_raw_response_wrapper.<locals>.wrapped  sQ    (ZDfjj6Q,R,XVX(Z-2)*"/KND$$9&$9::rK   )rh  rn  ri  ro  r   zAPIResponse[R]rp  rr  s   ` rH   to_raw_response_wrapperr    s'    
 __T; ; NrK   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   r   r   r   r(   r  s      rH   rl  .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")rh  rn  ri  ro  r   zAsyncAPIResponse[R]rp  rr  s   ` rH   async_to_raw_response_wrapperr    s)    
 __TF F NrK   c                N   ^ ^ [         R                  " T 5      SU U4S jj5       nU$ )  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                    > 0 [        [        UR                  S5      5      =(       d    0 EnSU[        '   TU[        '   X!S'   [        [
        T" U 0 UD65      $ r  )r   r   r   r   r   r*   rh  ri  rd  rk  r|  s      rH   rl  /to_custom_raw_response_wrapper.<locals>.wrapped  sX    (ZDfjj6Q,R,XVX(Z-2)*1=-."/M4#8#899rK   )rh  rn  ri  ro  r   r*   rp  r~  s   `` rH   to_custom_raw_response_wrapperr    s'     __T: : NrK   c                N   ^ ^ [         R                  " T 5      SU U4S jj5       nU$ )r  c                    > 0 [        [        UR                  S5      5      =(       d    0 EnSU[        '   TU[        '   X!S'   [        [
        [           T" U 0 UD65      $ r  )r   r   r   r   r   r   r,   r  s      rH   rl  5async_to_custom_raw_response_wrapper.<locals>.wrapped4  s^    (ZDfjj6Q,R,XVX(Z-2)*1=-."/I0143H3HIIrK   )rh  rn  ri  ro  r   r_  rp  r~  s   `` rH   $async_to_custom_raw_response_wrapperr  *  s)     __TJ J NrK   c           	     J    [        U [        S[        [        [        45      SS9$ )zGiven 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   r/   r   r   )typs    rH   extract_response_typer  A  s*     &-N^/_` rK   )rk  Callable[P, R]r   z3Callable[P, ResponseContextManager[APIResponse[R]]])rk  Callable[P, Awaitable[R]]r   z=Callable[P, AsyncResponseContextManager[AsyncAPIResponse[R]]])rk  Callable[P, object]r|  type[_APIResponseT]r   z2Callable[P, ResponseContextManager[_APIResponseT]])rk  Callable[P, Awaitable[object]]r|  type[_AsyncAPIResponseT]r   z<Callable[P, AsyncResponseContextManager[_AsyncAPIResponseT]])rk  r  r   zCallable[P, APIResponse[R]])rk  r  r   z+Callable[P, Awaitable[AsyncAPIResponse[R]]])rk  r  r|  r  r   zCallable[P, _APIResponseT])rk  r  r|  r  r   z*Callable[P, Awaitable[_AsyncAPIResponseT]])r  ztype[BaseAPIResponse[Any]]r   r   )U
__future__r   osr   loggingdatetimere  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$   r%   _base_clientr&   r'   r(   r)   r*   r,   	getLoggerrl   r-   r   r/   r   r   r   r  r  r'  r0  r~   r   r   r>  rR  rs  rw  r  r  r  r  r  r  r  r   rK   rH   <module>r     s   " 	        I H     q q < < D \ \ @,( cNCLT]/AB19PQ ''1^ 1_
gaj _
Dj/!$ jZhq) hVE* 2$-e4 $4E 2  $%5e%< $"
i 
"K "D$W]3 $0*'*<"= *0&
#B*
% 82
(* B2""
%  .
(* 0.rK   