
    хiv>                       % 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   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-  \(       a  SSK!J.r.  SSK/J0r0  \" S5      r1\" S5      r2\" S5      r3\Rh                  " \55      r6S\7S'    " S S\\2   5      r8 " S S\95      r:SS jr;SS jr< " S S5      r=g)    )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)	BaseModelis_basemodeladd_request_id)RAW_RESPONSE_HEADER)StreamAsyncStreamis_stream_class_typeextract_stream_chunk_type)APIResponseValidationError)FinalRequestOptions)
BaseClientPR_Tz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   )r7   c               f    X l         X0l        0 U l        X@l        XPl        X`l        Xl        Xpl        g N)r+   r-   r.   r0   r2   r3   r5   r7   )selfrawcast_toclientstream
stream_clsoptionsr7   s           Q/home/james-whalen/.local/lib/python3.13/site-packages/openai/_legacy_response.py__init__LegacyAPIResponse.__init__F   s2      !% *    c                L    U R                   R                  R                  S5      $ )Nzx-request-id)r5   headersgetr:   s    rA   
request_idLegacyAPIResponse.request_idZ   s    !!))--n==rD   c                   g r9    )r:   tos     rA   parseLegacyAPIResponse.parse^   s    ,/rD   c                    g r9   rL   rH   s    rA   rN   rO   a   s    rD   NrM   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      $ )a6  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 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`
rQ   )r+   r.   rG   _parser   r3   post_parser
isinstancer   r   rI   r   r$   )r:   rM   	cache_keycachedparseds        rA   rN   rO   d   s    @ .Bdmm	%%)))4M#DMM--..]]..v6Ffi((6??3*0Y'AvrD   c                .    U R                   R                  $ r9   )r5   rF   rH   s    rA   rF   LegacyAPIResponse.headers       !!)))rD   c                .    U R                   R                  $ r9   )r5   requestrH   s    rA   http_requestLegacyAPIResponse.http_request   r[   rD   c                .    U R                   R                  $ r9   )r5   status_coderH   s    rA   ra   LegacyAPIResponse.status_code   s    !!---rD   c                .    U R                   R                  $ r9   )r5   urlrH   s    rA   rd   LegacyAPIResponse.url   s    !!%%%rD   c                .    U R                   R                  $ r9   )r^   methodrH   s    rA   rg   LegacyAPIResponse.method   s      '''rD   c                .    U R                   R                  $ )zrReturn the binary response content.

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

