<s> from omnilib . omnispec . omnispec import OmniSpec , OmniResource <EOL> import xml . etree . ElementTree as ET <EOL> def can_translate ( rspec ) : <EOL> return rspec . startswith ( '<STR_LIT>' ) <EOL> def rspec_to_omnispec ( urn , rspec ) : <EOL> ospec = OmniSpec ( "<STR_LIT>" , urn ) <EOL> doc = ET . fromstring ( rspec ) <EOL> for res in doc . findall ( '<STR_LIT>' ) : <EOL> type = res . find ( '<STR_LIT:type>' ) . text <EOL> id = res . find ( '<STR_LIT:id>' ) . text <EOL> rurn = res . find ( '<STR_LIT>' ) . text <EOL> available = res . find ( '<STR_LIT>' ) . text <EOL> available = available . lower ( ) == '<STR_LIT:true>' <EOL> r = OmniResource ( id , '<STR_LIT>' + id , type ) <EOL> r . set_allocated ( not available ) <EOL> ospec . add_resource ( rurn , r ) <EOL> return ospec <EOL> def omnispec_to_rspec ( omnispec , filter_allocated ) : <EOL> root = ET . Element ( '<STR_LIT>' ) <EOL> for _ , r in omnispec . get_resources ( ) . items ( ) : <EOL> if filter_allocated and not r . get_allocate ( ) : <EOL> continue <EOL> res = ET . SubElement ( root , '<STR_LIT>' ) <EOL> ET . SubElement ( res , '<STR_LIT:type>' ) . text = r . get_type ( ) <EOL> ET . SubElement ( res , '<STR_LIT:id>' ) . text = r . get_name ( ) <EOL> ET . SubElement ( res , '<STR_LIT>' ) . text = str ( not r . get_allocated ( ) ) <EOL> return ET . tostring ( root ) </s>
