def _format_nsn(number, metadata, num_format, carrier_code=None):
 intl_number_formats = metadata.intl_number_format
 if ((len(intl_number_formats) == 0) or (num_format == PhoneNumberFormat.NATIONAL)):
  available_formats = metadata.number_format
 else:
  available_formats = metadata.intl_number_format
 formatting_pattern = _choose_formatting_pattern_for_number(available_formats, number)
 if (formatting_pattern is None):
  return number
 else:
  return _format_nsn_using_pattern(number, formatting_pattern, num_format, carrier_code)

def _format_nsn ( number , metadata , num_format , carrier_code = None ) : intl_number_formats = metadata . intl_number_format if ( ( len ( intl_number_formats ) == 0 ) or ( num_format == PhoneNumberFormat . NATIONAL ) ) : available_formats = metadata . number_format else : available_formats = metadata . intl_number_format formatting_pattern = _choose_formatting_pattern_for_number ( available_formats , number ) if ( formatting_pattern is None ) : return number else : return _format_nsn_using_pattern ( number , formatting_pattern , num_format , carrier_code )
format a national number .