
    &`i\                         U 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
 d dlZd dlmZ i Zeedf         ed<    e	d          Z e	d          Zded	ed
efdZ G d dej        j        eeef                   ZdS )    N)AnyDictGenericListTupleTypeTypeVarUnion)DAGNodeBase_PyObjScanner
_instances
SourceTypeTransformedTypeinstance_id
node_indexreturnc                 B    t           |                              |          S )zGet the node instance.

    Note: This function should be static and globally importable,
    otherwise the serialization overhead would be very significant.
    )r   _replace_index)r   r   s     j/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/ray/dag/py_obj_scanner.py	_get_noder      s     k"11*===    c                        e Zd ZdZefdeeef         f fdZ fdZ	de
dee         fdZdeeef         de
fd	Zd
edefdZd Zd Z xZS )r   a  Utility to find and replace the `source_type` in Python objects.

    `source_type` can either be a single type or a tuple of multiple types.

    The caller must first call `find_nodes()`, then compute a replacement table and
    pass it to `replace_nodes`.

    This uses cloudpickle under the hood, so all sub-objects that are not `source_type`
    must be serializable.

    Args:
        source_type: the type(s) of object to find and replace. Default to DAGNodeBase.
    source_typec                     || _         t          j                    | _        d | _        g | _        d | _        | t          t          |           <   t                      
                    | j                   d S N)r   ioBytesIO_buf_found_objects_replace_tabler   idsuper__init__)selfr   	__class__s     r   r$   z_PyObjScanner.__init__(   s`    &JLL	 AE#
2d88#####r   c                     t          || j                  rFt          | j                  }| j                            |           t
          t          |           |ffS t                                          |          S )zHook for reducing objects.

        Objects of `self.source_type` are saved to `self._found` and a global map so
        they can later be replaced.

        All other objects fall back to the default `CloudPickler` serialization.
        )	
isinstancer   lenr   appendr   r"   r#   reducer_override)r%   objindexr&   s      r   r+   z_PyObjScanner.reducer_override7   sm     c4+,, 	0$$EKs###r$xx///ww'',,,r   r,   r   c                 x    | j         
J d            g | _         g | _        |                     |           | j         S )z
        Serialize `obj` and store all instances of `source_type` found in `_found`.

        Args:
            obj: The object to scan for `source_type`.
        Returns:
            A list of all instances of `source_type` found in `obj`.
        NzDfind_nodes cannot be called twice on the same PyObjScanner instance.)r   r    dump)r%   r,   s     r   
find_nodesz_PyObjScanner.find_nodesF   sB     KQ  		#{r   tablec                     | j         
J d            || _        | j                            d           t	          j        | j                  S )z6Replace previously found DAGNodes per the given table.Nzfind_nodes must be called firstr   )r   r!   r   seekpickleload)r%   r1   s     r   replace_nodesz_PyObjScanner.replace_nodesW   sG    {&&(I&&&#	q{49%%%r   ic                 2    | j         | j        |                  S r   )r!   r   )r%   r7   s     r   r   z_PyObjScanner._replace_index^   s    "4;q>22r   c                 `    t          |           t          v rt          t          |           = dS dS )z%Clear the scanner from the _instancesN)r"   r   r%   s    r   clearz_PyObjScanner.cleara   s/    d88z!!2d88$$$ "!r   c                 .    |                                   d S r   )r;   r:   s    r   __del__z_PyObjScanner.__del__f   s    

r   )__name__
__module____qualname____doc__r   r
   r   r   r$   r+   r   r   r   r0   r   r   r6   intr   r;   r=   __classcell__)r&   s   @r   r   r      s         :E $ $E$+$6 $ $ $ $ $ $- - - - -c d:&6    "&4
O(C#D & & & & &3 3
 3 3 3 3% % %
      r   )r   r4   typingr   r   r   r   r   r   r	   r
   rayray.dag.baser   r   rB   __annotations__r   r   r   cloudpickleCloudPicklerr    r   r   <module>rK      s%   					  H H H H H H H H H H H H H H H H H H H H 



 $ $ $ $ $ $ *,
Do%& + + + W\""
'+,,>3 >C >J > > > >N N N N NCO0'*o:U2V N N N N Nr   