
    Zhs                     X    g d Z ddlZddlZddlmZ ddlmZ d
dZddZ	ddZ
dd	ZeZy))parent	referenceatparentschildren    N   )_proxy_helper)_locate_objectc                 P    d}t        | |||      }|j                         }|| u ry|S )al  
>>> listiter = iter([4,5,6,7])
>>> obj = parent(listiter, list)
>>> obj == [4,5,6,7]  # actually 'is', but don't have handle any longer
True

NOTE: objtype can be a single type (e.g. int or list) or a tuple of types.

WARNING: if obj is a sequence (e.g. list), may produce unexpected results.
Parent finds *one* parent (e.g. the last member of the sequence).
    r   N)r   pop)objobjtypeignoredepthchainr   s         \/mounts/lovelace/software/anaconda3/envs/py312/lib/python3.12/site-packages/dill/pointers.pyr   r      s3     EC%0EYY[F}M    c                     t         j                  }fd}t        |d      s|fn|}d |D        }t        | |||      ddd   }|S )zFind the chain of referents for obj. Chain will end with obj.

    objtype: an object type or tuple of types to search for
    depth: search depth (e.g. depth=2 is 'grandparents')
    ignore: an object or tuple of objects to ignore in the search
    c                     t        |       S N
isinstancexr   s    r   <lambda>zparents.<locals>.<lambda>-       *Q0 r   __len__c              3   2   K   | ]  }t        |        y wr   id.0r   s     r   	<genexpr>zparents.<locals>.<genexpr>0        (#bg(   N)gcget_referentshasattr
find_chainr   r   r   r   	edge_func	predicater   s    `     r   r   r   %   sO       I0I%fi8fYfF((FsIy%82>ELr   c                     t         j                  }fd}t        |d      s|fn|}d |D        }t        | ||||      }|S )a  Find the chain of referrers for obj. Chain will start with obj.

    objtype: an object type or tuple of types to search for
    depth: search depth (e.g. depth=2 is 'grandchildren')
    ignore: an object or tuple of objects to ignore in the search

    NOTE: a common thing to ignore is all globals, 'ignore=(globals(),)'

    NOTE: repeated calls may yield different results, as python stores
    the last value in the special variable '_'; thus, it is often good
    to execute something to replace '_' (e.g. >>> 1+1).
    c                     t        |       S r   r   r   s    r   r   zchildren.<locals>.<lambda>D   r   r   r   c              3   2   K   | ]  }t        |        y wr   r   r!   s     r   r#   zchildren.<locals>.<genexpr>G   r$   r%   )r'   get_referrersr)   r*   r+   s    `     r   r   r   6   sH       I0I%fi8fYfF((FsIy%@ELr   c                    | g}t        |       di}t        |       d i}t        |      }|j                  t        |             |j                  t        |             |j                  t        |             |j                  t        |             |j                  t        |             |j                  t        t        j                                      |j                  t        t        j                  d                   t        j                          |r|j                  d      }	 ||	      rA|	g}
|t        |	         .|t        |	         }	|
j                  |	       |t        |	         .|
S |t        |	         }||k  ru ||	      }|j                  t        |             |D ]N  }t        |      |v rt        |      |vs|dz   |t        |      <   |	|t        |      <   |j                  |       P |r| gS )Nr   r   )	r    setaddsys	_getframer'   collectr   append)r   r-   r,   	max_depthextra_ignorequeuer   r   r   targetr   tdepth	referrerssources                 r   r*   r*   S   s   EEWaLEgt_FF
JJr, 
JJr%y
JJr%y
JJr&z
JJr&z
JJr#--/"#
JJr#--"#$JJL
1VHEF$06
+V$ F$0 Lr&z"I!&)IJJr)}%# )f:'f:U*(.
E"V*%)/F2f:&LL() & 5Lr   ) )r   r@   )   r@   )__all__r'   r5   _dillr	   r   r
   r   r   r   r   r*   	refobjectr@   r   r   <module>rE      s4    ? 	 
 - '(": H 	r   