
    ~iO                    "   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mZ d dlZd dlmZmZmZ ddlmZ ddlmZmZ dd	lm Z  dd
l!m"Z"m#Z#m$Z$m%Z% ddl&m'Z'm(Z(m)Z)m*Z* ddl+m,Z,m-Z-m.Z. erddl/m0Z0 ddl1m2Z2  ed          Z3 ed          Z4 ed          Z5 edd          Z6 edd          Z7 edee'e
         e(e
         f                   Z8 ej9        e:          Z;de<d<    G d dee4                   Z= G d de=e4                   Z> G d de=e4                   Z? G d  d!e@          ZA G d" d#e           ZBd4d(ZCd5d+ZDd6d-ZEd7d/ZF G d0 d1ee6                   ZG G d2 d3ee7                   ZHdS )8    )annotationsN)TracebackType)AnyUnionGenericTypeVarIteratorAsyncIteratorcastCallable	AwaitableTYPE_CHECKINGoverload)	ParamSpecoverride
get_origin   )NoneType)CLIENT_REQUEST_HEADERRAW_RESPONSE_HEADER)ArkError)is_givenextract_type_argis_annotated_typeis_type_alias_type)StreamAsyncStreamis_stream_class_typeextract_stream_chunk_type)	BaseModelis_basemodeladd_request_id)RequestOptions)
BaseClientPR_T_APIResponseTzArkAPIResponse[Any])bound_AsyncAPIResponseTzArkAsyncAPIResponse[Any]_DefaultStreamTzlogging.Loggerlogc                  f   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Zed0d            Zed1d            Zed2d            Zed3d             Z	ed4d"            Z
ed0d#            Zed0d$            Zed5d&            Zed6d'            Zed0d(            Zd)d*d7d.Zd)S )8BaseAPIResponsetype[R]_cast_tor$   _clientzdict[type[Any], Any]_parsed_by_typebool_is_sse_stream1type[Stream[Any]] | type[AsyncStream[Any]] | None_stream_clsstr_request_idr#   _optionshttpx.Responsehttp_responserawcast_toclientstream
stream_clsoptionsreturnNonec               h    || _         || _        i | _        || _        || _        || _        || _        d S N)r0   r1   r2   r4   r6   r;   r9   )selfr<   r=   r>   r?   r@   rA   s          j/root/.openclaw/workspace/.venvs/ark-sdk/lib/python3.11/site-packages/volcenginesdkarkruntime/_response.py__init__zBaseAPIResponse.__init__I   s=      !$%     c                J    | j         j                            t                    S rE   r;   headersgetr   rF   s    rG   
request_idzBaseAPIResponse.request_id[   s    !)--.CDDDrI   httpx.Headersc                    | j         j        S rE   )r;   rL   rN   s    rG   rL   zBaseAPIResponse.headers_       !))rI   httpx.Requestc                    | j         j        S rE   )r;   requestrN   s    rG   http_requestzBaseAPIResponse.http_requestc   rR   rI   intc                    | j         j        S rE   )r;   status_coderN   s    rG   rY   zBaseAPIResponse.status_codeg   s    !--rI   	httpx.URLc                    | j         j        S rE   )r;   urlrN   s    rG   r\   zBaseAPIResponse.urlk   s    !%%rI   c                    | j         j        S rE   )rV   methodrN   s    rG   r^   zBaseAPIResponse.methodo   s     ''rI   c                    | j         j        S rE   )r;   http_versionrN   s    rG   r`   zBaseAPIResponse.http_versions   s    !..rI   datetime.timedeltac                    | j         j        S rE   )r;   elapsedrN   s    rG   rc   zBaseAPIResponse.elapsedw   rR   rI   c                    | j         j        S rE   )r;   	is_closedrN   s    rG   re   zBaseAPIResponse.is_closed{   s    !++rI   c           	     \    d| j         j         d| j         d| j        j         d| j         d	S )N<z [ z] type=>)	__class____name__rY   r;   reason_phraser0   rN   s    rG   __repr__zBaseAPIResponse.__repr__   s=    z4>*zzd.>zzASAazzjnjwzzzzrI   Ntoro   type[_T] | NoneR | _Tc               f
   ||n| j         }t          |          r|j        }|rt          |          rt	          |d          }t          |          p|}| j        rF|r{t          |          st          dt           dt                     t          t           |t          |d          | j        t          t          | j                                      S | j        rZt          t$          |                     t          | j                  | j        t          t          | j                                      S t          d| j        j                  }|t)                      t          t$           ||| j        t          t          | j                                      S |t*          u rt          t$          d           S | j        }|t,          k    rt          t$          |j                  S |t0          k    rt          t$          |j                  S |t4          k    r't          t$          t5          |j                            S |t6          k    r't          t$          t7          |j                            S |t8          k    r0t          t$          |j                                        dk              S t=          j        |          r)|j         d	k    rt          t$           ||                    S |tB          k    rtE          d
          t=          j        |          rNtG          |tH          j%                  r4|tH          j%        k    rtM          d          t          t$          |          S t=          j        |          r>tG          |tN                    s)tG          |tP          j'                  rt          d          |tR          ur|tT          urw|tV          urn|tX          uretG          |tN                    sPtE          d| dtN           dtV           dtT           dtX           dt*           dt,           dtH          j%         d          |j-        .                    dd          /                    d          ^}}|dk    rta          |          rr	 |1                                }| j        2                    |||          S # tf          $ r3}	th          5                    dtm          |	          |	           Y d }	~	nd }	~	ww xY w|j        S |1                                }| j        2                    |||          S )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>   r5   trueHttpxBinaryResponseContentz+Unexpected state - cast_to is `APIResponse`z:Subclasses of httpx.Response cannot be passed to `cast_to`z1Pydantic models must subclass our base model typezUnsupported type, expected z to be a subclass of z, .zcontent-type*;zapplication/json)datar=   rt   z5Could not read JSON from response data due to %s - %s)7r0   r   	__value__r   r   r   r4   r   	TypeErrorr   r   r   r'   r   r;   r   r1   r6   r&   _default_stream_clsMissingStreamClassErrorr   r7   textbytescontentrW   floatr3   lowerinspectisclassrk   ArkAPIResponseRuntimeError
issubclasshttpxResponse
ValueErrorr    pydanticobjectlistdictr   rL   rM   splitr!   json_process_response_data	Exceptionr,   debugtype)
rF   ro   r=   originr@   rt   content_type_rz   excs
             rG   _parsezBaseAPIResponse._parse   s   ""DM g&& 	('G  	3(11 	3&w22GG$$/ +	 +B// #c&ccVacc   B 9 -D! ! ! "&!3#C66  
 
 
  $$ 9$:J K K!%!3#C66 %     C0 J !-///
#!/T\22     h4== %c>>8=)))e8+,,,c>>3x}--...e5//000d??8=..00F:;;; OG$$	. $@@@778,,---^##LMMM?6"" 
	%z&%.'I'I 
	% %.(( P   8$$$ O 	Q vy11		Q
 68#566	Q OPPP 6!!d""d""e##vy11 $  Yg  Y  YI  Y  YY]  Y  Yae  Y  Yin  Y  Yrz  Y  Y  B  Y  Y  HM  HV  Y  Y  Y   $+//DDJJ3OOq---G$$ #==??D  <>>! '!) ?    !   IIOS		         = }}|22 3 
 
 	
s   
R; ;
S8)S33S8)r<   r:   r=   r/   r>   r$   r?   r3   r@   r5   rA   r#   rB   rC   rB   r7   )rB   rP   )rB   rS   )rB   rW   )rB   rZ   )rB   ra   )rB   r3   ro   rp   rB   rq   )rk   
__module____qualname____annotations__rH   propertyrO   rL   rV   rY   r\   r^   r`   rc   re   r   rm   r    rI   rG   r.   r.   >   s        ))))BBBB!!!!       $ E E E XE * * * X* * * * X* . . . X. & & & X& ( ( ( X( / / / X/ * * * X* , , , X, { { { X{ /3 V
 V
 V
 V
 V
 V
 V
 V
rI   r.   c                  p    e Z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dS )!r   rB   r7   c                L    | j         j                            t          d          S N rK   rN   s    rG   rO   zArkAPIResponse.request_id      !)--.CRHHHrI   Nrn   ro   rp   rq   c                  ||n| j         }| j                            |          }||S | j        s|                                  |                     |          }t          | j        j                  r| j                            |          }t          |t                    rt          || j                   || j        |<   t          t          |          S )aZ  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
        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`
        Nrn   r0   r2   rM   r4   readr   r   r9   post_parser
isinstancer    r"   rO   r   r&   rF   ro   	cache_keycachedparseds        rG   parsezArkAPIResponse.parse!  s    6 .BBdm	%)))44M" 	IIKKK##DM-.. 	7]..v66Ffi(( 	464?333*0Y'AvrI   r   c                    	 | j                                         S # t          j        $ r}t	                      |d }~ww xY wrE   )r;   r   r   StreamConsumedStreamAlreadyConsumedrF   r   s     rG   r   zArkAPIResponse.readN  sL    	3%**,,,# 	3 	3 	3'))s2	3s    >9>c                B    |                                   | j        j        S rE   r   r;   r   rN   s    rG   r   zArkAPIResponse.textT  s    		!&&rI   r   c                \    |                                   | j                                        S rE   r   r;   r   rN   s    rG   r   zArkAPIResponse.jsonX  s$    		!&&(((rI   rC   c                8    | j                                          d S rE   )r;   closerN   s    rG   r   zArkAPIResponse.close\  s      """""rI   
chunk_size
int | NoneIterator[bytes]c              #  L   K   | j                             |          D ]}|V  d S rE   )r;   
iter_bytesrF   r   chunks      rG   r   zArkAPIResponse.iter_bytes_  s;      '22:>> 	 	EKKKK	 	rI   Iterator[str]c              #  L   K   | j                             |          D ]}|V  d S rE   )r;   	iter_textr   s      rG   r   zArkAPIResponse.iter_textc  s;      '11*== 	 	EKKKK	 	rI   c              #  J   K   | j                                         D ]}|V  d S rE   )r;   
iter_linesrF   r   s     rG   r   zArkAPIResponse.iter_linesg  s9      '2244 	 	EKKKK	 	rI   r   r   rB   r   rB   r   rB   rC   rE   )r   r   rB   r   )r   r   rB   r   )rB   r   )rk   r   r   r   rO   r   r   r   r   r   r   r   r   r   rI   rG   r   r     s        I I I XI .2 + + + + + +Z3 3 3 3' ' ' ') ) ) )# # # #             rI   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d
S )(ArkAsyncAPIResponserB   r7   c                L    | j         j                            t          d          S r   rK   rN   s    rG   rO   zArkAsyncAPIResponse.request_idm  r   rI   ro   type[_T]r'   c               
   K   d S rE   r   )rF   ro   s     rG   r   zArkAsyncAPIResponse.parseq  s      25#rI   r&   c                
   K   d S rE   r   rN   s    rG   r   zArkAsyncAPIResponse.parset  s       #rI   Nrn   rp   rq   c                 K   ||n| j         }| j                            |          }||S | j        s|                                  d{V  |                     |          }t          | j        j                  r| j                            |          }t          |t                    rt          || j                   || j        |<   t          t          |          S )a4  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
        class MyModel(BaseModel):
            foo: str


        obj = response.parse(to=MyModel)
        print(obj.foo)
        ```

        We support parsing:
          - `BaseModel`
          - `dict`
          - `list`
          - `Union`
          - `str`
          - `httpx.Response`
        Nrn   r   r   s        rG   r   zArkAsyncAPIResponse.parsew  s      2 .BBdm	%)))44M" 	))++##DM-.. 	7]..v66Ffi(( 	464?333*0Y'AvrI   r   c                   K   	 | j                                          d{V S # t          j        $ r}t	                      |d}~ww xY w)z,Read and return the binary response content.N)r;   areadr   r   r   r   s     rG   r   zArkAsyncAPIResponse.read  sd      	3+11333333333# 	3 	3 	3 ())s2		3s   # AAAc                R   K   |                                   d{V  | j        j        S )z3Read and decode the response content into a string.Nr   rN   s    rG   r   zArkAsyncAPIResponse.text  s2      iikk!&&rI   r   c                l   K   |                                   d{V  | j                                        S )z*Read and decode the JSON response content.Nr   rN   s    rG   r   zArkAsyncAPIResponse.json  s;      iikk!&&(((rI   rC   c                H   K   | j                                          d{V  dS )zClose the response and release the connection.

        Automatically called if the response body is read to completion.
        N)r;   acloserN   s    rG   r   zArkAsyncAPIResponse.close  s5      
  '')))))))))))rI   r   r   AsyncIterator[bytes]c               Z   K   | j                             |          2 3 d{V }|W V  6 dS )z
        A byte-iterator over the decoded response content.

        This automatically handles gzip, deflate and brotli encoded responses.
        N)r;   aiter_bytesr   s      rG   r   zArkAsyncAPIResponse.iter_bytes  sZ        -99*EE 	 	 	 	 	 	 	%KKKKK FEE   *AsyncIterator[str]c               Z   K   | j                             |          2 3 d{V }|W V  6 dS )zA str-iterator over the decoded response content
        that handles both gzip, deflate, etc but also detects the content's
        string encoding.
        N)r;   
