3
[_ð]Ž  ã               @   s   G d d„ de ƒZdS )c               @   s  e Zd ZdZdgZdDd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d"d#„ Zd$d%„ Zd&d'„ Zd(d)„ Zd*d+„ Zd,d-„ Zd.d/„ Zd0d1„ Zd2d3„ Zd4d5„ Zd6d7„ Zd8d9„ Zd:d;„ Z d<d=„ Z!d>d?„ Z"d@dA„ Z#dBdC„ Z$dS )EÚSeta!  A simple set class.

    This class was originally used to deal with sets being missing in
    ancient versions of python, but dnspython will continue to use it
    as these sets are based on lists and are thus indexable, and this
    ability is widely used in dnspython applications.
    ÚitemsNc             C   s*   g | _ |dk	r&x|D ]}| j|ƒ qW dS )zaInitialize the set.

        *items*, an iterable or ``None``, the initial set of items.
        N)r   Úadd)Úselfr   Úitem© r   ú,/tmp/pip-build-yz_zf6az/dnspython/dns/set.pyÚ__init__   s    
zSet.__init__c             C   s   dt | jƒ S )Nzdns.simpleset.Set(%s))Úreprr   )r   r   r   r   Ú__repr__)   s    zSet.__repr__c             C   s   || j kr| j j|ƒ dS )z Add an item to the set.
        N)r   Úappend)r   r   r   r   r   r   ,   s    
zSet.addc             C   s   | j j|ƒ dS )z%Remove an item from the set.
        N)r   Úremove)r   r   r   r   r   r   3   s    z
Set.removec             C   s*   y| j j|ƒ W n tk
r$   Y nX dS )z0Remove an item from the set if present.
        N)r   r   Ú
ValueError)r   r   r   r   r   Údiscard9   s    zSet.discardc             C   s    | j }|j|ƒ}t| jƒ|_|S )aÞ  Make a (shallow) copy of the set.

        There is a 'clone protocol' that subclasses of this class
        should use.  To make a copy, first call your super's _clone()
        method, and use the object returned as the new instance.  Then
        make shallow copies of the attributes defined in the subclass.

        This protocol allows us to write the set algorithms that
        return new instances (e.g. union) once, and keep using them in
        subclasses.
        )Ú	__class__Ú__new__Úlistr   )r   ÚclsÚobjr   r   r   Ú_cloneB   s    
z
Set._clonec             C   s   | j ƒ S )z*Make a (shallow) copy of the set.
        )r   )r   r   r   r   Ú__copy__T   s    zSet.__copy__c             C   s   | j ƒ S )z*Make a (shallow) copy of the set.
        )r   )r   r   r   r   ÚcopyZ   s    zSet.copyc             C   s<   t |tƒstdƒ‚| |krdS x|jD ]}| j|ƒ q&W dS )zaUpdate the set, adding any elements from other which are not
        already in the set.
        zother must be a Set instanceN)Ú
isinstancer   r   r   r   )r   Úotherr   r   r   r   Úunion_update`   s    
zSet.union_updatec             C   sL   t |tƒstdƒ‚| |krdS x(t| jƒD ]}||jkr*| jj|ƒ q*W dS )z]Update the set, removing any elements from other which are not
        in both sets.
        zother must be a Set instanceN)r   r   r   r   r   r   )r   r   r   r   r   r   Úintersection_updatel   s    

zSet.intersection_updatec             C   s@   t |tƒstdƒ‚| |kr"g | _nx|jD ]}| j|ƒ q*W dS )zWUpdate the set, removing any elements from other which are in
        the set.
        zother must be a Set instanceN)r   r   r   r   r   )r   r   r   r   r   r   Údifference_update{   s    
zSet.difference_updatec             C   s   | j ƒ }|j|ƒ |S )zwReturn a new set which is the union of ``self`` and ``other``.

        Returns the same Set type as this set.
        )r   r   )r   r   r   r   r   r   Úunionˆ   s    
z	Set.unionc             C   s   | j ƒ }|j|ƒ |S )z†Return a new set which is the intersection of ``self`` and
        ``other``.

        Returns the same Set type as this set.
        )r   r   )r   r   r   r   r   r   Úintersection’   s    
zSet.intersectionc             C   s   | j ƒ }|j|ƒ |S )z©Return a new set which ``self`` - ``other``, i.e. the items
        in ``self`` which are not also in ``other``.

        Returns the same Set type as this set.
        )r   r   )r   r   r   r   r   r   Ú
difference�   s    
zSet.differencec             C   s
   | j |ƒS )N)r   )r   r   r   r   r   Ú__or__¨   s    z
Set.__or__c             C   s
   | j |ƒS )N)r   )r   r   r   r   r   Ú__and__«   s    zSet.__and__c             C   s
   | j |ƒS )N)r   )r   r   r   r   r   Ú__add__®   s    zSet.__add__c             C   s
   | j |ƒS )N)r   )r   r   r   r   r   Ú__sub__±   s    zSet.__sub__c             C   s   | j |ƒ | S )N)r   )r   r   r   r   r   Ú__ior__´   s    
zSet.__ior__c             C   s   | j |ƒ | S )N)r   )r   r   r   r   r   Ú__iand__¸   s    
zSet.__iand__c             C   s   | j |ƒ | S )N)r   )r   r   r   r   r   Ú__iadd__¼   s    
zSet.__iadd__c             C   s   | j |ƒ | S )N)r   )r   r   r   r   r   Ú__isub__À   s    
zSet.__isub__c             C   s   x|D ]}| j |ƒ qW dS )zÑUpdate the set, adding any elements from other which are not
        already in the set.

        *other*, the collection of items with which to update the set, which
        may be any iterable type.
        N)r   )r   r   r   r   r   r   ÚupdateÄ   s    
z
Set.updatec             C   s
   g | _ dS )zMake the set empty.N)r   )r   r   r   r   ÚclearÏ   s    z	Set.clearc             C   s@   x| j D ]}||j krdS qW x|j D ]}|| j kr&dS q&W dS )NFT)r   )r   r   r   r   r   r   Ú__eq__Ó   s    

z
Set.__eq__c             C   s   | j |ƒ S )N)r)   )r   r   r   r   r   Ú__ne__Þ   s    z
Set.__ne__c             C   s
   t | jƒS )N)Úlenr   )r   r   r   r   Ú__len__á   s    zSet.__len__c             C   s
   t | jƒS )N)Úiterr   )r   r   r   r   Ú__iter__ä   s    zSet.__iter__c             C   s
   | j | S )N)r   )r   Úir   r   r   Ú__getitem__ç   s    zSet.__getitem__c             C   s   | j |= d S )N)r   )r   r/   r   r   r   Ú__delitem__ê   s    zSet.__delitem__c             C   s4   t |tƒstdƒ‚x| jD ]}||jkrdS qW dS )zFIs this set a subset of *other*?

        Returns a ``bool``.
        zother must be a Set instanceFT)r   r   r   r   )r   r   r   r   r   r   Úissubsetí   s    

zSet.issubsetc             C   s4   t |tƒstdƒ‚x|jD ]}|| jkrdS qW dS )zHIs this set a superset of *other*?

        Returns a ``bool``.
        zother must be a Set instanceFT)r   r   r   r   )r   r   r   r   r   r   Ú
issupersetú   s    

zSet.issuperset)N)%Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú	__slots__r   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r    r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r,   r.   r0   r1   r2   r3   r   r   r   r   r      sD   
	
r   N)Úobjectr   r   r   r   r   Ú<module>   s    