B
    Wa	e/                 @   s2   d dl mZ dgZG dd dZG dd dZdS )    )refWeakSetc               @   s$   e Zd Zdd Zdd Zdd ZdS )_IterationGuardc             C   s   t || _d S )N)r   weakcontainer)selfr    r   !/usr/lib/python3.7/_weakrefset.py__init__   s    z_IterationGuard.__init__c             C   s    |   }|d k	r|j|  | S )N)r   
_iteratingadd)r   wr   r   r   	__enter__   s    z_IterationGuard.__enter__c             C   s0   |   }|d k	r,|j}||  |s,|  d S )N)r   r
   remove_commit_removals)r   etbr   sr   r   r   __exit__   s    
z_IterationGuard.__exit__N)__name__
__module____qualname__r	   r   r   r   r   r   r   r   
   s   r   c               @   s  e Zd Zd>ddZdd Zdd Zdd	 Zd
d Zdd Zdd Z	dd Z
dd Zdd Zdd Zdd Zdd Zdd Zdd ZeZd d! Zd"d# Zd$d% ZeZd&d' Zd(d) Zd*d+ ZeZd,d- Zd.d/ ZeZd0d1 Zd2d3 Zd4d5 Z e Z!d6d7 Z"d8d9 Z#d:d; Z$e$Z%d<d= Z&dS )?r   Nc             C   sB   t  | _t| fdd}|| _g | _t  | _|d k	r>| | d S )Nc             S   s2   | }|d k	r.|j r"|j|  n|j|  d S )N)r
   _pending_removalsappenddatadiscard)itemZselfrefr   r   r   r   _remove&   s
    z!WeakSet.__init__.<locals>._remove)setr   r   r   r   r
   update)r   r   r   r   r   r   r	   $   s    zWeakSet.__init__c             C   s(   | j }| jj}x|r"||  qW d S )N)r   r   r   pop)r   lr   r   r   r   r   4   s    zWeakSet._commit_removalsc          	   c   s<   t | * x"| jD ]}| }|d k	r|V  qW W d Q R X d S )N)r   r   )r   itemrefr   r   r   r   __iter__:   s
    
zWeakSet.__iter__c             C   s   t | jt | j S )N)lenr   r   )r   r   r   r   __len__C   s    zWeakSet.__len__c             C   s,   yt |}W n tk
r    dS X || jkS )NF)r   	TypeErrorr   )r   r   Zwrr   r   r   __contains__F   s
    zWeakSet.__contains__c             C   s   | j t| ft| dd fS )N__dict__)	__class__listgetattr)r   r   r   r   
__reduce__M   s    zWeakSet.__reduce__c             C   s&   | j r|   | jt|| j d S )N)r   r   r   r   r   r   )r   r   r   r   r   r   Q   s    zWeakSet.addc             C   s   | j r|   | j  d S )N)r   r   r   clear)r   r   r   r   r-   V   s    zWeakSet.clearc             C   s
   |  | S )N)r)   )r   r   r   r   copy[   s    zWeakSet.copyc             C   sX   | j r|   xDy| j }W n tk
r<   tdd Y nX | }|d k	r|S qW d S )Nzpop from empty WeakSet)r   r   r   r    KeyError)r   r"   r   r   r   r   r    ^   s    zWeakSet.popc             C   s"   | j r|   | jt| d S )N)r   r   r   r   r   )r   r   r   r   r   r   j   s    zWeakSet.removec             C   s"   | j r|   | jt| d S )N)r   r   r   r   r   )r   r   r   r   r   r   o   s    zWeakSet.discardc             C   s*   | j r|   x|D ]}| | qW d S )N)r   r   r   )r   otherZelementr   r   r   r   t   s    
zWeakSet.updatec             C   s   |  | | S )N)r   )r   r0   r   r   r   __ior__z   s    
zWeakSet.__ior__c             C   s   |   }|| |S )N)r.   difference_update)r   r0   newsetr   r   r   
difference~   s    
zWeakSet.differencec             C   s   |  | d S )N)__isub__)r   r0   r   r   r   r2      s    zWeakSet.difference_updatec             C   s<   | j r|   | |kr"| j  n| jdd |D  | S )Nc             s   s   | ]}t |V  qd S )N)r   ).0r   r   r   r   	<genexpr>   s    z#WeakSet.__isub__.<locals>.<genexpr>)r   r   r   r-   r2   )r   r0   r   r   r   r5      s    zWeakSet.__isub__c                s      fdd|D S )Nc             3   s   | ]}| kr|V  qd S )Nr   )r6   r   )r   r   r   r7      s    z'WeakSet.intersection.<locals>.<genexpr>)r)   )r   r0   r   )r   r   intersection   s    zWeakSet.intersectionc             C   s   |  | d S )N)__iand__)r   r0   r   r   r   intersection_update   s    zWeakSet.intersection_updatec             C   s(   | j r|   | jdd |D  | S )Nc             s   s   | ]}t |V  qd S )N)r   )r6   r   r   r   r   r7      s    z#WeakSet.__iand__.<locals>.<genexpr>)r   r   r   r:   )r   r0   r   r   r   r9      s    zWeakSet.__iand__c             C   s   | j dd |D S )Nc             s   s   | ]}t |V  qd S )N)r   )r6   r   r   r   r   r7      s    z#WeakSet.issubset.<locals>.<genexpr>)r   issubset)r   r0   r   r   r   r;      s    zWeakSet.issubsetc             C   s   | j ttt|k S )N)r   r   mapr   )r   r0   r   r   r   __lt__   s    zWeakSet.__lt__c             C   s   | j dd |D S )Nc             s   s   | ]}t |V  qd S )N)r   )r6   r   r   r   r   r7      s    z%WeakSet.issuperset.<locals>.<genexpr>)r   
issuperset)r   r0   r   r   r   r>      s    zWeakSet.issupersetc             C   s   | j ttt|kS )N)r   r   r<   r   )r   r0   r   r   r   __gt__   s    zWeakSet.__gt__c             C   s$   t || jstS | jttt|kS )N)
isinstancer)   NotImplementedr   r   r<   r   )r   r0   r   r   r   __eq__   s    zWeakSet.__eq__c             C   s   |   }|| |S )N)r.   symmetric_difference_update)r   r0   r3   r   r   r   symmetric_difference   s    
zWeakSet.symmetric_differencec             C   s   |  | d S )N)__ixor__)r   r0   r   r   r   rC      s    z#WeakSet.symmetric_difference_updatec                s@    j r    |kr" j  n j fdd|D   S )Nc             3   s   | ]}t | jV  qd S )N)r   r   )r6   r   )r   r   r   r7      s    z#WeakSet.__ixor__.<locals>.<genexpr>)r   r   r   r-   rC   )r   r0   r   )r   r   rE      s    zWeakSet.__ixor__c             C   s   |  dd | |fD S )Nc             s   s   | ]}|D ]
}|V  q
qd S )Nr   )r6   r   r   r   r   r   r7      s    z WeakSet.union.<locals>.<genexpr>)r)   )r   r0   r   r   r   union   s    zWeakSet.unionc             C   s   t | |dkS )Nr   )r$   r8   )r   r0   r   r   r   
isdisjoint   s    zWeakSet.isdisjoint)N)'r   r   r   r	   r   r#   r%   r'   r,   r   r-   r.   r    r   r   r   r1   r4   __sub__r2   r5   r8   __and__r:   r9   r;   __le__r=   r>   __ge__r?   rB   rD   __xor__rC   rE   rF   __or__rG   r   r   r   r   r   #   sH   
			N)_weakrefr   __all__r   r   r   r   r   r   <module>   s   