aiter_textr   s      rG   r   zArkAsyncAPIResponse.iter_text  sZ      
  -88DD 	 	 	 	 	 	 	%KKKKK EDDr   c               X   K   | j                                         2 3 d{V }|W V  6 dS )z;Like `iter_text()` but will only yield chunks for each lineN)r;   aiter_linesr   s     rG   r   zArkAsyncAPIResponse.iter_lines  sU      -99;; 	 	 	 	 	 	 	%KKKKK <;;s   )r   )ro   r   rB   r'   )rB   r&   r   r   r   r   rE   )r   r   rB   r   )r   r   rB   r   )rB   r   )rk   r   r   r   rO   r   r   r   r   r   r   r   r   r   r   rI   rG   r   r   l  s       I I I XI 555 X5### X#37 ) ) ) ) ) )V3 3 3 3' ' ' '
) ) ) )
* * * *             rI   r   c                        e Zd Zd fdZ xZS )r~   rB   rC   c                J    t                                          d           d S )NzTThe `stream` argument was set to `True` but the `stream_cls` argument was not given.superrH   )rF   rj   s    rG   rH   z MissingStreamClassError.__init__  s,    b	
 	
 	
 	
 	
rI   r   rk   r   r   rH   __classcell__rj   s   @rG   r~   r~     s=        
 
 
 
 
 
 
 
 
 