NOTE: this will be turned into a method in the next major version.
)r5   textrH   s    rA   rm   LegacyAPIResponse.text   s     !!&&&rD   c                .    U R                   R                  $ r9   )r5   http_versionrH   s    rA   rp   LegacyAPIResponse.http_version   s    !!...rD   c                .    U R                   R                  $ r9   )r5   	is_closedrH   s    rA   rs   LegacyAPIResponse.is_closed   s    !!+++rD   c                .    U R                   R                  $ )zCThe time taken for the complete request/response cycle to complete.)r5   elapsedrH   s    rA   rv   LegacyAPIResponse.elapsed   s     !!)))rD   c               
   U(       a  [        U5      (       a  [        US5      nU R                  (       GaD  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 R"                  U R                  [        [        U R                  5      S95      $ Ub  UOU R"                  n[        U5      (       a  [        US5      nU[$        L a  [        [        S 5      $ U R                  nU[&        :X  a  [        [        UR(                  5      $ U[*        :X  a#  [        [        [+        UR(                  5      5      $ U[,        :X  a#  [        [        [-        UR(                  5      5      $ U[.        :X  a+  [        [        UR(                  R1                  5       S:H  5      $ [3        U5      =(       d    Un[4        R6                  " U5      (       a+  [9        U[:        5      (       a  [        [        U" U5      5      $ U[<        :X  a  [?        S	5      e[4        R6                  " U5      (       aN  [9        U[@        RB                  5      (       a/  U[@        RB                  :w  a  [E        S
5      e[        [        U5      $ [4        R6                  " U5      (       a?  [9        U[F        5      (       d*  [9        U[H        RF                  5      (       a  [	        S5      eU[J        Laz  U[L        Laq  U[N        Lah  U[P        La_  [9        U[F        5      (       dJ  [?        SU S[F         S[N         S[L         S[P         S[$         S[&         S[@        RB                   S35      eURR                  RU                  SS5      RW                  S5      tpgUS:w  a|  [Y        U5      (       a,   UR[                  5       nU R                  R]                  UUUS9$ U R                  Rf                  (       a  [i        USU S3UR(                  S9eUR(                  $ UR[                  5       nU R                  R]                  UUUS9$ ! [^         a*  n	[`        Rc                  S[e        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)r<   responser=   r1   truez+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)datar<   rz   z5Could not read JSON from response data due to %s - %szMExpected Content-Type response header to be `application/json` but received `z
` instead.)rz   messagebody)5r   r   r0   r   	TypeErrorr   r   r   r%   r   r5   r   r-   r2   r$   _default_stream_clsMissingStreamClassErrorr+   r   strrm   r6   floatr/   lowerr   inspectisclass
issubclassHttpxBinaryResponseContentr(   RuntimeErrorhttpxResponse
ValueErrorr   pydanticobjectlistdictr   rF   rG   splitr   json_process_response_data	Exceptionr&   debugtype_strict_response_validationr    )
r:   rM   r?   r<   rz   origincontent_type_r   excs
             rA   rS   LegacyAPIResponse._parse   s   #B''!"a(B<<<+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!-// MM!//T\\2  "DMM W%%&w2Gh4= %%c>8==))c>3x}}-..e5/00d?8==..0F:;;G$/??6""z&:T'U'U78,--&&LMM??6""z&%..'I'I %..( #]__8$$??6"":fi+H+HZX^`h`r`rMsMs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   7T 
U T<<Uc                j    SU R                    SU R                  R                   SU R                   S3$ )Nz<APIResponse [ z] type=>)ra   r5   reason_phraser+   rH   s    rA   __repr__LegacyAPIResponse.__repr__L  s;     0 0143E3E3S3S2TT[\`\i\i[jjkllrD   )r+   r-   r3   r.   r0   r2   r5   r7   )r;   r4   r<   r*   r=   r,   r>   r/   r?   r1   r@   r!   r7   r6   returnNoner   z
str | None)rM   ztype[_T]r   r%   )r   r$   )rM   ztype[_T] | Noner   zR | _T)r   zhttpx.Headers)r   zhttpx.Request)r   r6   )r   z	httpx.URLr   r   r   bytes)r   r/   )r   zdatetime.timedelta)__name__
__module____qualname____firstlineno____doc____annotations__rB   propertyrI   r   rN   rF   r^   ra   rd   rg   rj   rm   rp   rs   rv   rS   r   r   __static_attributes__rL   rD   rA   r(   r(   -   s   
 !!))MBB!!!!M + + 	+
 %+ + F+ %+ + 
+( > > / / -1 -^ * * * * . . & & ( ( * * ' ' / / , , * * /3 E
N m mrD   r(   c                  ,   ^  \ rS rSrSU 4S jjrSrU =r$ )r   iQ  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)superrB   )r:   	__class__s    rA   rB    MissingStreamClassError.__init__R  s     I	
rD   rL   r   r   )r   r   r   r   rB   r   __classcell__)r   s   @rA   r   r   Q  s    
 
rD   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   rG   r   r(   r$   argskwargsr   funcs      rA   wrapped(to_raw_response_wrapper.<locals>.wrapped]  sS    (ZDfjj6Q,R,XVX(Z-3)*"/%a($*?*?@@rD   r   zP.argsr   zP.kwargsr   zLegacyAPIResponse[R]	functoolswrapsr   r   s   ` rA   to_raw_response_wrapperr   X  s)    
 __TA A NrD   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      rA   r   .async_to_raw_response_wrapper.<locals>.wrappedn  s\     (ZDfjj6Q,R,XVX(Z-3)*"/%a(d0Ef0E*EFF*Es   AA"A 
	A"r   r   r   s   ` rA   async_to_raw_response_wrapperr   i  s)    
 __TG G NrD   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   iz  r4   rz   c                    Xl         g r9   rz   )r:   rz   s     rA   rB   #HttpxBinaryResponseContent.__init__}  s     rD   c                .    U R                   R                  $ r9   )rz   rj   rH   s    rA   rj   "HttpxBinaryResponseContent.content  s    }}$$$rD   c                .    U R                   R                  $ r9   )rz   rm   rH   s    rA   rm   HttpxBinaryResponseContent.text  s    }}!!!rD   c                .    U R                   R                  $ r9   )rz   encodingrH   s    rA   r   #HttpxBinaryResponseContent.encoding  s    }}%%%rD   c                .    U R                   R                  $ r9   )rz   charset_encodingrH   s    rA   r   +HttpxBinaryResponseContent.charset_encoding  s    }}---rD   c                :    U R                   R                  " S0 UD6$ )NrL   )rz   r   )r:   r   s     rA   r   HttpxBinaryResponseContent.json  s    }}!!+F++rD   c                6    U R                   R                  5       $ r9   )rz   readrH   s    rA   r   HttpxBinaryResponseContent.read  s    }}!!##rD   Nc                8    U R                   R                  U5      $ r9   )rz   
iter_bytesr:   
chunk_sizes     rA   r   %HttpxBinaryResponseContent.iter_bytes  s    }}''
33rD   c                8    U R                   R                  U5      $ r9   )rz   	iter_textr   s     rA   r   $HttpxBinaryResponseContent.iter_text  s    }}&&z22rD   c                6    U R                   R                  5       $ r9   )rz   
iter_linesrH   s    rA   r   %HttpxBinaryResponseContent.iter_lines  s    }}''))rD   c                8    U R                   R                  U5      $ r9   )rz   iter_rawr   s     rA   r   #HttpxBinaryResponseContent.iter_raw  s    }}%%j11rD   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openrz   r   write)r:   filefr   s       rA   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 instead)r   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        rA   stream_to_file)HttpxBinaryResponseContent.stream_to_file  s@     $T"a00< = #""s   4A
Ac                6    U R                   R                  5       $ r9   )rz   closerH   s    rA   r   HttpxBinaryResponseContent.close  s    }}""$$rD   c                R   #    U R                   R                  5       I S h  vN $  N7fr9   )rz   areadrH   s    rA   r   HttpxBinaryResponseContent.aread  s     ]]((****   '%'c                @   #    U R                   R                  U5      $ 7fr9   )rz   aiter_bytesr   s     rA   r	  &HttpxBinaryResponseContent.aiter_bytes  s     }}((44   c                @   #    U R                   R                  U5      $ 7fr9   )rz   
aiter_textr   s     rA   r  %HttpxBinaryResponseContent.aiter_text  s     }}''
33r  c                >   #    U R                   R                  5       $ 7fr9   )rz   aiter_linesrH   s    rA   r  &HttpxBinaryResponseContent.aiter_lines  s     }}((**s   c                @   #    U R                   R                  U5      $ 7fr9   )rz   	aiter_rawr   s     rA   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   rz   r	  r   )r:   r   r   pathr   r   s         rA   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r9   )rz   acloserH   s    rA   r  !HttpxBinaryResponseContent.aclose  s     ]]))++++r  r   )rz   r4   r   r   r   r   r   )r   r   r   r   r9   )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   rB   r   rj   rm   r   r   r   r   r   r   r   r   r   r   r   r  r  r	  r  r  r  r  r  r   rL   rD   rA   r   r   z  s5   ! % % " " & & . .,$43*2$ 
   	M "&	$ 	
 
%+54+3  	M "&		$$	$ 		$
 
	$	$,rD   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]]])>
__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   _modelsr   r   r   
_constantsr   
_streamingr   r   r   r   _exceptionsr    r!   _base_clientr"   r#   r$   r%   	getLoggerr   r&   r   r(   r   r   r   r   r   rL   rD   rA   <module>r0     s    " 	       U T     A A < < + \ \ 3,( cNCLT]''1^ 1am
 amH	
i 
""f, f,rD   