
    &`i|                        d Z ddlZddlZddlmZmZmZmZ ddlm	Z	 ddl
mc mc m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  G d d eddefd	efd
efdee         fdee         fg                    Z G d de	j                  Z G d dej                  Zdded	edefdZ dddddedefdZ!ded	edej"        fdZ#dS )a  Implements the client side of the client/server pickling protocol.

All ray client client/server data transfer happens through this pickling
protocol. The model is as follows:

    * All Client objects (eg ClientObjectRef) always live on the client and
      are never represented in the server
    * All Ray objects (eg, ray.ObjectRef) always live on the server and are
      never returned to the client
    * In order to translate between these two references, PickleStub tuples
      are generated as persistent ids in the data blobs during the pickling
      and unpickling of these objects.

The PickleStubs have just enough information to find or generate their
associated partner object on either side.

This also has the advantage of avoiding predefined pickle behavior for ray
objects, which may include ray internal reference counting.

ClientPickler dumps things from the client into the appropriate stubs
ServerUnpickler loads stubs from the server into their client counterparts.
    N)AnyDict
NamedTupleOptional)
RayAPIStub)ClientActorClassClientActorHandleClientActorRefClientObjectRefClientRemoteFuncClientRemoteMethodInProgressSentinelOptionWrapperc                       e Zd Zd ZdS )
PickleStubc                 6    t                               |           S N)object
__reduce__)selfs    r/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/ray/util/client/client_pickler.pyr   zPickleStub.__reduce__9   s       &&&    N)__name__
__module____qualname__r    r   r   r   r   -   s#        ' ' ' ' 'r   r   type	client_idref_idnamebaseline_optionsc                   $     e Zd Z fdZd Z xZS )ClientPicklerc                 H     t                      j        |i | || _        d S r   )super__init__r   )r   r   argskwargs	__class__s       r   r&   zClientPickler.__init__@   s*    $)&)))"r   c                 \   t          |t                    rt          d| j        dd d           S t          |t                    rt          d| j        |j        d d           S t          |t                    r#t          d| j        |j        j        d d           S t          |t                    r|j	        |
                                 t          |j	                  t          u r#t          d| j        |j        j        d d           S t          d| j        |j	        j        d |j                  S t          |t                    r|j	        |
                                 t          |j	                  t          u r#t          d| j        |j        j        d d           S t          d	| j        |j	        j        d |j                  S t          |t                     r-t          d
| j        |j        j        j        |j        d           S t          |t(                    rt+          d          d S )NRayr   )r   r   r   r    r!   ObjectActorRemoteFuncSelfReference
RemoteFuncRemoteActorSelfReferenceRemoteActorRemoteMethodz)Sending a partial option is unimplemented)
isinstancer   r   r   r   idr	   	_actor_idr   _ref_ensure_refr   r   _client_side_ref_optionsr   r   _actor_handle	actor_ref_method_namer   NotImplementedError)r   objs     r   persistent_idzClientPickler.persistent_idD   ss   c:&& E	S.!%    _-- =	S.v!%    .// 5	S.}'!%    -.. -	Sx!!!CH~~!333!2"n/2%)    !.x{!$    -.. 	Sx!!!CH~~!333!3"n/2%)    ".x{!$    /00 		S#.(25%!%    ]++ 	S%&QRRRtr   )r   r   r   r&   r?   __classcell__)r)   s   @r   r#   r#   ?   sN        # # # # #G G G G G G Gr   r#   c                       e Zd Zd ZdS )ServerUnpicklerc                     t          |t                    sJ |j        dk    rt          |j                  S |j        dk    r!t          t          |j                            S t          d          )Nr,   r-   z!Being passed back an unknown stub)r3   r   r   r   r   r	   r
   r=   )r   pids     r   persistent_loadzServerUnpickler.persistent_load   si    #z*****8x"3:...X  $^CJ%?%?@@@%&IJJJr   N)r   r   r   rE   r   r   r   rB   rB      s(        K K K K Kr   rB   r>   returnc                     t          j                    5 }t          |||          }|                    |            |                                cd d d            S # 1 swxY w Y   d S )N)protocol)ioBytesIOr#   dumpgetvalue)r>   r   rH   filecps        r   dumps_from_clientrO      s    	 9dX>>>
}}                 s   ;AA #A TASCIIstrictfix_importsencodingerrorsdatac                    t          | t                    rt          d          t          j        |           }t          ||||                                          S )Nz%Can't load pickle from unicode stringrR   )r3   str	TypeErrorrI   rJ   rB   load)rV   rS   rT   rU   rM   s        r   loads_from_serverr[      s^     $ A?@@@:dD+  
dffr   valc                     t          j                    }t           j        j        j        |_        t          | |          |_        |S r   )ray_client_pb2ArgLocalityINTERNEDlocalrO   rV   )r\   r   outs      r   convert_to_argrd      s6    



C"+4CI i00CHJr   r   )$__doc__rI   pickletypingr   r   r   r   ray.cloudpicklecloudpickle!ray.core.generated.ray_client_pb2core	generatedr^   ray.util.clientr   ray.util.client.commonr   r	   r
   r   r   r   r   r   rX   bytesr   CloudPicklerr#   	UnpicklerrB   rO   r[   r_   rd   r   r   r   <module>rr      sg   . 
			  2 2 2 2 2 2 2 2 2 2 2 2 % % % % % % : : : : : : : : : : : : & & & & & &	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	' ' ' ' 'JSM#uXc]#$0	
	 	' ' '$L L L L LK, L L L^K K K K Kf& K K K 3 3 %     !%wx  
     0B      r   