rI   r~   c                        e Zd Zd fdZ xZS )r   rB   rC   c                N    d}t                                          |           d S )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   )rF   messagerj   s     rG   rH   zStreamAlreadyConsumed.__init__  s.    A 	 	!!!!!rI   r   r   r   s   @rG   r   r     s=        
" 
" 
" 
" 
" 
" 
" 
" 
" 
"rI   r   funcCallable[P, R]rB   Callable[P, ArkAPIResponse[R]]c                H     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.
    argsP.argskwargsP.kwargsrB   ArkAPIResponse[R]c                     i t          t          |                    d                    pi }d|t          <   ||d<   t          t          t
                    | i |          S Nextra_headersr<   )r   r   rM   r   r   r&   r   r   r   r   s      rG   wrappedz(to_raw_response_wrapper.<locals>.wrapped  sh    )
CO4455;)
 .3)*"/N1%ttT'<V'<'<===rI   )r   r   r   r   rB   r   	functoolswrapsr   r   s   ` rG   to_raw_response_wrapperr     s?    
 _T> > > > > > NrI   Callable[P, Awaitable[R]].Callable[P, Awaitable[ArkAsyncAPIResponse[R]]]c                H     t          j                   d fd            }|S )	r   r   r   r   r   rB   ArkAsyncAPIResponse[R]c                    K   i t          t          |                    d                    pi }d|t          <   ||d<   t          t          t
                    | i | d {V           S r   )r   r   rM   r   r   r&   r   s      rG   r   z.async_to_raw_response_wrapper.<locals>.wrapped  s      )
