(number, country, locale)
| 66 | |
| 67 | |
| 68 | def appspot(number, country, locale): |
| 69 | print("\n\nPhone Number entered: %s" % number) |
| 70 | print("Default country entered: %s" % country) |
| 71 | print("Language entered: %s" % locale) |
| 72 | country = "ZZ" if country is None else country |
| 73 | |
| 74 | # Parse and analyse. Compare with: |
| 75 | # java/demo/src/main/java/com/google/phonenumbers/demo/render/ResultRenderer.java |
| 76 | numobj = phonenumbers.parse(number, country, keep_raw_input=True) |
| 77 | has_default_country = country != "" and country != "ZZ" |
| 78 | |
| 79 | is_possible_number = phonenumbers.is_possible_number(numobj) |
| 80 | is_valid_number = phonenumbers.is_valid_number(numobj) |
| 81 | if is_valid_number and has_default_country: |
| 82 | is_valid_number_for_region = phonenumbers.is_valid_number_for_region(numobj, country) |
| 83 | else: |
| 84 | is_valid_number_for_region = None |
| 85 | phone_number_region = phonenumbers.region_code_for_number(numobj) |
| 86 | number_type = phonenumbers.number_type(numobj) |
| 87 | validation_result = phonenumbers.is_possible_number_with_reason(numobj) |
| 88 | |
| 89 | is_possible_short_number = phonenumbers.is_possible_short_number(numobj) |
| 90 | is_valid_short_number = phonenumbers.is_valid_short_number(numobj) |
| 91 | if has_default_country: |
| 92 | is_possible_short_number_for_region = phonenumbers.is_possible_short_number_for_region(numobj, country) |
| 93 | is_valid_short_number_for_region = phonenumbers.is_valid_short_number_for_region(numobj, country) |
| 94 | else: |
| 95 | is_possible_short_number_for_region = None |
| 96 | is_valid_short_number_for_region = None |
| 97 | |
| 98 | # Render. Compare with: |
| 99 | # java/demo/src/main/resources/com/google/phonenumbers/demo/result.soy |
| 100 | table = Table("Parsing result (parse(keep_raw_input=True))") |
| 101 | table.append("country_code", blank_if_none(numobj.country_code)) |
| 102 | table.append("national_number", blank_if_none(numobj.national_number)) |
| 103 | table.append("extension", blank_if_none(numobj.extension)) |
| 104 | table.append("country_code_source", blank_if_none(phonenumbers.CountryCodeSource.to_string(numobj.country_code_source))) |
| 105 | table.append("italian_leading_zero", blank_if_none(numobj.italian_leading_zero)) |
| 106 | table.append("number_of_leading_zeros", blank_if_none(numobj.number_of_leading_zeros)) |
| 107 | table.append("raw_input", blank_if_none(numobj.raw_input)) |
| 108 | table.append("preferred_domestic_carrier_code", blank_if_none(numobj.preferred_domestic_carrier_code)) |
| 109 | table.render() |
| 110 | |
| 111 | table = Table("Validation Results") |
| 112 | table.append("Result from isPossibleNumber()", is_possible_number) |
| 113 | if is_possible_number: |
| 114 | if validation_result == phonenumbers.ValidationResult.IS_POSSIBLE_LOCAL_ONLY: |
| 115 | table.append("Result from isPossibleNumberWithReason()", phonenumbers.ValidationResult.to_string(validation_result)) |
| 116 | table.append("Number is considered invalid as it is not a possible national number.") |
| 117 | else: |
| 118 | table.append("Result from isValidNumber()", is_valid_number) |
| 119 | if is_valid_number_for_region is not None: |
| 120 | table.append("Result from isValidNumberForRegion()", is_valid_number_for_region) |
| 121 | table.append("Phone Number region", phone_number_region) |
| 122 | table.append("Result from getNumberType()", phonenumbers.PhoneNumberType.to_string(number_type)) |
| 123 | else: |
| 124 | table.append("Result from isPossibleNumberWithReason()", phonenumbers.ValidationResult.to_string(validation_result)) |
| 125 | table.append("Note: Numbers that are not possible have type UNKNOWN, an unknown region, and are considered invalid.") |
no test coverage detected