U
    3ìd²  ã                   @   s4   d Z ddlmZ G dd„ deƒZG dd„ deƒZdS )z
Represents an EC2 Object
é    )ÚTagSetc                   @   s&   e Zd Zddd„Zdd„ Zdd„ ZdS )	Ú	EC2ObjectNc                 C   s,   || _ | j r"t| j dƒr"|j| _nd | _d S )NÚregion)Ú
connectionÚhasattrr   ©Úselfr   © r	   ú6/tmp/pip-unpacked-wheel-d7dsrkjd/boto/ec2/ec2object.pyÚ__init__   s    
zEC2Object.__init__c                 C   s   d S ©Nr	   ©r   ÚnameÚattrsr   r	   r	   r
   ÚstartElement&   s    zEC2Object.startElementc                 C   s   t | ||ƒ d S r   )Úsetattr)r   r   Úvaluer   r	   r	   r
   Ú
endElement)   s    zEC2Object.endElement)N)Ú__name__Ú
__module__Ú__qualname__r   r   r   r	   r	   r	   r
   r      s   
r   c                       sR   e Zd ZdZd‡ fdd„	Zdd„ Zdd	d
„Zddd„Zddd„Zddd„Z	‡  Z
S )ÚTaggedEC2ObjectaŠ  
    Any EC2 resource that can be tagged should be represented
    by a Python object that subclasses this class.  This class
    has the mechanism in place to handle the tagSet element in
    the Describe* responses.  If tags are found, it will create
    a TagSet object and allow it to parse and collect the tags
    into a dict that is stored in the "tags" attribute of the
    object.
    Nc                    s   t t| ƒ |¡ tƒ | _d S r   )Úsuperr   r   r   Útagsr   ©Ú	__class__r	   r
   r   8   s    zTaggedEC2Object.__init__c                 C   s   |dkr| j S d S d S )NZtagSet)r   r   r	   r	   r
   r   <   s    zTaggedEC2Object.startElementÚ Fc                 C   s   |   ||i|¡ dS )aó  
        Add a tag to this object.  Tags are stored by AWS and can be used
        to organize and filter resources.  Adding a tag involves a round-trip
        to the EC2 service.

        :type key: str
        :param key: The key or name of the tag being stored.

        :type value: str
        :param value: An optional value that can be stored with the tag.
                      If you want only the tag name and no value, the
                      value should be the empty string.
        N)Úadd_tags©r   Úkeyr   Údry_runr	   r	   r
   Úadd_tagB   s    zTaggedEC2Object.add_tagc                 C   s8   | j j| jg||d}| jdkr(tƒ | _| j |¡ dS )aß  
        Add tags to this object.  Tags are stored by AWS and can be used
        to organize and filter resources.  Adding tags involves a round-trip
        to the EC2 service.

        :type tags: dict
        :param tags: A dictionary of key-value pairs for the tags being stored.
                     If for some tags you want only the name and no value, the
                     corresponding value for that tag name should be an empty
                     string.
        ©r    N)r   Zcreate_tagsÚidr   r   Úupdate)r   r   r    Ústatusr	   r	   r
   r   R   s    ý
zTaggedEC2Object.add_tagsc                 C   s   |   ||i|¡ dS )aº  
        Remove a tag from this object.  Removing a tag involves a round-trip
        to the EC2 service.

        :type key: str
        :param key: The key or name of the tag being stored.

        :type value: str
        :param value: An optional value that can be stored with the tag.
                      If a value is provided, it must match the value currently
                      stored in EC2.  If not, the tag will not be removed.  If
                      a value of None is provided, the tag will be
                      unconditionally deleted.
                      NOTE: There is an important distinction between a value
                      of '' and a value of None.
        N)Úremove_tagsr   r	   r	   r
   Ú
remove_tagg   s    zTaggedEC2Object.remove_tagc                 C   sT   | j j| jg||d}| ¡ D ]0\}}|| jkr|dksF|| j| kr| j|= qdS )a  
        Removes tags from this object.  Removing tags involves a round-trip
        to the EC2 service.

        :type tags: dict
        :param tags: A dictionary of key-value pairs for the tags being removed.
                     For each key, the provided value must match the value
                     currently stored in EC2.  If not, that particular tag will
                     not be removed.  However, if a value of None is provided,
                     the tag will be unconditionally deleted.
                     NOTE: There is an important distinction between a value of
                     '' and a value of None.
        r"   N)r   Zdelete_tagsr#   Úitemsr   )r   r   r    r%   r   r   r	   r	   r
   r&   z   s    ý
zTaggedEC2Object.remove_tags)N)r   F)F)NF)F)r   r   r   Ú__doc__r   r   r!   r   r'   r&   Ú__classcell__r	   r	   r   r
   r   -   s   



r   N)r)   Zboto.ec2.tagr   Úobjectr   r   r	   r	   r	   r
   Ú<module>   s   