<s> """<STR_LIT>""" <EOL> import json <EOL> import xml . etree . ElementTree as ET <EOL> from cafe . engine . models . base import AutoMarshallingModel <EOL> from cloudcafe . compute . common . constants import Constants <EOL> from cloudcafe . compute . common . equality_tools import EqualityTools <EOL> from cloudcafe . compute . extensions . security_groups_api . models . security_group_rule import SecurityGroupRule <EOL> class SecurityGroup ( AutoMarshallingModel ) : <EOL> def __init__ ( self , id = None , name = None , description = None , <EOL> rules = None , tenant_id = None ) : <EOL> self . name = name <EOL> self . description = description <EOL> self . rules = rules <EOL> self . id = id <EOL> self . tenant_id = tenant_id <EOL> def __repr__ ( self ) : <EOL> values = [ ] <EOL> for prop in self . __dict__ : <EOL> values . append ( "<STR_LIT>" % ( prop , self . __dict__ [ prop ] ) ) <EOL> return '<STR_LIT:[>' + '<STR_LIT:U+002CU+0020>' . join ( values ) + '<STR_LIT:]>' <EOL> @ classmethod <EOL> def _json_to_obj ( cls , serialized_str ) : <EOL> """<STR_LIT>""" <EOL> json_dict = json . loads ( serialized_str ) <EOL> return cls . _dict_to_obj ( json_dict . get ( '<STR_LIT>' ) ) <EOL> @ classmethod <EOL> def _dict_to_obj ( cls , json_dict ) : <EOL> rules = [ ] <EOL> for rule in json_dict . get ( '<STR_LIT>' ) : <EOL> rules . append ( SecurityGroupRule . _dict_to_obj ( rule ) ) <EOL> return SecurityGroup ( id = json_dict . get ( '<STR_LIT:id>' ) , <EOL> name = json_dict . get ( '<STR_LIT:name>' ) , <EOL> description = json_dict . get ( '<STR_LIT:description>' ) , <EOL> rules = rules , <EOL> tenant_id = json_dict . get ( '<STR_LIT>' ) ) <EOL> @ classmethod <EOL> def _xml_to_obj ( cls , serialized_str ) : <EOL> """<STR_LIT>""" <EOL> xml_ele = ET . fromstring ( serialized_str ) <EOL> cls . _remove_xml_etree_namespace ( <EOL> xml_ele , Constants . XML_API_NAMESPACE ) <EOL> return cls . _xml_ele_to_obj ( xml_ele ) <EOL> @ classmethod <EOL> def _xml_ele_to_obj ( cls , xml_ele ) : <EOL> id = xml_ele . attrib . get ( '<STR_LIT:id>' ) <EOL> tenant_id = xml_ele . attrib . get ( '<STR_LIT>' ) <EOL> name = xml_ele . attrib . get ( '<STR_LIT:name>' ) <EOL> description = xml_ele . find ( '<STR_LIT:description>' ) . text <EOL> rules = [ ] <EOL> for rule in xml_ele . find ( '<STR_LIT>' ) . findall ( '<STR_LIT>' ) : <EOL> rules . append ( SecurityGroupRule . _xml_ele_to_obj ( rule ) ) <EOL> return SecurityGroup ( id = id , name = name , <EOL> description = description , <EOL> rules = rules , <EOL> tenant_id = tenant_id ) <EOL> def __eq__ ( self , other ) : <EOL> """<STR_LIT>""" <EOL> return EqualityTools . are_objects_equal ( self , other ) <EOL> def __ne__ ( self , other ) : <EOL> """<STR_LIT>""" <EOL> return not self == other <EOL> class SecurityGroups ( SecurityGroup ) : <EOL> @ classmethod <EOL> def _xml_to_obj ( cls , serialized_str ) : <EOL> """<STR_LIT>""" <EOL> xml_ele = ET . fromstring ( serialized_str ) <EOL> cls . _remove_xml_etree_namespace ( <EOL> xml_ele , Constants . XML_API_NAMESPACE ) <EOL> groups = [ ] <EOL> for group in xml_ele . findall ( '<STR_LIT>' ) : <EOL> groups . append ( SecurityGroup . _xml_ele_to_obj ( group ) ) <EOL> return groups <EOL> @ classmethod <EOL> def _json_to_obj ( cls , serialized_str ) : <EOL> """<STR_LIT>""" <EOL> ret = [ ] <EOL> json_dict = json . loads ( serialized_str ) <EOL> groups = json_dict . get ( '<STR_LIT>' ) <EOL> for group in groups : <EOL> ret . append ( SecurityGroup . _dict_to_obj ( group ) ) <EOL> return ret </s>
