
     `iSC                    (   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mZ d dlZd dlZd dlZddlmZ ddlmZmZm Z m!Z! 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, ddl-m.Z. ddl/m0Z0m1Z1 erddl"m2Z2 ddl3m4Z4  ed          Z5 ed          Z6 ed          Z7 edd          Z8 ej9        e:          Z;de<d<    G d dee6                   Z= G d de>          Z?d%dZ@d&d"ZA G d# d$          ZBdS )'    )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is_type_alias_type)	BaseModelis_basemodeladd_request_id)RAW_RESPONSE_HEADER)StreamAsyncStreamis_stream_class_typeextract_stream_chunk_type)APIResponseValidationError)JSONLDecoderAsyncJSONLDecoder)FinalRequestOptions)
BaseClientPR_T_T_coT)	covariantz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   )r;   rawcast_toclientstream
stream_clsoptionsreturnNonec               v    || _         || _        i | _        || _        || _        || _        || _        || _        d S N)r/   r1   r2   r4   r6   r7   r9   r;   )selfr<   r=   r>   r?   r@   rA   r;   s           n/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/anthropic/_legacy_response.py__init__zLegacyAPIResponse.__init__H   sF      !% *    
str | Nonec                @    | j         j                            d          S )Nz
request-id)r9   headersgetrF   s    rG   
request_idzLegacyAPIResponse.request_id\   s    !)--l;;;rI   totype[_T]r(   c                   d S rE    )rF   rP   s     rG   parsezLegacyAPIResponse.parse`   s    ,/CrI   r'   c                    d S rE   rS   rN   s    rG   rT   zLegacyAPIResponse.parsec   s    #rI   NrP   type[_T] | NoneR | _Tc               x   ||n| j         }| j                            |          }||S |                     |          }t	          | j        j                  r| j                            |          }t          |t                    rt          || j
                   || j        |<   t          t          |          S )a  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 anthropic import BaseModel


        class MyModel(BaseModel):
            foo: str


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

        We support parsing:
          - `BaseModel`
          - `dict`
          - `list`
          - `Union`
          - `str`
          - `int`
          - `float`
          - `httpx.Response`
        NrV   )r/   r2   rM   _parser   r7   post_parser
isinstancer   r   rO   r   r'   )rF   rP   	cache_keycachedparseds        rG   rT   zLegacyAPIResponse.parsef   s    @ .BBdm	%)))44M##DM-.. 	7]..v66Ffi(( 	464?333*0Y'AvrI   httpx.Headersc                    | j         j        S rE   )r9   rL   rN   s    rG   rL   zLegacyAPIResponse.headers       !))rI   httpx.Requestc                    | j         j        S rE   )r9   requestrN   s    rG   http_requestzLegacyAPIResponse.http_request   rb   rI   c                    | j         j        S rE   )r9   status_coderN   s    rG   rh   zLegacyAPIResponse.status_code   s    !--rI   	httpx.URLc                    | j         j        S rE   )r9   urlrN   s    rG   rk   zLegacyAPIResponse.url   s    !%%rI   strc                    | j         j        S rE   )rf   methodrN   s    rG   rn   zLegacyAPIResponse.method   s     ''rI   bytesc                    | j         j        S )zReturn the binary response content.

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

        NOTE: this will be turned into a method in the next major version.
        )r9   textrN   s    rG   rs   zLegacyAPIResponse.text   s     !&&rI   c                    | j         j        S rE   )r9   http_versionrN   s    rG   ru   zLegacyAPIResponse.http_version   s    !..rI   c                    | j         j        S rE   )r9   	is_closedrN   s    rG   rw   zLegacyAPIResponse.is_closed   s    !++rI   datetime.timedeltac                    | j         j        S )zCThe time taken for the complete request/response cycle to complete.)r9   elapsedrN   s    rG   rz   zLegacyAPIResponse.elapsed   s     !))rI   c                  ||n| j         }t          |          r|j        }|rt          |          rt	          |d          }t          |          p|}t          j        |          rt          t          t          |          t                    r[t          t           t          d|          | j                            d          t	          |d          | j                            S t          t          t          |          t                    r[t          t           t          d|          | j                            d          t	          |d          | j                            S | 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                  }|t7                      t          t           ||| j        t          t          | j                                      S |t8          u rt          t          d           S | j        }|t:          k    rt          t          |j                  S |t>          k    r't          t          t?          |j                            S |t@          k    r't          t          tA          |j                            S |tB          k    r0t          t          |j        "                                dk              S t          j        |          r3t          |tF                    rt          t           ||                    S |tH          k    rtK          d          t          j        |          rNt          |tL          j'                  r4|tL          j'        k    rtQ          d          t          t          |          S t          j        |          r>t          |tR                    s)t          |tT          j)                  rt'          d          |tV          ur|tX          urw|tZ          urn|t\          uret          |tR                    sPtK          d| dtR           dtZ           dtX           dt\           dt8           dt:           dtL          j'         d          |j/        0                    dd          1                    d          ^}}|2                    d          stg          |          rr	 |4                                }| j        5                    |||          S # tl          $ r3}	tn          8                    dts          |	          |	           Y d }	~	nd }	~	ww xY w| j        j:        rtw          |d| d|j                  |j        S |4                                }| j        5                    |||          S )Nr   ztype[JSONLDecoder[Any]]@   
