<s> from boto . compat import six <EOL> class Rule ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , id = None , prefix = None , status = None , expiration = None , <EOL> transition = None ) : <EOL> self . id = id <EOL> self . prefix = '<STR_LIT>' if prefix is None else prefix <EOL> self . status = status <EOL> if isinstance ( expiration , six . integer_types ) : <EOL> self . expiration = Expiration ( days = expiration ) <EOL> else : <EOL> self . expiration = expiration <EOL> if isinstance ( transition , Transition ) : <EOL> self . transition = Transitions ( ) <EOL> self . transition . append ( transition ) <EOL> elif transition : <EOL> self . transition = transition <EOL> else : <EOL> self . transition = Transitions ( ) <EOL> def __repr__ ( self ) : <EOL> return '<STR_LIT>' % self . id <EOL> def startElement ( self , name , attrs , connection ) : <EOL> if name == '<STR_LIT>' : <EOL> return self . transition <EOL> elif name == '<STR_LIT>' : <EOL> self . expiration = Expiration ( ) <EOL> return self . expiration <EOL> return None <EOL> def endElement ( self , name , value , connection ) : <EOL> if name == '<STR_LIT>' : <EOL> self . id = value <EOL> elif name == '<STR_LIT>' : <EOL> self . prefix = value <EOL> elif name == '<STR_LIT>' : <EOL> self . status = value <EOL> else : <EOL> setattr ( self , name , value ) <EOL> def to_xml ( self ) : <EOL> s = '<STR_LIT>' <EOL> if self . id is not None : <EOL> s += '<STR_LIT>' % self . id <EOL> s += '<STR_LIT>' % self . prefix <EOL> s += '<STR_LIT>' % self . status <EOL> if self . expiration is not None : <EOL> s += self . expiration . to_xml ( ) <EOL> if self . transition is not None : <EOL> s += self . transition . to_xml ( ) <EOL> s += '<STR_LIT>' <EOL> return s <EOL> class Expiration ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , days = None , date = None ) : <EOL> self . days = days <EOL> self . date = date <EOL> def startElement ( self , name , attrs , connection ) : <EOL> return None <EOL> def endElement ( self , name , value , connection ) : <EOL> if name == '<STR_LIT>' : <EOL> self . days = int ( value ) <EOL> elif name == '<STR_LIT>' : <EOL> self . date = value <EOL> def __repr__ ( self ) : <EOL> if self . days is None : <EOL> how_long = "<STR_LIT>" % self . date <EOL> else : <EOL> how_long = "<STR_LIT>" % self . days <EOL> return '<STR_LIT>' % how_long <EOL> def to_xml ( self ) : <EOL> s = '<STR_LIT>' <EOL> if self . days is not None : <EOL> s += '<STR_LIT>' % self . days <EOL> elif self . date is not None : <EOL> s += '<STR_LIT>' % self . date <EOL> s += '<STR_LIT>' <EOL> return s <EOL> class Transition ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , days = None , date = None , storage_class = None ) : <EOL> self . days = days <EOL> self . date = date <EOL> self . storage_class = storage_class <EOL> def __repr__ ( self ) : <EOL> if self . days is None : <EOL> how_long = "<STR_LIT>" % self . date <EOL> else : <EOL> how_long = "<STR_LIT>" % self . days <EOL> return '<STR_LIT>' % ( how_long , self . storage_class ) <EOL> def to_xml ( self ) : <EOL> s = '<STR_LIT>' <EOL> s += '<STR_LIT>' % self . storage_class <EOL> if self . days is not None : <EOL> s += '<STR_LIT>' % self . days <EOL> elif self . date is not None : <EOL> s += '<STR_LIT>' % self . date <EOL> s += '<STR_LIT>' <EOL> return s <EOL> class Transitions ( list ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self ) : <EOL> self . transition_properties = <NUM_LIT:3> <EOL> self . current_transition_property = <NUM_LIT:1> <EOL> self . temp_days = None <EOL> self . temp_date = None <EOL> self . temp_storage_class = None <EOL> def startElement ( self , name , attrs , connection ) : <EOL> return None <EOL> def endElement ( self , name , value , connection ) : <EOL> if name == '<STR_LIT>' : <EOL> self . temp_days = int ( value ) <EOL> elif name == '<STR_LIT>' : <EOL> self . temp_date = value <EOL> elif name == '<STR_LIT>' : <EOL> self . temp_storage_class = value <EOL> if self . current_transition_property == self . transition_properties : <EOL> self . append ( Transition ( self . temp_days , self . temp_date , self . temp_storage_class ) ) <EOL> self . temp_days = self . temp_date = self . temp_storage_class = None <EOL> self . current_transition_property = <NUM_LIT:1> <EOL> else : <EOL> self . current_transition_property += <NUM_LIT:1> <EOL> def to_xml ( self ) : <EOL> """<STR_LIT>""" <EOL> s = '<STR_LIT>' <EOL> for transition in self : <EOL> s += transition . to_xml ( ) <EOL> return s <EOL> def add_transition ( self , days = None , date = None , storage_class = None ) : <EOL> """<STR_LIT>""" <EOL> transition = Transition ( days , date , storage_class ) <EOL> self . append ( transition ) <EOL> def __first_or_default ( self , prop ) : <EOL> for transition in self : <EOL> return getattr ( transition , prop ) <EOL> return None <EOL> @ property <EOL> def days ( self ) : <EOL> return self . __first_or_default ( '<STR_LIT>' ) <EOL> @ property <EOL> def date ( self ) : <EOL> return self . __first_or_default ( '<STR_LIT:date>' ) <EOL> @ property <EOL> def storage_class ( self ) : <EOL> return self . __first_or_default ( '<STR_LIT>' ) <EOL> class Lifecycle ( list ) : <EOL> """<STR_LIT>""" <EOL> def startElement ( self , name , attrs , connection ) : <EOL> if name == '<STR_LIT>' : <EOL> rule = Rule ( ) <EOL> self . append ( rule ) <EOL> return rule <EOL> return None <EOL> def endElement ( self , name , value , connection ) : <EOL> setattr ( self , name , value ) <EOL> def to_xml ( self ) : <EOL> """<STR_LIT>""" <EOL> s = '<STR_LIT>' <EOL> s += '<STR_LIT>' <EOL> for rule in self : <EOL> s += rule . to_xml ( ) <EOL> s += '<STR_LIT>' <EOL> return s <EOL> def add_rule ( self , id = None , prefix = '<STR_LIT>' , status = '<STR_LIT>' , <EOL> expiration = None , transition = None ) : <EOL> """<STR_LIT>""" <EOL> rule = Rule ( id , prefix , status , expiration , transition ) <EOL> self . append ( rule ) </s>