CO4455;)
 .3)*"/'*$$2G2G2G,G,G,G,G,G,GHHHrI   )r   r   r   r   rB   r  r   r   s   ` rG   async_to_raw_response_wrapperr    sE     _TI I I I I I NrI   6Callable[P, ResponseContextManager[ArkAPIResponse[R]]]c                H     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.
    r   r   r   r   rB   )ResponseContextManager[ArkAPIResponse[R]]c                    i t          t          |                    d                    pi }d|t          <   ||d<   t	          j        g| R i |}t          t          t          g t          t                   f         |                    S Nr   r?   )
r   r   rM   r   r   partialResponseContextManagerr   r   r&   r   r   r   make_requestr   s       rG   r   z-to_streamed_response_wrapper.<locals>.wrapped  s    )
CO4455;)
 .6)*"/ (??????%"nQ//0,??
 
 	
rI   )r   r   r   r   rB   r  r   r   s   ` rG   to_streamed_response_wrapperr    ?     _T
 
 
 
 
 
  NrI   @Callable[P, AsyncResponseContextManager[ArkAsyncAPIResponse[R]]]c                H     t          j                   d fd            }|S )	r  r   r   r   r   rB   3AsyncResponseContextManager[ArkAsyncAPIResponse[R]]c                     i t          t          |                    d                    pi }d|t          <   ||d<    | i |}t	          t          t
          t          t                            |                    S r
  )r   r   rM   r   AsyncResponseContextManagerr   r   r&   r  s       rG   r   z3async_to_streamed_response_wrapper.<locals>.wrapped3  s    )
CO4455;)
 .6)*"/tT,V,,*.q12LAA
 
 	
rI   )r   r   r   r   rB   r  r   r   s   ` rG   "async_to_streamed_response_wrapperr  ,  r  rI   c                  *    e Zd ZdZddZddZddZdS )r  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
    request_funcCallable[[], _APIResponseT]rB   rC   c                "    || _         d | _        d S rE   _request_func!_ResponseContextManager__response)rF   r  s     rG   rH   zResponseContextManager.__init__M  s    )04rI   r(   c                B    |                                  | _        | j        S rE   r  rN   s    rG   	__enter__z ResponseContextManager.__enter__Q  s    ,,..rI   exc_typetype[BaseException] | Noner   BaseException | Noneexc_tbTracebackType | Nonec                J    | j         | j                                          d S d S rE   )r  r   rF   r!  r   r$  s       rG   __exit__zResponseContextManager.__exit__U  s.     ?&O!!##### '&rI   N)r  r  rB   rC   )rB   r(   r!  r"  r   r#  r$  r%  rB   rC   )rk   r   r   __doc__rH   r   r(  r   rI   rG   r  r  G  sZ         
