3
ebI                 @   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.6/_weakrefset.py__init__   s    z_IterationGuard.__init__c             C   s    | j  }|d k	r|jj|  | S )N)r   
_iteratingadd)r   wr   r   r   	__enter__   s    z_IterationGuard.__enter__c             C   s0   | j  }|d k	r,|j}|j|  |s,|j  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>| j| d S )Nc             S   s2   | }|d k	r.|j r"|jj|  n|jj|  d S )N)r
   _pending_removalsappenddatadiscard)item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"||j  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   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  | j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  | jj  d S )N)r   r   r   clear)r   r   r   r   r/   V   s    zWeakSet.clearc             C   s
   | j | S )N)r+   )r   r   r   r   copy[   s    zWeakSet.copyc             C   sV   | j r| j  xBy| jj }W n tk
r:   t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  | j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  | j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| j  x|D ]}| j| qW d S )N)r   r   r   )r   otherelementr   r   r   r    t   s    
zWeakSet.updatec             C   s   | j | | S )N)r    )r   r2   r   r   r   __ior__z   s    
zWeakSet.__ior__c             C   s   | j  }|j| |S )N)r0   difference_update)r   r2   newsetr   r   r   
difference~   s    
zWeakSet.differencec             C   s   | j | d S )N)__isub__)r   r2   r   r   r   r5      s    zWeakSet.difference_updatec             C   s<   | j r| j  | |kr"| jj  n| j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/   r5   )r   r2   r   r   r   r8      s    zWeakSet.__isub__c                s    j  fdd|D S )Nc             3   s   | ]}| kr|V  qd S )Nr   )r9   r   )r   r   r   r:      s    z'WeakSet.intersection.<locals>.<genexpr>)r+   )r   r2   r   )r   r   intersection   s    zWeakSet.intersectionc             C   s   | j | d S )N)__iand__)r   r2   r   r   r   intersection_update   s    zWeakSet.intersection_updatec             C   s(   | j r| j  | jjdd |D  | S )Nc             s   s   | ]}t |V  qd S )N)r   )r9   r   r   r   r   r:      s    z#WeakSet.__iand__.<locals>.<genexpr>)r   r   r   r=   )r   r2   r   r   r   r<      s    zWeakSet.__iand__c             C   s   | j jdd |D S )Nc             s   s   | ]}t |V  qd S )N)r   )r9   r   r   r   r   r:      s    z#WeakSet.issubset.<locals>.<genexpr>)r   issubset)r   r2   r   r   r   r>      s    zWeakSet.issubsetc             C   s   | j tdd |D k S )Nc             s   s   | ]}t |V  qd S )N)r   )r9   r   r   r   r   r:      s    z!WeakSet.__lt__.<locals>.<genexpr>)r   r   )r   r2   r   r   r   __lt__   s    zWeakSet.__lt__c             C   s   | j jdd |D S )Nc             s   s   | ]}t |V  qd S )N)r   )r9   r   r   r   r   r:      s    z%WeakSet.issuperset.<locals>.<genexpr>)r   
issuperset)r   r2   r   r   r   r@      s    zWeakSet.issupersetc             C   s   | j tdd |D kS )Nc             s   s   | ]}t |V  qd S )N)r   )r9   r   r   r   r   r:      s    z!WeakSet.__gt__.<locals>.<genexpr>)r   r   )r   r2   r   r   r   __gt__   s    zWeakSet.__gt__c             C   s(   t || jstS | jtdd |D kS )Nc             s   s   | ]}t |V  qd S )N)r   )r9   r   r   r   r   r:      s    z!WeakSet.__eq__.<locals>.<genexpr>)
isinstancer+   NotImplementedr   r   )r   r2   r   r   r   __eq__   s    zWeakSet.__eq__c             C   s   | j  }|j| |S )N)r0   symmetric_difference_update)r   r2   r6   r   r   r   symmetric_difference   s    
zWeakSet.symmetric_differencec             C   s   | j | d S )N)__ixor__)r   r2   r   r   r   rE      s    z#WeakSet.symmetric_difference_updatec                s@    j r j   |kr" jj  n jj fdd|D   S )Nc             3   s   | ]}t | jV  qd S )N)r   r   )r9   r   )r   r   r   r:      s    z#WeakSet.__ixor__.<locals>.<genexpr>)r   r   r   r/   rE   )r   r2   r   )r   r   rG      s    zWeakSet.__ixor__c             C   s   | j dd | |fD S )Nc             s   s   | ]}|D ]
}|V  q
qd S )Nr   )r9   r   r   r   r   r   r:      s    z WeakSet.union.<locals>.<genexpr>)r+   )r   r2   r   r   r   union   s    zWeakSet.unionc             C   s   t | j|dkS )Nr   )r%   r;   )r   r2   r   r   r   
isdisjoint   s    zWeakSet.isdisjoint)N)'r   r   r   r	   r   r$   r&   r)   r.   r   r/   r0   r!   r   r   r    r4   r7   __sub__r5   r8   r;   __and__r=   r<   r>   __le__r?   r@   __ge__rA   rD   rF   __xor__rE   rG   rH   __or__rI   r   r   r   r   r   #   sH   
			N)_weakrefr   __all__r   r   r   r   r   r   <module>   s   