def is_valid_short_number_for_region(short_number, region_dialing_from):
 if isinstance(short_number, PhoneNumber):
  short_number = national_significant_number(short_number)
 metadata = PhoneMetadata.short_metadata_for_region(region_dialing_from)
 if (metadata is None):
  return False
 general_desc = metadata.general_desc
 if ((general_desc.national_number_pattern is None) or (not _is_number_matching_desc(short_number, general_desc))):
  return False
 short_number_desc = metadata.short_code
 if (short_number_desc.national_number_pattern is None):
  return False
 return _is_number_matching_desc(short_number, short_number_desc)

def is_valid_short_number_for_region ( short_number , region_dialing_from ) : if isinstance ( short_number , PhoneNumber ) : short_number = national_significant_number ( short_number ) metadata = PhoneMetadata . short_metadata_for_region ( region_dialing_from ) if ( metadata is None ) : return False general_desc = metadata . general_desc if ( ( general_desc . national_number_pattern is None ) or ( not _is_number_matching_desc ( short_number , general_desc ) ) ) : return False short_number_desc = metadata . short_code if ( short_number_desc . national_number_pattern is None ) : return False return _is_number_matching_desc ( short_number , short_number_desc )
tests whether a short number matches a valid pattern in a region .