ó
è?F[c           @   s¬   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 d e f d „  ƒ  YZ d e f d „  ƒ  YZ d S(   iÿÿÿÿ(   t   InvalidLifecycleConfigErrort   LifecycleConfigurationt   Rulet   Actiont   Deletet   SetStorageClasst	   Conditiont   Aget   CreatedBeforet   NumberOfNewerVersionst   IsLivet   MatchesStorageClassc           B   sV   e  Z d  Z d d d d „ Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 RS(	   sx  
    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.
    c         C   s.   | |  _  | |  _ | p i  |  _ t |  _ d  S(   N(   t   actiont   action_textt
   conditionst   RULEt   current_tag(   t   selfR   R   R   (    (    s0   lib/python2.7/site-packages/boto/gs/lifecycle.pyt   __init__:   s    		c         C   s/   |  j  | k r+ t d | |  j  f ƒ ‚ n  d S(   s   Verify parent of the start tag.s"   Invalid tag %s found inside %s tagN(   R   R    (   R   t   tagt   parent(    (    s0   lib/python2.7/site-packages/boto/gs/lifecycle.pyt   validateStartTagB   s    c         C   s/   | |  j  k r+ t d |  j  | f ƒ ‚ n  d S(   s%   Verify end tag against the start tag.s%   Mismatched start and end tags (%s/%s)N(   R   R    (   R   R   (    (    s0   lib/python2.7/site-packages/boto/gs/lifecycle.pyt   validateEndTagH   s    c         C   sî   | t  k r |  j | t ƒ nÂ | t k re |  j | t  ƒ |  j d  k	 rY t d ƒ ‚ n  | |  _ n| | t k r„ |  j | t ƒ n] | t k rÑ |  j | t ƒ | |  j	 k rá | t
 k rá t d | ƒ ‚ qá n t d | ƒ ‚ | |  _ d  S(   Ns+   Only one action tag is allowed in each rules,   Found duplicate non-repeatable conditions %ss   Unsupported tag (   t   ACTIONR   R   t   LEGAL_ACTIONSR   t   NoneR    t	   CONDITIONt   LEGAL_CONDITIONSR   t   LEGAL_REPEATABLE_CONDITIONSR   (   R   t   namet   attrst
   connection(    (    s0   lib/python2.7/site-packages/boto/gs/lifecycle.pyt   startElementO   s$    c         C   s  |  j  | ƒ | t k r& |  j ƒ  nõ | t k r> t |  _ nÝ | t k r€ | t k rt | d  k	 rt | j ƒ  |  _	 n  t |  _ n› | t
 k r˜ t |  _ nƒ | t k rt
 |  _ | t k rõ | |  j k rØ g  |  j | <n  |  j | j | j ƒ  ƒ q| j ƒ  |  j | <n t d | ƒ ‚ d  S(   Ns   Unsupported end tag (   R   R   t   validateR   R   R   t   SET_STORAGE_CLASSR   t   stripR   R   R   R   R   t   appendR    (   R   R   t   valueR   (    (    s0   lib/python2.7/site-packages/boto/gs/lifecycle.pyt
   endElementf   s&    	c         C   s;   |  j  s t d ƒ ‚ n  |  j s7 t d |  j  ƒ ‚ n  d S(   s   Validate the rule.s#   No action was specified in the rules(   No condition was specified for action %sN(   R   R    R   (   R   (    (    s0   lib/python2.7/site-packages/boto/gs/lifecycle.pyR!   €   s    		c         C   sc  d t  d g } | j d t d ƒ |  j ra | j d |  j d |  j d |  j d g ƒ n | j d |  j d ƒ | j d t d ƒ | j d t d ƒ x† |  j D]{ } | t k rÅ q­ n  | t	 k rá |  j | } n |  j | g } x4 | D], } | j d | d | d | d g ƒ qø Wq­ W| j d t d ƒ | j d t  d ƒ d j
 | ƒ S(   s0   Convert the rule into XML string representation.t   <t   >s   </s   />t    (   R   R$   R   R   t   extendR   R   R   R   R   t   join(   R   t   st   condition_namet   condition_valuest   condition_value(    (    s0   lib/python2.7/site-packages/boto/gs/lifecycle.pyt   to_xml‰   s,    	N(   t   __name__t
   __module__t   __doc__R   R   R   R   R    R&   R!   R0   (    (    (    s0   lib/python2.7/site-packages/boto/gs/lifecycle.pyR   -   s   						t   LifecycleConfigc           B   s;   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(   sI   
    A container of rules associated with a lifecycle configuration.
    c         C   s   t  |  _ d  S(   N(   t   Falset   has_root_tag(   R   (    (    s0   lib/python2.7/site-packages/boto/gs/lifecycle.pyR   «   s    c         C   s†   | t  k r0 |  j r$ t d ƒ ‚ n  t |  _ nR | t k rr |  j sX t d | ƒ ‚ n  t ƒ  } |  j | ƒ | St d | ƒ ‚ d  S(   Ns'   Only one root tag is allowed in the XMLs   Invalid root tag s   Unsupported tag (   t   LIFECYCLE_CONFIGR6   R    t   TrueR   R   R$   (   R   R   R   R   t   rule(    (    s0   lib/python2.7/site-packages/boto/gs/lifecycle.pyR    ¯   s    			c         C   s#   | t  k r n t d | ƒ ‚ d  S(   Ns   Unsupported end tag (   R7   R    (   R   R   R%   R   (    (    s0   lib/python2.7/site-packages/boto/gs/lifecycle.pyR&   ¾   s    c         C   sd   d g } | j  d t d ƒ x! |  D] } | j  | j ƒ  ƒ q% W| j  d t d ƒ d j | ƒ S(   s>   Convert LifecycleConfig object into XML string representation.s&   <?xml version="1.0" encoding="UTF-8"?>R'   R(   s   </R)   (   R$   R7   R0   R+   (   R   R,   R9   (    (    s0   lib/python2.7/site-packages/boto/gs/lifecycle.pyR0   Ä   s    	c         C   s#   t  | | | ƒ } |  j | ƒ d S(   s’  
        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   R9   (    (    s0   lib/python2.7/site-packages/boto/gs/lifecycle.pyt   add_ruleÍ   s    (   R1   R2   R3   R   R    R&   R0   R:   (    (    (    s0   lib/python2.7/site-packages/boto/gs/lifecycle.pyR4   ¦   s   					N(   t   boto.exceptionR    R7   R   R   t   DELETER"   R   t   AGEt   CREATED_BEFOREt   NUM_NEWER_VERSIONSt   IS_LIVEt   MATCHES_STORAGE_CLASSR   R   R   t   objectR   t   listR4   (    (    (    s0   lib/python2.7/site-packages/boto/gs/lifecycle.pyt   <module>   s"   		y