U
    W¨+d^#  ã                   @   sx   d dl mZ dZdZdZdZdZdZdZd	Z	d
Z
dZdZeegZee	e
eegZegZG dd„ deƒZG dd„ deƒZdS )é    )ÚInvalidLifecycleConfigErrorZLifecycleConfigurationÚRuleÚActionZDeleteZSetStorageClassÚ	ConditionZAgeZCreatedBeforeZNumberOfNewerVersionsZIsLiveZMatchesStorageClassc                   @   sJ   e Zd 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S )r   ax  
    A lifecycle rule for a bucket.

    :ivar action: Action to be taken.

    :ivar action_text: The text value for the specified action, if any.

    :ivar conditions: A dictionary of conditions that specify when the action
    should be taken. Each item in the dictionary represents the name and
    value (or a list of multiple values, if applicable) of a condition.
    Nc                 C   s    || _ || _|pi | _t| _d S )N)ÚactionÚaction_textÚ
conditionsÚRULEÚcurrent_tag)Úselfr   r   r   © r   ú5/tmp/pip-unpacked-wheel-dlxw5sjy/boto/gs/lifecycle.pyÚ__init__:   s    
zRule.__init__c                 C   s    | j |krtd|| j f ƒ‚dS )zVerify parent of the start tag.z"Invalid tag %s found inside %s tagN©r
   r   )r   ÚtagÚparentr   r   r   ÚvalidateStartTagB   s    
ÿzRule.validateStartTagc                 C   s    || j krtd| j |f ƒ‚dS )z%Verify end tag against the start tag.z%Mismatched start and end tags (%s/%s)Nr   )r   r   r   r   r   ÚvalidateEndTagH   s    
ÿÿzRule.validateEndTagc                 C   s¤   |t kr|  |t¡ n„|tkrD|  |t ¡ | jd k	r<tdƒ‚|| _nV|tkrZ|  |t¡ n@|tkrŽ|  |t¡ || jkrš|t	krštd| ƒ‚ntd| ƒ‚|| _
d S )Nz+Only one action tag is allowed in each rulez,Found duplicate non-repeatable conditions %súUnsupported tag )ÚACTIONr   r	   ÚLEGAL_ACTIONSr   r   Ú	CONDITIONÚLEGAL_CONDITIONSr   ÚLEGAL_REPEATABLE_CONDITIONSr
   )r   ÚnameÚattrsÚ
connectionr   r   r   ÚstartElementO   s*    
ÿ
ÿÿzRule.startElementc                 C   sÆ   |   |¡ |tkr|  ¡  n¦|tkr,t| _n–|tkrV|tkrN|d k	rN| ¡ | _t| _nl|t	krft| _n\|t
kr¶t	| _|tkr¦|| jkrg | j|< | j|  | ¡ ¡ qÂ| ¡ | j|< ntd| ƒ‚d S ©NzUnsupported end tag )r   r	   Úvalidater   r
   r   ÚSET_STORAGE_CLASSÚstripr   r   r   r   r   Úappendr   ©r   r   Úvaluer   r   r   r   Ú
endElementf   s&    




zRule.endElementc                 C   s&   | j stdƒ‚| js"td| j  ƒ‚dS )zValidate the rule.z#No action was specified in the rulez(No condition was specified for action %sN)r   r   r   ©r   r   r   r   r   €   s    ÿÿzRule.validatec                 C   s  dt  d g}| dt d ¡ | jrN| d| j d | jd| j d g¡ n| d| j d ¡ | dt d ¡ | dt d ¡ | jD ]X}|tkršqŒ|t	kr®| j| }n| j| g}|D ]$}| d| d |d| d g¡ q¾qŒ| dt d ¡ | dt  d ¡ d 
|¡S )z0Convert the rule into XML string representation.ú<ú>ú</z/>Ú )r	   r"   r   r   Úextendr   r   r   r   r   Újoin)r   ÚsZcondition_nameZcondition_valuesZcondition_valuer   r   r   Úto_xml‰   s0    þ

þ
zRule.to_xml)NNN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r%   r   r.   r   r   r   r   r   -   s   
	c                   @   s8   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
d„ ZdS )ÚLifecycleConfigzI
    A container of rules associated with a lifecycle configuration.
    c                 C   s
   d| _ d S )NF)Úhas_root_tagr&   r   r   r   r   «   s    zLifecycleConfig.__init__c                 C   s\   |t kr| jrtdƒ‚d| _n:|tkrL| js8td| ƒ‚tƒ }|  |¡ |S td| ƒ‚d S )Nz'Only one root tag is allowed in the XMLTzInvalid root tag r   )ÚLIFECYCLE_CONFIGr4   r   r	   r   r"   )r   r   r   r   Úruler   r   r   r   ¯   s    ÿ
zLifecycleConfig.startElementc                 C   s   |t kr
ntd| ƒ‚d S r   )r5   r   r#   r   r   r   r%   ¾   s    zLifecycleConfig.endElementc                 C   sL   dg}|  dt d ¡ | D ]}|  | ¡ ¡ q|  dt d ¡ d |¡S )z>Convert LifecycleConfig object into XML string representation.z&<?xml version="1.0" encoding="UTF-8"?>r'   r(   r)   r*   )r"   r5   r.   r,   )r   r-   r6   r   r   r   r.   Ä   s    zLifecycleConfig.to_xmlc                 C   s   t |||ƒ}|  |¡ dS )a’  
        Add a rule to this Lifecycle configuration.  This only adds the rule to
        the local copy.  To install the new rule(s) on the bucket, you need to
        pass this Lifecycle config object to the configure_lifecycle method of
        the Bucket object.

        :type action: str
        :param action: Action to be taken.

        :type action_text: str
        :param action_text: Value for the specified action.

        :type conditions: dict
        :param conditions: A dictionary of conditions that specify when the
        action should be taken. Each item in the dictionary represents the name
        and value of a condition.
        N)r   r"   )r   r   r   r   r6   r   r   r   Úadd_ruleÍ   s    zLifecycleConfig.add_ruleN)	r/   r0   r1   r2   r   r   r%   r.   r7   r   r   r   r   r3   ¦   s   	r3   N)Zboto.exceptionr   r5   r	   r   ÚDELETEr    r   ZAGEZCREATED_BEFOREZNUM_NEWER_VERSIONSZIS_LIVEZMATCHES_STORAGE_CLASSr   r   r   Úobjectr   Úlistr3   r   r   r   r   Ú<module>   s$   ÿy