
    ~i9                       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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mZ ddlmZmZmZmZ ddl m!Z!m"Z"m#Z# dd	l$m%Z% dd
l&m'Z'm(Z(m)Z)m*Z* erddl+m,Z, ddl-m.Z.  ed          Z/ ed          Z0 ed          Z1 ej2        e3          Z4de5d<    G d dee0                   Z6 G d de7          Z8d dZ9d!dZ: G d d          Z;dS )"    )annotationsN)
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)	BaseModelis_basemodeladd_request_id)RAW_RESPONSE_HEADER)StreamAsyncStreamis_stream_class_typeextract_stream_chunk_type)RequestOptions)
BaseClientPR_Tzlogging.Loggerlogc                     e Zd ZU dZ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	d%d&d@d)Z	edAd+            Z
edBd-            ZedCd.            ZedDd0            ZedEd2            ZedFd4            ZedEd5            ZedEd6            ZedGd7            ZedHd9            Zd%d&d@d:ZedEd;            Zd%S )ILegacyAPIResponsea  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   )r5   rawcast_toclientstream
stream_clsoptionsreturnNonec               v    || _         || _        i | _        || _        || _        || _        || _        || _        d S N)r)   r+   r,   r.   r0   r1   r3   r5   )selfr6   r7   r8   r9   r:   r;   r5   s           q/root/.openclaw/workspace/.venvs/ark-sdk/lib/python3.11/site-packages/volcenginesdkarkruntime/_legacy_response.py__init__zLegacyAPIResponse.__init__S   sF      !% *    
str | Nonec                @    | j         j                            d          S )Nzx-request-id)r3   headersgetr@   s    rA   
request_idzLegacyAPIResponse.request_idg   s    !)--n===rC   totype[_T]r$   c                   d S r?    )r@   rJ   s     rA   parsezLegacyAPIResponse.parsek   s    ,/CrC   r#   c                    d S r?   rM   rH   s    rA   rN   zLegacyAPIResponse.parsen   s    #rC   NrJ   type[_T] | NoneR | _Tc               x   ||n| j         }| j                            |          }||S |                     |          }t	          | j        j                  r| j                            |          }t          |t                    rt          || j
                   || j        |<   t          t          |          S )NrP   )r)   r,   rG   _parser   r1   post_parser
isinstancer   r   rI   r   r#   )r@   rJ   	cache_keycachedparseds        rA   rN   zLegacyAPIResponse.parseq   s    .BBdm	%)))44M##DM-.. 	7]..v66Ffi(( 	464?333*0Y'AvrC   httpx.Headersc                    | j         j        S r?   )r3   rF   rH   s    rA   rF   zLegacyAPIResponse.headers       !))rC   httpx.Requestc                    | j         j        S r?   )r3   requestrH   s    rA   http_requestzLegacyAPIResponse.http_request   r\   rC   c                    | j         j        S r?   )r3   status_coderH   s    rA   rb   zLegacyAPIResponse.status_code   s    !--rC   	httpx.URLc                    | j         j        S r?   )r3   urlrH   s    rA   re   zLegacyAPIResponse.url   s    !%%rC   strc                    | j         j        S r?   )r`   methodrH   s    rA   rh   zLegacyAPIResponse.method   s     ''rC   bytesc                    | j         j        S )zReturn the binary response content.

        NOTE: this will be removed in favour of `.read()` in the
        next major version.
        )r3   contentrH   s    rA   rk   zLegacyAPIResponse.content   s     !))rC   c                    | j         j        S )zyReturn the decoded response content.

        NOTE: this will be turned into a method in the next major version.
        )r3   textrH   s    rA   rm   zLegacyAPIResponse.text   s     !&&rC   c                    | j         j        S r?   )r3   http_versionrH   s    rA   ro   zLegacyAPIResponse.http_version   s    !..rC   c                    | j         j        S r?   )r3   	is_closedrH   s    rA   rq   zLegacyAPIResponse.is_closed   s    !++rC   datetime.timedeltac                    | j         j        S )zCThe time taken for the complete request/response cycle to complete.)r3   elapsedrH   s    rA   rt   zLegacyAPIResponse.elapsed   s     !))rC   c               0
   ||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$          t1          |j                            S |t2          k    r't          t$          t3          |j                            S |t4          k    r0t          t$          |j                                        dk              S t9          j        |          r3t=          |t>                    rt          t$           ||                    S |t@          k    rtC          d	          t9          j        |          rNt=          |tD          j#                  r4|tD          j#        k    rtI          d
          t          t$          |          S t9          j        |          r>t=          |tJ                    s)t=          |tL          j%                  rt          d          |tN          ur|tP          urw|tR          urn|tT          uret=          |tJ                    sPtC          d| dtJ           dtR           dtP           dtT           dt*           dt,           dtD          j#         d          |j+        ,                    dd          -                    d          ^}}|dk    rt]          |          rr	 |/                                }| j        0                    |||          S # tb          $ r3}	td          3                    dti          |	          |	           Y d }	~	nd }	~	ww xY w|j        S |/                                }| j        0                    |||          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)r7   responser8   r/   truez+Unexpected state - cast_to is `APIResponse`z:Subclasses of httpx.Response cannot be passed to `cast_to`z2Pydantic models must subclass our base model type.zUnsupported type, expected z to be a subclass of z, .zcontent-type*;zapplication/json)datar7   rw   z5Could not read JSON from response data due to %s - %s)5r)   r   	__value__r   r   r   r.   r   	TypeErrorr   r   r   r$   r   r3   r   r+   r0   r#   _default_stream_clsMissingStreamClassErrorr   rf   rm   r4   floatr-   lowerinspectisclass
