<s> """<STR_LIT>""" <EOL> from boto . ec2 . securitygroup import SecurityGroup <EOL> class DBSecurityGroup ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , connection = None , owner_id = None , <EOL> name = None , description = None ) : <EOL> self . connection = connection <EOL> self . owner_id = owner_id <EOL> self . name = name <EOL> self . description = description <EOL> self . ec2_groups = [ ] <EOL> self . ip_ranges = [ ] <EOL> def __repr__ ( self ) : <EOL> return '<STR_LIT>' % self . name <EOL> def startElement ( self , name , attrs , connection ) : <EOL> if name == '<STR_LIT>' : <EOL> cidr = IPRange ( self ) <EOL> self . ip_ranges . append ( cidr ) <EOL> return cidr <EOL> elif name == '<STR_LIT>' : <EOL> ec2_grp = EC2SecurityGroup ( self ) <EOL> self . ec2_groups . append ( ec2_grp ) <EOL> return ec2_grp <EOL> else : <EOL> return None <EOL> def endElement ( self , name , value , connection ) : <EOL> if name == '<STR_LIT>' : <EOL> self . owner_id = value <EOL> elif name == '<STR_LIT>' : <EOL> self . name = value <EOL> elif name == '<STR_LIT>' : <EOL> self . description = value <EOL> elif name == '<STR_LIT>' : <EOL> pass <EOL> else : <EOL> setattr ( self , name , value ) <EOL> def delete ( self ) : <EOL> return self . connection . delete_dbsecurity_group ( self . name ) <EOL> def authorize ( self , cidr_ip = None , ec2_group = None ) : <EOL> """<STR_LIT>""" <EOL> if isinstance ( ec2_group , SecurityGroup ) : <EOL> group_name = ec2_group . name <EOL> group_owner_id = ec2_group . owner_id <EOL> else : <EOL> group_name = None <EOL> group_owner_id = None <EOL> return self . connection . authorize_dbsecurity_group ( self . name , <EOL> cidr_ip , <EOL> group_name , <EOL> group_owner_id ) <EOL> def revoke ( self , cidr_ip = None , ec2_group = None ) : <EOL> """<STR_LIT>""" <EOL> if isinstance ( ec2_group , SecurityGroup ) : <EOL> group_name = ec2_group . name <EOL> group_owner_id = ec2_group . owner_id <EOL> return self . connection . revoke_dbsecurity_group ( <EOL> self . name , <EOL> ec2_security_group_name = group_name , <EOL> ec2_security_group_owner_id = group_owner_id ) <EOL> return self . connection . revoke_dbsecurity_group ( <EOL> self . name , cidr_ip = cidr_ip ) <EOL> class IPRange ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , parent = None ) : <EOL> self . parent = parent <EOL> self . cidr_ip = None <EOL> self . status = None <EOL> def __repr__ ( self ) : <EOL> return '<STR_LIT>' % self . cidr_ip <EOL> def startElement ( self , name , attrs , connection ) : <EOL> pass <EOL> def endElement ( self , name , value , connection ) : <EOL> if name == '<STR_LIT>' : <EOL> self . cidr_ip = value <EOL> elif name == '<STR_LIT>' : <EOL> self . status = value <EOL> else : <EOL> setattr ( self , name , value ) <EOL> class EC2SecurityGroup ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , parent = None ) : <EOL> self . parent = parent <EOL> self . name = None <EOL> self . owner_id = None <EOL> def __repr__ ( self ) : <EOL> return '<STR_LIT>' % self . name <EOL> def startElement ( self , name , attrs , connection ) : <EOL> pass <EOL> def endElement ( self , name , value , connection ) : <EOL> if name == '<STR_LIT>' : <EOL> self . name = value <EOL> elif name == '<STR_LIT>' : <EOL> self . owner_id = value <EOL> else : <EOL> setattr ( self , name , value ) </s>
