def port_rule_masking(port_min, port_max):
 if (port_max < port_min):
  raise ValueError(_("'port_max' is smaller than 'port_min'"))
 bitdiff = (port_min ^ port_max)
 if (bitdiff == 0):
  return [_hex_format(port_min)]
 top_bit = 1
 while (top_bit <= bitdiff):
  top_bit <<= 1
 if (((port_min & (top_bit - 1)) == 0) and ((port_max & (top_bit - 1)) == (top_bit - 1))):
  return [_hex_format(port_min, (top_bit - 1))]
 top_bit >>= 1
 rules = []
 rules.extend(_gen_rules_port_min(port_min, top_bit))
 rules.extend(_gen_rules_port_max(port_max, top_bit))
 return rules

def port_rule_masking ( port_min , port_max ) : if ( port_max < port_min ) : raise ValueError ( _ ( "'port_max' is smaller than 'port_min'" ) ) bitdiff = ( port_min ^ port_max ) if ( bitdiff == 0 ) : return [ _hex_format ( port_min ) ] top_bit = 1 while ( top_bit <= bitdiff ) : top_bit <<= 1 if ( ( ( port_min & ( top_bit - 1 ) ) == 0 ) and ( ( port_max & ( top_bit - 1 ) ) == ( top_bit - 1 ) ) ) : return [ _hex_format ( port_min , ( top_bit - 1 ) ) ] top_bit >>= 1 rules = [ ] rules . extend ( _gen_rules_port_min ( port_min , top_bit ) ) rules . extend ( _gen_rules_port_max ( port_max , top_bit ) ) return rules
translate a range [port_min .