issubclassHttpxBinaryResponseContentr'   RuntimeErrorhttpxResponse
ValueErrorr   pydanticobjectlistdictr   rF   rG   splitr   json_process_response_data	Exceptionr%   debugtype)
r@   rJ   r7   originr:   rw   content_type_r|   excs
             rA   rT   zLegacyAPIResponse._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=)))c>>3x}--...e5//000d??8=..00F:;;;?6"" 	.z&:T'U'U 	.778,,---&&&LMMM?
 
 	%00	% %.(( P   8$$$ O 	R vy11		R
 68#566	R PQQQ 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   
S*)SSc                B    d| j          d| j        j         d| j         dS )Nz<APIResponse [ z] type=>)rb   r3   reason_phraser)   rH   s    rA   __repr__zLegacyAPIResponse.__repr__F  s0    l 0ll43E3Sll\`\illllrC   )r6   r2   r7   r(   r8   r*   r9   r-   r:   r/   r;   r    r5   r4   r<   r=   r<   rD   )rJ   rK   r<   r$   )r<   r#   )rJ   rQ   r<   rR   )r<   rZ   )r<   r]   )r<   r4   )r<   rc   r<   rf   r<   ri   )r<   r-   )r<   rr   )__name__
__module____qualname____doc____annotations__rB   propertyrI   r   rN   rF   r`   rb   re   rh   rk   rm   ro   rq   rt   rT   r   r   rM   rC   rA   r'   r'   :   s        
 
 !!!!))))MMMBBBB!!!!M + + + + + +( > > > X> /// X/ X-1        * * * X* * * * X* . . . X. & & & X& ( ( ( X( * * * X* ' ' ' X' / / / X/ , , , X, * * * X* /3 Q
 Q
 Q
 Q
 Q
 Q
f m m m Xm m mrC   r'   c                        e Zd Zd fdZ xZS )r   r<   r=   c                J    t                                          d           d S )NzTThe `stream` argument was set to `True` but the `stream_cls` argument was not given.)superrB   )r@   	__class__s    rA   rB   z MissingStreamClassError.__init__L  s,    b	
 	
 	
 	
 	
rC   r<   r=   )r   r   r   rB   __classcell__)r   s   @rA   r   r   K  s=        
 
 
 
 
 
 
 
 
 
rC   r   funcCallable[P, R]r<   !Callable[P, LegacyAPIResponse[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.kwargsr<   LegacyAPIResponse[R]c                     i t          t          |                    d                    pi }d|t          <   ||d<   t          t          t
                    | i |          S Nextra_headersrx   r   r   rG   r   r'   r#   r   r   r   r   s      rA   wrappedz(to_raw_response_wrapper.<locals>.wrappedW  si    )
CO4455;)
 .4)*"/%a($$*?*?*?@@@rC   r   r   r   r   r<   r   	functoolswrapsr   r   s   ` rA   to_raw_response_wrapperr   R  sE    
 _TA A A A A A NrC   Callable[P, Awaitable[R]],Callable[P, Awaitable[LegacyAPIResponse[R]]]c                H     t          j                   d fd            }|S )	r   r   r   r   r   r<   r   c                    K   i t          t          |                    d                    pi }d|t          <   ||d<   t          t          t
                    | i | d {V           S r   r   r   s      rA   r   z.async_to_raw_response_wrapper.<locals>.wrappedl  s      )
CO4455;)
 .4)*"/%a(d0Ef0E0E*E*E*E*E*E*EFFFrC   r   r   r   s   ` rA   async_to_raw_response_wrapperr   e  sE     _TG G G G G G NrC   c                      e Zd ZU ded<   d&dZed'd            Zed(d	            Zed)d            Zed)d            Z	d*dZ
