U
    W+d*                     @   s`   d dl mZ G dd deZG dd deZG dd deZG dd	 d	eZG d
d deZdS )    )sixc                   @   s:   e Zd ZdZdddZdd Zdd Zd	d
 Zdd ZdS )RuleaH  
    A Lifecycle rule for an S3 bucket.

    :ivar id: Unique identifier for the rule. The value cannot be longer
        than 255 characters. This value is optional. The server will
        generate a unique value for the rule if no value is provided.

    :ivar prefix: Prefix identifying one or more objects to which the
        rule applies. If prefix is not provided, Boto generates a default
        prefix which will match all objects.

    :ivar status: If 'Enabled', the rule is currently being applied.
        If 'Disabled', the rule is not currently being applied.

    :ivar expiration: An instance of `Expiration`. This indicates
        the lifetime of the objects that are subject to the rule.

    :ivar transition: An instance of `Transition`.  This indicates
        when to transition to a different storage class.

    Nc                 C   sv   || _ |d krdn|| _|| _t|tjr8t|d| _n|| _t|tr^t	 | _
| j
| n|rj|| _
nt	 | _
d S )N )days)idprefixstatus
isinstancer   integer_types
Expiration
expiration
TransitionTransitions
transitionappend)selfr   r   r   r   r    r   5/tmp/pip-unpacked-wheel-dlxw5sjy/boto/s3/lifecycle.py__init__.   s    
zRule.__init__c                 C   s
   d| j  S )Nz
<Rule: %s>)r   r   r   r   r   __repr__C   s    zRule.__repr__c                 C   s(   |dkr| j S |dkr$t | _| jS d S )Nr   r   )r   r   r   r   nameattrs
connectionr   r   r   startElementF   s    zRule.startElementc                 C   s@   |dkr|| _ n,|dkr || _n|dkr0|| _nt| || d S )NZIDZPrefixZStatus)r   r   r   setattrr   r   valuer   r   r   r   
endElementN   s    zRule.endElementc                 C   st   d}| j d k	r|d| j  7 }|d| j 7 }|d| j 7 }| jd k	rP|| j 7 }| jd k	rh|| j 7 }|d7 }|S )Nz<Rule>z<ID>%s</ID>z<Prefix>%s</Prefix>z<Status>%s</Status>z</Rule>)r   r   r   r   to_xmlr   r   sr   r   r   r    X   s    


zRule.to_xml)NNNNN)	__name__
__module____qualname____doc__r   r   r   r   r    r   r   r   r   r      s     

r   c                   @   s:   e Zd ZdZdddZdd Zdd Zd	d
 Zdd ZdS )r   z
    When an object will expire.

    :ivar days: The number of days until the object expires

    :ivar date: The date when the object will expire. Must be
        in ISO 8601 format.
    Nc                 C   s   || _ || _d S Nr   date)r   r   r)   r   r   r   r   n   s    zExpiration.__init__c                 C   s   d S r'   r   r   r   r   r   r   r   s    zExpiration.startElementc                 C   s&   |dkrt || _n|dkr"|| _d S )NDaysDate)intr   r)   r   r   r   r   r   u   s    zExpiration.endElementc                 C   s(   | j d krd| j }n
d| j  }d| S )Non: %sin: %s daysz<Expiration: %s>r(   r   Zhow_longr   r   r   r   {   s    

zExpiration.__repr__c                 C   sB   d}| j d k	r|d| j  7 }n| jd k	r6|d| j 7 }|d7 }|S )Nz<Expiration><Days>%s</Days><Date>%s</Date>z</Expiration>r(   r!   r   r   r   r       s    

zExpiration.to_xml)NN)	r#   r$   r%   r&   r   r   r   r   r    r   r   r   r   r   e   s   
r   c                   @   s*   e Zd ZdZd	ddZdd Zdd ZdS )
r   aJ  
    A transition to a different storage class.

    :ivar days: The number of days until the object should be moved.

    :ivar date: The date when the object should be moved.  Should be
        in ISO 8601 format.

    :ivar storage_class: The storage class to transition to.  Valid
        values are GLACIER, STANDARD_IA.
    Nc                 C   s   || _ || _|| _d S r'   r   r)   storage_class)r   r   r)   r3   r   r   r   r      s    zTransition.__init__c                 C   s.   | j d krd| j }n
d| j  }d|| jf S )Nr-   r.   z<Transition: %s, %s>r2   r/   r   r   r   r      s    

zTransition.__repr__c                 C   sP   d}|d| j  7 }| jd k	r,|d| j 7 }n| jd k	rD|d| j 7 }|d7 }|S )Nz<Transition>z<StorageClass>%s</StorageClass>r0   r1   z</Transition>)r3   r   r)   r!   r   r   r   r       s    

zTransition.to_xml)NNN)r#   r$   r%   r&   r   r   r    r   r   r   r   r      s   
r   c                   @   sf   e Zd ZdZdd Zdd Zdd Zdd	 ZdddZdd Z	e
dd Ze
dd Ze
dd Zd
S )r   z[
    A container for the transitions associated with a Lifecycle's Rule configuration.
    c                 C   s"   d| _ d| _d | _d | _d | _d S )N      )transition_propertiescurrent_transition_property	temp_days	temp_datetemp_storage_classr   r   r   r   r      s
    zTransitions.__init__c                 C   s   d S r'   r   r   r   r   r   r      s    zTransitions.startElementc                 C   s   |dkrt || _n|dkr$|| _n|dkr2|| _| j| jkrp| t| j| j| j d  | _ | _| _d| _n|  jd7  _d S )Nr*   r+   ZStorageClassr5   )r,   r8   r9   r:   r7   r6   r   r   r   r   r   r   r      s    zTransitions.endElementc                 C   s   d}| D ]}||  7 }q|S )v
        Returns a string containing the XML version of the Lifecycle
        configuration as defined by S3.
        r   r    )r   r"   r   r   r   r   r       s    zTransitions.to_xmlNc                 C   s   t |||}| | dS )aB  
        Add a transition 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.

        :ivar days: The number of days until the object should be moved.

        :ivar date: The date when the object should be moved.  Should be
            in ISO 8601 format.

        :ivar storage_class: The storage class to transition to.  Valid
            values are GLACIER, STANDARD_IA.
        N)r   r   )r   r   r)   r3   r   r   r   r   add_transition   s    zTransitions.add_transitionc                 C   s   | D ]}t ||  S d S r'   )getattr)r   propr   r   r   r   Z__first_or_default   s    zTransitions.__first_or_defaultc                 C   s
   |  dS )Nr   _Transitions__first_or_defaultr   r   r   r   r      s    zTransitions.daysc                 C   s
   |  dS )Nr)   r@   r   r   r   r   r)      s    zTransitions.datec                 C   s
   |  dS )Nr3   r@   r   r   r   r   r3      s    zTransitions.storage_class)NNN)r#   r$   r%   r&   r   r   r   r    r=   rA   propertyr   r)   r3   r   r   r   r   r      s   



r   c                   @   s2   e Zd ZdZdd Zdd Zdd ZdddZdS )	LifecyclezN
    A container for the rules associated with a Lifecycle configuration.
    c                 C   s    |dkrt  }| | |S d S )Nr   r   r   )r   r   r   r   ruler   r   r   r     s
    
zLifecycle.startElementc                 C   s   t | || d S r'   )r   r   r   r   r   r   	  s    zLifecycle.endElementc                 C   s.   d}|d7 }| D ]}||  7 }q|d7 }|S )r;   z&<?xml version="1.0" encoding="UTF-8"?>z<LifecycleConfiguration>z</LifecycleConfiguration>r<   )r   r"   rE   r   r   r   r      s    zLifecycle.to_xmlNr   Enabledc                 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 id: str
        :param id: Unique identifier for the rule. The value cannot be longer
            than 255 characters. This value is optional. The server will
            generate a unique value for the rule if no value is provided.

        :type prefix: str
        :iparam prefix: Prefix identifying one or more objects to which the
            rule applies.

        :type status: str
        :param status: If 'Enabled', the rule is currently being applied.
            If 'Disabled', the rule is not currently being applied.

        :type expiration: int
        :param expiration: Indicates the lifetime, in days, of the objects
            that are subject to the rule. The value must be a non-zero
            positive integer. A Expiration object instance is also perfect.

        :type transition: Transitions
        :param transition: Indicates when an object transitions to a
            different storage class. 
        NrD   )r   r   r   r   r   r   rE   r   r   r   add_rule  s    zLifecycle.add_rule)Nr   rF   NN)r#   r$   r%   r&   r   r   r    rG   r   r   r   r   rC      s       rC   N)	Zboto.compatr   objectr   r   r   listr   rC   r   r   r   r   <module>   s
   M&"P