5 5 5 5   $ $ $ $ $ $rI   r  c                  *    e Zd ZdZddZddZddZdS )r  r  api_requestAwaitable[_AsyncAPIResponseT]rB   rC   c                "    || _         d | _        d S rE   _api_request&_AsyncResponseContextManager__response)rF   r,  s     rG   rH   z$AsyncResponseContextManager.__init__e  s    '59rI   r*   c                8   K   | j          d {V | _        | j        S rE   r/  rN   s    rG   
__aenter__z&AsyncResponseContextManager.__aenter__i  s*       $ 1111111rI   r!  r"  r   r#  r$  r%  c                Z   K   | j         !| j                                          d {V  d S d S rE   )r1  r   r'  s       rG   	__aexit__z%AsyncResponseContextManager.__aexit__m  sD       ?&/''))))))))))) '&rI   N)r,  r-  rB   rC   )rB   r*   r)  )rk   r   r   r*  rH   r3  r5  r   rI   rG   r  r  _  sZ         
: : : :   * * * * * *rI   r  )r   r   rB   r   )r   r   rB   r   )r   r   rB   r  )r   r   rB   r  )I
__future__r   datetimer   r   loggingr   typesr   typingr   r   r   r   r	   r
   r   r   r   r   r   r   typing_extensionsr   r   r   _typesr   
_constantsr   r   _exceptionsr   _utilsr   r   r   r   
_streamingr   r   r   r   _modelsr    r!   r"   _request_optionsr#   _base_clientr$   r%   r&   r'   r(   r*   r+   	getLoggerrk   r,   r   r.   r   r   r|   r~   r   r   r  r  r  r  r  r   rI   rG   <module>rE     s?   # " " " " " "                                         = = = = = = = = = =       B B B B B B B B ! ! ! ! ! ! U U U U U U U U U U U U            = < < < < < < < < < )000000((((((IcNNGCLLWT]]/DEEEW19STTT '+5kRUFV9V3WXXX'g'11 1 1 1 1[
 [
 [
 [
 [
gaj [
 [
 [
|M M M M M_Q' M M M`e e e e e/!, e e eP
 
 
 
 
i 
 
 
" " " " "H " " "   &   *   6   6$ $ $ $ $W]3 $ $ $0* * * * *'*<"= * * * * *rI   