d'dZd+d,dZd+d-dZd.dZd+d,dZd/dZd0dZd'dZd+d1d Zd+d2d"Zd3d#Zd+d1d$Zd0d%ZdS )4r   r2   rw   r<   r=   c                    || _         d S r?   )rw   )r@   rw   s     rA   rB   z#HttpxBinaryResponseContent.__init__}  s     rC   ri   c                    | j         j        S r?   )rw   rk   rH   s    rA   rk   z"HttpxBinaryResponseContent.content  s    }$$rC   rf   c                    | j         j        S r?   )rw   rm   rH   s    rA   rm   zHttpxBinaryResponseContent.text  s    }!!rC   rD   c                    | j         j        S r?   )rw   encodingrH   s    rA   r   z#HttpxBinaryResponseContent.encoding  s    }%%rC   c                    | j         j        S r?   )rw   charset_encodingrH   s    rA   r   z+HttpxBinaryResponseContent.charset_encoding  s    }--rC   r   r   c                &     | j         j        di |S )NrM   )rw   r   )r@   r   s     rA   r   zHttpxBinaryResponseContent.json  s    !t}!++F+++rC   c                4    | j                                         S r?   )rw   readrH   s    rA   r   zHttpxBinaryResponseContent.read  s    }!!###rC   N
chunk_size
int | NoneIterator[bytes]c                6    | j                             |          S r?   )rw   
iter_bytesr@   r   s     rA   r   z%HttpxBinaryResponseContent.iter_bytes  s    }''
333rC   Iterator[str]c                6    | j                             |          S r?   )rw   	iter_textr   s     rA   r   z$HttpxBinaryResponseContent.iter_text  s    }&&z222rC   c                4    | j                                         S r?   )rw   
iter_linesrH   s    rA   r   z%HttpxBinaryResponseContent.iter_lines  s    }'')))rC   c                6    | j                             |          S r?   )rw   iter_rawr   s     rA   r   z#HttpxBinaryResponseContent.iter_raw  s    }%%j111rC   filestr | os.PathLike[str]c                    t          |d          5 }| j                                        D ]}|                    |           	 ddd           dS # 1 swxY w Y   dS )av  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)openrw   r   write)r@   r   fr|   s       rA   write_to_filez(HttpxBinaryResponseContent.write_to_file  s     $T""" 	a0022  	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   2AAAc                4    | j                                         S r?   )rw   closerH   s    rA   r   z HttpxBinaryResponseContent.close  s    }""$$$rC   c                D   K   | j                                          d {V S r?   )rw   areadrH   s    rA   r   z HttpxBinaryResponseContent.aread  s,      ]((*********rC   AsyncIterator[bytes]c                :   K   | j                             |          S r?   )rw   aiter_bytesr   s     rA   r   z&HttpxBinaryResponseContent.aiter_bytes  s      }((444rC   AsyncIterator[str]c                :   K   | j                             |          S r?   )rw   
aiter_textr   s     rA   r   z%HttpxBinaryResponseContent.aiter_text  s      }''
333rC   c                8   K   | j                                         S r?   )rw   aiter_linesrH   s    rA   r   z&HttpxBinaryResponseContent.aiter_lines  s      }((***rC   c                :   K   | j                             |          S r?   )rw   	aiter_rawr   s     rA   r   z$HttpxBinaryResponseContent.aiter_raw  s      }&&z222rC   c                D   K   | j                                          d {V S r?   )rw   acloserH   s    rA   r   z!HttpxBinaryResponseContent.aclose  s,      ]))+++++++++rC   )rw   r2   r<   r=   r   r   r   )r   r   r<   r   r?   )r   r   r<   r   )r   r   r<   r   )r<   r   )r   r   r<   r=   r   )r   r   r<   r   )r   r   r<   r   )r<   r   )r   r   r   r   rB   r   rk   rm   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rM   rC   rA   r   r   z  s        ! ! ! ! % % % X% " " " X" & & & X& . . . X., , , ,$ $ $ $4 4 4 4 43 3 3 3 3* * * *2 2 2 2 2    % % % %+ + + +5 5 5 5 54 4 4 4 4+ + + +3 3 3 3 3, , , , , ,rC   r   )r   r   r<   r   )r   r   r<   r   )<
__future__r   osr   loggingdatetimer   typingr   r   r   r   r   r	   r
   r   r   r   typing_extensionsr   r   r   r   r   r   _typesr   _utilsr   r   r   r   _modelsr   r   r   
_constantsr   
_streamingr   r   r   r   _request_optionsr    _base_clientr!   r"   r#   r$   	getLoggerr   r%   r   r'   r~   r   r   r   r   rM   rC   rA   <module>r     s   # " " " " " " 				                               I H H H H H H H H H H H         U U U U U U U U U U U U < < < < < < < < < < + + + + + +             )000000((((((IcNNGCLLWT]]'g'11 1 1 1 1Nm Nm Nm Nm Nm
 Nm Nm Nmb
 
 
 
 
i 
 
 
   &   *K, K, K, K, K, K, K, K, K, K,rC   