chunk_size)raw_iterator	line_typer9   ztype[AsyncJSONLDecoder[Any]]z/Expected custom parse type to be a subclass of z or zUExpected custom stream type to be passed with a type argument, e.g. Stream[ChunkType])failure_message)r=   responser>   r5   truez+Unexpected state - cast_to is `APIResponse`z:Subclasses of httpx.Response cannot be passed to `cast_to`zYPydantic models must subclass our base model type, e.g. `from anthropic import BaseModel`zUnsupported type, expected z to be a subclass of z, .zcontent-type*;json)datar=   r   z5Could not read JSON from response data due to %s - %szMExpected Content-Type response header to be `application/json` but received `z
` instead.)r   messagebody)<r/   r   	__value__r   r   r   inspectisclass
issubclassr   r   r"   r'   r9   
iter_bytesr#   aiter_bytesr4   r   	TypeErrorr   r   r(   r    r1   r6   _default_stream_clsMissingStreamClassErrorr   rl   rs   r:   floatr3   lowerHttpxBinaryResponseContentr-   RuntimeErrorhttpxResponse
ValueErrorr   pydanticobjectlistdictr   rL   rM   splitendswithr   r   _process_response_data	Exceptionr+   debugtype_strict_response_validationr!   )
rF   rP   r=   originr@   r   content_type_r   excs
             rG   rZ   zLegacyAPIResponse._parse   s   ""DM g&& 	('G  	3(11 	3&w22GG$$/?6"" 	$sF++\:: <D2G<<%)%7%B%Bb%B%Q%Q"27A">">&*&8     $sF++->?? AD7AA%)%7%C%Cr%C%R%R"27A">">&*&8     < &	 +B// q#$oV\$o$obm$o$opppB 9 -D! ! ! "&!3#C66  
 
 
  $$ 9$:J K K!%!3#C66 %     QSWS_SsttJ!-///
#!/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
	% %.(( !^___8$$$ O 	y vy11		y
 68#566	y wxxx 6!!dNNdNNeOO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$$V,, 	!G$$ 
	#==??D  <>>! '!) ?    ! g g gIIUW[\_W`W`beffffffffg |7 0% Elx  E  E  E!    = }}|22 3 
 
 	
s   W
 

X)XXc                B    d| j          d| j        j         d| j         dS )Nz<APIResponse [ z] type=>)rh   r9   reason_phraser/   rN   s    rG   __repr__zLegacyAPIResponse.__repr__k  s0    l 0ll43E3Sll\`\illllrI   )r<   r8   r=   r.   r>   r0   r?   r3   r@   r5   rA   r$   r;   r:   rB   rC   rB   rJ   )rP   rQ   rB   r(   )rB   r'   )rP   rW   rB   rX   )rB   r`   )rB   rc   )rB   r:   )rB   ri   rB   rl   rB   ro   )rB   r3   )rB   rx   )__name__
__module____qualname____doc____annotations__rH   propertyrO   r   rT   rL   rf   rh   rk   rn   rq   rs   ru   rw   rz   rZ   r   r   rS   rI   rG   r-   r-   /   s        
 
 !!!!))))MMMBBBB!!!!!!!!M + + + + + +( < < < X< /// X/ X-1 - - - - - -^ * * * X* * * * X* . . . X. & & & X& ( ( ( X( * * * X* ' ' ' X' / / / X/ , , , X, * * * X* /3 b
 b
 b
 b
 b
 b
H m m m Xm m mrI   r-   c                        e Zd Zd fdZ xZS )r   rB   rC   c                J    t                                          d           d S )Nz}The `stream` argument was set to `True` but the `stream_cls` argument was not given. See `anthropic._streaming` for reference)superrH   )rF   	__class__s    rG   rH   z MissingStreamClassError.__init__q  s/     L	
 	
 	
 	
 	
rI   rB   rC   )r   r   r   rH   __classcell__)r   s   @rG   r   r   p  s=        
 
 
 
 
 
 
 
 
 
