o
    c²“iÙ  ã                   @   sf   d dl Z d dlmZ d dlmZmZ edededefdd„ƒZ	edefdd	„ƒZ
eG d
d„ dƒƒZdS )é    N)ÚDeveloperAPIÚ	PublicAPIÚclsÚ
serializerÚdeserializerc                C   s    t jjj ¡ }| | ||¡ dS )a  Use the given serializer to serialize instances of type ``cls``,
    and use the deserializer to deserialize the serialized object.

    Args:
        cls: A Python class/type.
        serializer: A function that converts an instances of
            type ``cls`` into a serializable object (e.g. python dict
            of basic objects).
        deserializer: A function that constructs the
            instance of type ``cls`` from the serialized object.
            This function itself must be serializable.
    N)ÚrayÚ_privateÚworkerÚglobal_workerÚget_serialization_contextÚ _register_cloudpickle_serializer)r   r   r   Úcontext© r   úJ/home/ubuntu/.local/lib/python3.10/site-packages/ray/util/serialization.pyÚregister_serializer   s   r   c                 C   s   t jjj ¡ }| | ¡ dS )z¦Deregister the serializer associated with the type ``cls``.
    There is no effect if the serializer is unavailable.

    Args:
        cls: A Python class/type.
    N)r   r   r	   r
   r   Ú_unregister_cloudpickle_reducer)r   r   r   r   r   Úderegister_serializer   s   r   c                   @   s$   e Zd Zdd„ Zdd„ Zdd„ ZdS )ÚStandaloneSerializationContextc                 C   s   |t jj|< d S ©N©ÚpickleÚCloudPicklerÚdispatch)Úselfr   Úreducerr   r   r   Ú_register_cloudpickle_reducer*   s   z<StandaloneSerializationContext._register_cloudpickle_reducerc                 C   s   t jj |d ¡ d S r   )r   r   r   Úpop)r   r   r   r   r   r   -   s   z>StandaloneSerializationContext._unregister_cloudpickle_reducerc                    s   ‡ ‡fdd„}|t jj|< d S )Nc                    s   ˆ ˆ| ƒffS r   r   )Úobj©Úcustom_deserializerÚcustom_serializerr   r   Ú_CloudPicklerReducer3   s   z]StandaloneSerializationContext._register_cloudpickle_serializer.<locals>._CloudPicklerReducerr   )r   r   r    r   r!   r   r   r   r   0   s   z?StandaloneSerializationContext._register_cloudpickle_serializerN)Ú__name__Ú
__module__Ú__qualname__r   r   r   r   r   r   r   r   $   s    r   )r   Úray.cloudpickleÚcloudpickler   Úray.util.annotationsr   r   ÚtypeÚcallabler   r   r   r   r   r   r   Ú<module>   s    