rI   r   funcCallable[P, R]rB   !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.kwargsrB   LegacyAPIResponse[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|  sc    (ZDfjj6Q6Q,R,R,XVX(Z-3)*"/%a($$*?*?*?@@@rI   r   r   r   r   rB   r   	functoolswrapsr   r   s   ` rG   to_raw_response_wrapperr   w  sE    
 _TA A A A A A NrI   Callable[P, Awaitable[R]],Callable[P, Awaitable[LegacyAPIResponse[R]]]c                H     t          j                   d fd            }|S )	r   r   r   r   r   rB   r   c                    K   i t          t          |                    d                    pi }d|t          <   ||d<   t          t          t
                    | i | d {V           S r   r   r   s      rG   r   z.async_to_raw_response_wrapper.<locals>.wrapped  sy      (ZDfjj6Q6Q,R,R,XVX(Z-3)*"/%a(d0Ef0E0E*E*E*E*E*E*EFFFrI   r   r   r   s   ` rG   async_to_raw_response_wrapperr     sE    
 _TG G G G G G NrI   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/d0dZd/d1dZd2dZd/d0dZd3dZ ed          ddd4d            Zd5d Zd+d!Zd/d6d#Zd/d7d%Zd8d&Zd/d6d'Z ed          ddd4d(            Zd5d)ZdS )9r   r8   r   rB   rC   c                    || _         d S rE   )r   )rF   r   s     rG   rH   z#HttpxBinaryResponseContent.__init__  s     rI   ro   c                    | j         j        S rE   )r   rq   rN   s    rG   rq   z"HttpxBinaryResponseContent.content  s    }$$rI   rl   c                    | j         j        S rE   )r   rs   rN   s    rG   rs   zHttpxBinaryResponseContent.text  s    }!!rI   rJ   c                    | j         j        S rE   )r   encodingrN   s    rG   r   z#HttpxBinaryResponseContent.encoding  s    }%%rI   c                    | j         j        S rE   )r   charset_encodingrN   s    rG   r   z+HttpxBinaryResponseContent.charset_encoding  s    }--rI   r   r   c                &     | j         j        di |S )NrS   )r   r   )rF   r   s     rG   r   zHttpxBinaryResponseContent.json  s    !t}!++F+++rI   c                4    | j                                         S rE   )r   readrN   s    rG   r   zHttpxBinaryResponseContent.read  s    }!!###rI   Nr~   
int | NoneIterator[bytes]c                6    | j                             |          S rE   )r   r   rF   r~   s     rG   r   z%HttpxBinaryResponseContent.iter_bytes  s    }''
333rI   Iterator[str]c                6    | j                             |          S rE   )r   	iter_textr   s     rG   r   z$HttpxBinaryResponseContent.iter_text  s    }&&z222rI   c                4    | j                                         S rE   )r   
iter_linesrN   s    rG   r   z%HttpxBinaryResponseContent.iter_lines  s    }'')))rI   c                6    | j                             |          S rE   )r   iter_rawr   s     rG   r   z#HttpxBinaryResponseContent.iter_raw  s    }%%j111rI   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openr   r   write)rF   r   fr   s       rG   write_to_filez(HttpxBinaryResponseContent.write_to_file  s     $T""" 	a0022  	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   2AAAzDue to a bug, this method doesn't actually stream the response content, `.with_streaming_response.method()` should be used insteadr}   c                   t          |d          5 }| j                            |          D ]}|                    |           	 d d d            d S # 1 swxY w Y   d S Nr   r   r   )rF   r   r~   r   r   s        rG   stream_to_filez)HttpxBinaryResponseContent.stream_to_file  s     $T""" 	a00<<  	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   3AAAc                4    | j                                         S rE   )r   closerN   s    rG   r   z HttpxBinaryResponseContent.close  s    }""$$$rI   c                D   K   | j                                          d {V S rE   )r   areadrN   s    rG   r   z HttpxBinaryResponseContent.aread  s,      ]((*********rI   AsyncIterator[bytes]c                :   K   | j                             |          S rE   )r   r   r   s     rG   r   z&HttpxBinaryResponseContent.aiter_bytes  s      }((444rI   AsyncIterator[str]c                :   K   | j                             |          S rE   )r   
aiter_textr   s     rG   r  z%HttpxBinaryResponseContent.aiter_text  s      }''
333rI   c                8   K   | j                                         S rE   )r   aiter_linesrN   s    rG   r  z&HttpxBinaryResponseContent.aiter_lines  s      }((***rI   c                :   K   | j                             |          S rE   )r   	aiter_rawr   s     rG   r	  z$HttpxBinaryResponseContent.aiter_raw  s      }&&z222rI   c               >  K   t          j        |          }|                    d           d {V 4 d {V }| j                            |          2 3 d {V }|                    |           d {V  #6 	 d d d           d {V  d S # 1 d {V swxY w Y   d S r   )anyioPathr   r   r   r   )rF   r   r~   pathr   r   s         rG   astream_to_filez*HttpxBinaryResponseContent.astream_to_file  s^      z$-------- 	$ 	$ 	$ 	$ 	$ 	$ 	$"m77
CC $ $ $ $ $ $ $dggdmm######## DC	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$s   BA7B
BBc                D   K   | j                                          d {V S rE   )r   acloserN   s    rG   r  z!HttpxBinaryResponseContent.aclose  s,      ]))+++++++++rI   )r   r8   rB   rC   r   r   r   )r   r   rB   r   rE   )r~   r   rB   r   )r~   r   rB   r   )rB   r   )r   r   rB   rC   )r   r   r~   r   rB   rC   r   )r~   r   rB   r  )r~   r   rB   r  )rB   r  )r   r   r   r   rH   r   rq   rs   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r	  r  r  rS   rI   rG   r   r     st        ! ! ! ! % % % X% " " " X" & & & X& . . . X., , , ,$ $ $ $4 4 4 4 43 3 3 3 3* * * *2 2 2 2 2     Z 	M  "&	     % % % %+ + + +5 5 5 5 54 4 4 4 4+ + + +3 3 3 3 3 Z 	M  "&		$ 	$ 	$ 	$ 	$ 	$, , , , , ,rI   r   )r   r   rB   r   )r   r   rB   r   )C
__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   r   _modelsr   r   r   
_constantsr   
_streamingr   r   r   r    _exceptionsr!   _decoders.jsonlr"   r#   r$   _base_clientr%   r&   r'   r(   r)   	getLoggerr   r+   r   r-   r   r   r   r   r   rS   rI   rG   <module>r      s   " " " " " " " 				                               U T T T T T T T T T T T T T          U U U U U U U U U U U U < < < < < < < < < < + + + + + + \ \ \ \ \ \ \ \ \ \ \ \ 3 3 3 3 3 3 < < < < < < < < ),,,,,,(((((( IcNNGCLLWT]]4((('g'11 1 1 1 1~m ~m ~m ~m ~m
 ~m ~m ~mB

 
 
 
 
i 
 
 
   "   "f, f, f, f, f, f, f, f, f, f,rI   